I'm new to scapy and I'm trying to implement a protocol. Within this protocol a type, lets call it "Attribute" is used multiple times (with an other name ofcourse). Now I'm trying to implement this, but it won't work.
I've created my "Attribute" as follows:
class Attribute(Packet):
name = "Attribute"
fields_desc = [
ByteField("Tag_ID_Open", 0xa3), # 0xa3 = Attribute
ShortField("ObjectVariableTypeName", 0x8169),
ByteField("Datatype_Flags", 0x00),
ShortField("Datatype", 0x15), #0x15 = String
ByteField("Length", 0x00),
StrField("Value","SubscriptionContainer"),
ByteField("Tag_ID_Close", 0xa2), # 0xa2 = Terminating Object
]
The class where this "Attribute" is used is as follows: (I know there are some issues with conditional fields)
class ClassServerSession_GetNewRIDOnServer(Packet):
name = "ClassServerSession_GetNewRIDOnServer"
fields_desc = [
ByteField("Tag_ID_Open", 0xa3), # 0xa3 = Attribute
NBytesField("RelationID",0x000000,8),
ShortField("ClassID",0x0000),
ByteField("ClassFlags",0x00),
ByteField("AttributeID",0x00),
PacketListField("ObjectVariableTypeName", None, Attribute(ID_Number = 0x8169, Value="ServerSession_1C9C381",Length=len("ServerSession_1C9C381"))),
PacketListField("ServerSessionClientString", None, Attribute(ID_Number = 0x8221, Value="1:::6.0::Intel(R) PRO/1000 MT Desktop Adapter.TCPIP.1", Length=len("1:::6.0::Intel(R) PRO/1000 MT Desktop Adapter.TCPIP.1"))),
PacketListField("ServerSessionUser", None, Attribute(ID_Number = 0x8228, Value="", Length=len(""))),
PacketListField("ServerSessionApplication", None, Attribute(ID_Number = 0x8229, Value="", Length=len(""))),
PacketListField("ServerSessionHost", None, Attribute(ID_Number = 0x822a, Value="DESKTOP-3DTU8UA_1340031", Length=len("DESKTOP-3DTU8UA_1340031"))),
PacketListField("ServerSessionRole", None, Attribute(ID_Number = 0x822b, Datatype = 0x04, Value=1, Length=1)),
PacketListField("ServerSessionClientRID", None, Attribute(ID_Number = 0x822c, Datatype = 0x12, Value=0x01c9c381)),
PacketListField("ServerSessionClientComment", None, Attribute(ID_Number = 0x822d, Value="", Length=0)),
ByteField("Tag_ID_Close", 0xa2), # 0xa2 = Terminating Object
]
When printing this class I get the following:
pPacket = ClassServerSession_GetNewRIDOnServer()
pPacket.show2()
###[ ClassServerSession_GetNewRIDOnServer ]###
Tag_ID_Open= 163
RelationID= 0
ClassID = 0
ClassFlags= 0
AttributeID= 0
\ObjectVariableTypeName\
|###[ Raw ]###
| load = '\\xa2'
\ServerSessionClientString\
\ServerSessionUser\
\ServerSessionApplication\
\ServerSessionHost\
\ServerSessionRole\
\ServerSessionClientRID\
\ServerSessionClientComment\
Tag_ID_Close= 162
I've tried with FieldLenList, without succes:
FieldLenField("ObjectVariableTypeName", 22, length_of=Attribute, fmt='B'),
PacketListField("Attribute", None, Attribute(ID_Number = 0x8169, Value="ServerSession_1C9C381",Length=len("ServerSession_1C9C381"))),
Also searched stackoverflow for similar issues, but couldn't find any. Looked at examples found on stackoverflow and other sites, but none of them were helpfull.
Can somebody help me?