Ejemplo n.º 1
0
class PortIngressRuleResultReplace(Packet):
    """ Variable Descriptor: Port Ingress Rule Result Replace """
    name = "Variable Descriptor: Port Ingress Rule Result Replace"
    fields_desc = [
        XByteField("branch", 0xD7),
        XShortField("leaf", 0x0501),
        ByteField("length", 4),
        XByteField("result", 3),
        XByteField("replace", 8),
        XByteField("fieldcode", 0),
        XByteField("fieldinstance", 0),
    ]
Ejemplo n.º 2
0
class CDPMsgProtoHello(CDPMsgGeneric):
    name = "Protocol Hello"
    type = 0x0008
    fields_desc = [
        XShortEnumField("type", 0x0008, _cdp_tlv_types),
        ShortField("len", 32),
        OUIField("oui", 0x00000c),
        XShortField("protocol_id", 0x0),
        # TLV length (len) - 2 (type) - 2 (len) - 3 (OUI) - 2
        # (Protocol ID)
        StrLenField("data", "", length_from=lambda p: p.len - 9)
    ]
Ejemplo n.º 3
0
class PPTPIncomingCallReply(PPTP):
    name = "PPTP Incoming Call Reply"
    fields_desc = [
        LenField("len", 148),
        ShortEnumField("type", 1, _PPTP_msg_type),
        XIntField("magic_cookie", _PPTP_MAGIC_COOKIE),
        ShortEnumField("ctrl_msg_type", 10, _PPTP_ctrl_msg_type),
        XShortField("reserved_0", 0x0000),
        ShortField("call_id", 1),
        ShortField("peer_call_id", 1),
        ByteEnumField("result_code", 1, _PPTP_result_code),
        ByteEnumField("error_code", 0, _PPTP_general_error_code),
        ShortField("pkt_window_size", 64),
        ShortField("pkt_transmit_delay", 0),
        XShortField("reserved_1", 0x0000)
    ]

    def answers(self, other):
        return isinstance(
            other,
            PPTPIncomingCallRequest) and other.call_id == self.peer_call_id
Ejemplo n.º 4
0
class DCPOEMIDBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 2, DCP_OPTIONS),
        MultiEnumField("sub_option",
                       8,
                       DCP_SUBOPTIONS,
                       fmt='B',
                       depends_on=lambda p: p.option),
        LenField("dcp_block_length", None),
        ShortEnumField("block_info", 0, BLOCK_INFOS),
        XShortField("vendor_id", 0x002a),
        XShortField("device_id", 0x0313),
        PadField(StrLenField("padding",
                             b"\x00",
                             length_from=lambda p: p.dcp_block_length % 2),
                 1,
                 padwith=b"\x00")
    ]

    def extract_padding(self, s):
        return '', s
Ejemplo n.º 5
0
class PPTPOutgoingCallRequest(PPTP):
    name = "PPTP Outgoing Call Request"
    fields_desc = [
        LenField("len", 168),
        ShortEnumField("type", 1, _PPTP_msg_type),
        XIntField("magic_cookie", _PPTP_MAGIC_COOKIE),
        ShortEnumField("ctrl_msg_type", 7, _PPTP_ctrl_msg_type),
        XShortField("reserved_0", 0x0000),
        ShortField("call_id", 1),
        ShortField("call_serial_number", 0),
        IntField("minimum_bps", 32768),
        IntField("maximum_bps", 2147483648),
        IntEnumField("bearer_type", 3, _PPTP_bearer_type),
        IntEnumField("framing_type", 3, _PPTP_framing_type),
        ShortField("pkt_window_size", 16),
        ShortField("pkt_proc_delay", 0),
        ShortField('phone_number_len', 0),
        XShortField("reserved_1", 0x0000),
        StrFixedLenField("phone_number", '', 64),
        StrFixedLenField("subaddress", '', 64)
    ]
Ejemplo n.º 6
0
class MultiAP_Message(Packet):
    name = "IEEE 1905 MultiAP Message"
    fields_desc = [
        XByteField("msg_version", None),
        XByteField("msg_reserved", None),
        XShortEnumField("msg_type", None, ieee1905_msg_type),
        XShortField("msg_id", None),
        XByteField("frag_id", None),
        BitField("flag_last_frag_ind", 0, 1),
        BitField("flag_relay_ind", 0, 1),
        BitField("flag_reserved", 0, 6)
    ]
Ejemplo n.º 7
0
class OLTUnicastLogicalLink(Packet):
    """ Object Context: OLT Unicast Logical Link """
    name = "Object Context: OLT Unicast Logical Link"
    fields_desc = [
        XByteField("branch", 0xD6),
        XShortField("leaf", 0x000a),
        XByteField("length", 10),
        XByteField("pon", 0),
        StrField("unicastvssn", "TBIT"),
        XIntField("unicastlink", 0x00000000),
        XByteField("pad", 0),
    ]
Ejemplo n.º 8
0
class OFPTStatsRequestQueue(_ofp_header):
    name = "OFPST_STATS_REQUEST_QUEUE"
    fields_desc = [ByteEnumField("version", 0x01, ofp_version),
                   ByteEnumField("type", 16, ofp_type),
                   ShortField("len", None),
                   IntField("xid", 0),
                   ShortEnumField("stats_type", 5, ofp_stats_types),
                   FlagsField("flags", 0, 16, []),
                   ShortEnumField("port_no", "NONE", ofp_port_no),
                   XShortField("pad", 0),
                   IntEnumField("queue_id", "ALL", ofp_queue)]
    overload_fields = {TCP: {"sport": 6653}}
Ejemplo n.º 9
0
class UDS_WMBAPR(Packet):
    name = 'WriteMemoryByAddressPositiveResponse'
    fields_desc = [
        BitField('memorySizeLen', 0, 4),
        BitField('memoryAddressLen', 0, 4),
        ConditionalField(XByteField('memoryAddress1', 0),
                         lambda pkt: pkt.memoryAddressLen == 1),
        ConditionalField(XShortField('memoryAddress2', 0),
                         lambda pkt: pkt.memoryAddressLen == 2),
        ConditionalField(X3BytesField('memoryAddress3', 0),
                         lambda pkt: pkt.memoryAddressLen == 3),
        ConditionalField(XIntField('memoryAddress4', 0),
                         lambda pkt: pkt.memoryAddressLen == 4),
        ConditionalField(XByteField('memorySize1', 0),
                         lambda pkt: pkt.memorySizeLen == 1),
        ConditionalField(XShortField('memorySize2', 0),
                         lambda pkt: pkt.memorySizeLen == 2),
        ConditionalField(X3BytesField('memorySize3', 0),
                         lambda pkt: pkt.memorySizeLen == 3),
        ConditionalField(XIntField('memorySize4', 0),
                         lambda pkt: pkt.memorySizeLen == 4)
    ]
Ejemplo n.º 10
0
class GMLAN_DPBAPR(Packet):
    name = 'DefinePIDByAddressPositiveResponse'
    fields_desc = [
        XShortField('parameterIdentifier', 0),
    ]

    @staticmethod
    def get_log(pkt):
        return pkt.sprintf("%GMLAN.service%"), pkt.parameterIdentifier

    def answers(self, other):
        return other.__class__ == GMLAN_DPBA \
            and other.parameterIdentifier == self.parameterIdentifier
Ejemplo n.º 11
0
class LoWPANMesh(Packet):
    name = "6LoWPAN Mesh Packet"
    deprecated_fields = {
        "_v": ("v", "2.4.4"),
        "_f": ("f", "2.4.4"),
        "_sourceAddr": ("src", "2.4.4"),
        "_destinyAddr": ("dst", "2.4.4"),
    }
    fields_desc = [
        BitField("reserved", 0x2, 2),
        BitEnumField("v", 0x0, 1, ["EUI-64", "Short"]),
        BitEnumField("f", 0x0, 1, ["EUI-64", "Short"]),
        BitField("hopsLeft", 0x0, 4),
        MultipleTypeField(
            [(XShortField("src", 0x0), lambda pkt: pkt.v == 1)],
            XLongField("src", 0x0)
        ),
        MultipleTypeField(
            [(XShortField("dst", 0x0), lambda pkt: pkt.v == 1)],
            XLongField("dst", 0x0)
        )
    ]
Ejemplo n.º 12
0
class AlarmNotificationPDU(Block):
    fields_desc = [
        # IEC-61158-6-10:2021, Table 513
        BlockHeader,
        ShortField("AlarmType", 0),
        XIntField("API", 0),
        ShortField("SlotNumber", 0),
        ShortField("SubslotNumber", 0),
        XIntField("ModuleIdentNumber", 0),
        XIntField("SubmoduleIdentNUmber", 0),
        XShortField("AlarmSpecifier", 0),
        PacketListField("AlarmPayload", [], _guess_alarm_payload)
    ]
Ejemplo n.º 13
0
class APHTCaps(IEEE1905_TLV):
    name = "AP HT Capabilities TLV"
    fields_desc = [
        XByteField("type", 0x86),
        XShortField("len", None),
        MACField("radio_id", None),
        BitField("max_tx_streams", 0x00, 2),
        BitField("max_rx_streams", 0x00, 2),
        BitField("short_gi_20mhz_flag", 0, 1),
        BitField("short_gi_40mhz_flag", 0, 1),
        BitField("ht_40mhz_flag", 0, 1),
        BitField("reserved", 0, 1)
    ]
Ejemplo n.º 14
0
class OSPFv3_Network_LSA(OSPF_BaseLSA):
    name = "OSPFv3 Network LSA"
    fields_desc = [ShortField("age", 1),
                   ShortEnumField("type", 0x2002, _OSPFv3_LStypes),
                   IPField("id", "0.0.0.0"),
                   IPField("adrouter", "1.1.1.1"),
                   XIntField("seq", 0x80000001),
                   XShortField("chksum", None),
                   ShortField("len", None),
                   ByteField("reserved", 0),
                   OSPFv3OptionsField(),
                   FieldListField("routerlist", [], IPField("", "0.0.0.1"),
                                  length_from=lambda pkt: pkt.len - 24)]
Ejemplo n.º 15
0
class RxLinkMetric(IEEE1905_TLV):
    name = "Receiver Link Metric TLV"
    fields_desc = [
        XByteField("type", 0x0A),
        XShortField("len", None),
        MACField("local_al_mac", None),
        MACField("neigh_al_mac", None),
        FieldLenField("metric_cnt", None, fmt='B', count_of="metric_list"),
        PacketListField("metric_list",
                        None,
                        RxLinkMetric_Entry,
                        count_from=lambda p: p.metric_cnt)
    ]
Ejemplo n.º 16
0
class OSPF_Network_LSA(OSPF_BaseLSA):
    name = "OSPF Network LSA"
    fields_desc = [ShortField("age", 1),
                   OSPFOptionsField(),
                   ByteField("type", 2),
                   IPField("id", "192.168.0.0"),
                   IPField("adrouter", "1.1.1.1"),
                   XIntField("seq", 0x80000001),
                   XShortField("chksum", None),
                   ShortField("len", None),
                   IPField("mask", "255.255.255.0"),
                   FieldListField("routerlist", [], IPField("", "1.1.1.1"),
                                  length_from=lambda pkt: pkt.len - 24)]
Ejemplo n.º 17
0
class OSPFv3_Router_LSA(OSPF_BaseLSA):
    name = "OSPFv3 Router LSA"
    fields_desc = [ShortField("age", 1),
                   ShortEnumField("type", 0x2001, _OSPFv3_LStypes),
                   IPField("id", "0.0.0.0"),
                   IPField("adrouter", "1.1.1.1"),
                   XIntField("seq", 0x80000001),
                   XShortField("chksum", None),
                   ShortField("len", None),
                   FlagsField("flags", 0, 8, ["B", "E", "V", "W"]),
                   OSPFv3OptionsField(),
                   PacketListField("linklist", [], OSPFv3_Link,
                                   length_from=lambda pkt:pkt.len - 24)]
Ejemplo n.º 18
0
class VendorSpecific(IEEE1905_TLV):
    name = "Vendor Specific TLV"
    fields_desc = [
        XByteField("type", 0x0B),
        XShortField("len", None),
        X3BytesField("vendor_oui", None),
        FieldLenField("vendor_data_len", None, fmt='B',
                      count_of="vendor_data"),
        FieldListField("vendor_data",
                       None,
                       XByteField("byte", None),
                       count_from=lambda p: p.vendor_data_len)
    ]
Ejemplo n.º 19
0
class APRadioBasicCaps(IEEE1905_TLV):
    name = "AP Radio Basic Capabilities TLV"
    fields_desc = [
        XByteField("type", 0x85),
        XShortField("len", None),
        MACField("radio_id", None),
        XByteField("max_bss_cnt", None),
        FieldLenField("op_class_cnt", None, fmt='B', count_of="op_class_list"),
        PacketListField("op_class_list",
                        None,
                        APRadioBasicCaps_OpClass,
                        count_from=lambda p: p.op_class_cnt)
    ]
Ejemplo n.º 20
0
class ModbusPDU10WriteMultipleRegistersRequest(Packet):
    name = "Write Multiple Registers"
    fields_desc = [
        XByteField("funcCode", 0x10),
        XShortField("startingAddr", 0x0000),
        BitFieldLenField(
            "quantityRegisters",
            None,
            16,
            count_of="outputsValue",
        ),  # noqa: E501
        BitFieldLenField("byteCount",
                         None,
                         8,
                         count_of="outputsValue",
                         adjust=lambda pkt, x: x * 2),  # noqa: E501
        FieldListField(
            "outputsValue",
            [0x0000],
            XShortField("", 0x0000),  # noqa: E501
            count_from=lambda pkt: pkt.byteCount)
    ]
Ejemplo n.º 21
0
class OpChnlReport(IEEE1905_TLV):
    name = "Operating Channel Report TLV"
    fields_desc = [
        XByteField("type", 0x8F),
        XShortField("len", None),
        MACField("radio_id", None),
        FieldLenField("op_class_cnt", None, fmt='B', count_of="op_class_list"),
        PacketListField("op_class_list",
                        None,
                        OpChnlReport_OpClass,
                        count_from=lambda p: p.op_class_cnt),
        XByteField("eirp", None)
    ]
Ejemplo n.º 22
0
class ModbusPDU17ReadWriteMultipleRegistersRequest(Packet):
    name = "Read Write Multiple Registers"
    fields_desc = [
        XByteField("funcCode", 0x17),
        XShortField("readStartingAddr", 0x0000),
        XShortField("readQuantityRegisters", 0x0001),
        XShortField("writeStartingAddr", 0x0000),
        BitFieldLenField("writeQuantityRegisters",
                         None,
                         16,
                         count_of="writeRegistersValue"),  # noqa: E501
        BitFieldLenField("byteCount",
                         None,
                         8,
                         count_of="writeRegistersValue",
                         adjust=lambda pkt, x: x * 2),  # noqa: E501
        FieldListField(
            "writeRegistersValue",
            [0x0000],
            XShortField("", 0x0000),  # noqa: E501
            count_from=lambda pkt: pkt.byteCount)
    ]
Ejemplo n.º 23
0
class IODControlRes(Block):
    """IODControl response block"""
    fields_desc = [
        BlockHeader,
        StrFixedLenField("padding", "", length=2),
        UUIDField("ARUUID", None),
        ShortField("SessionKey", 0),
        XShortField("AlarmSequenceNumber", 0),
        # ControlCommand
        BitField("ControlCommand_reserved", 0, 9),
        BitField("ControlCommand_PrmBegin", 0, 1),
        BitField("ControlCommand_ReadyForRT_CLASS_3", 0, 1),
        BitField("ControlCommand_ReadyForCompanion", 0, 1),
        BitField("ControlCommand_Done", 1, 1),
        BitField("ControlCommand_Release", 0, 1),
        BitField("ControlCommand_ApplicationReady", 0, 1),
        BitField("ControlCommand_PrmEnd", 0, 1),
        XShortField("ControlBlockProperties", 0)
    ]

    # default block_type value
    block_type = 0x8110
Ejemplo n.º 24
0
class ModbusADUResponse(Packet):
    name = "ModbusADU"
    fields_desc = [
        XShortField("transId", 0x0000),  # needs to be unique
        XShortField("protoId", 0x0000),  # needs to be zero (Modbus)
        ShortField("len", None),  # is calculated with payload
        XByteField("unitId", 0xff)
    ]  # 0xFF or 0x00 should be used for Modbus over TCP/IP  # noqa: E501

    def guess_payload_class(self, payload):
        function_code = orb(payload[0])

        if function_code == 0x2B:
            sub_code = orb(payload[1])
            try:
                return _mei_types_response[sub_code]
            except KeyError:
                pass
        try:
            return _modbus_response_classes[function_code]
        except KeyError:
            pass
        try:
            return _modbus_error_classes[function_code]
        except KeyError:
            pass
        if function_code in _reserved_funccode_response:
            return ModbusPDUReservedFunctionCodeResponse
        elif function_code in _reserved_funccode_error:
            return ModbusPDUReservedFunctionCodeError
        if function_code < 0x80:
            return ModbusPDUUserDefinedFunctionCodeResponse
        return ModbusPDUUserDefinedFunctionCodeError

    def post_build(self, p, pay):
        if self.len is None:
            tmp_len = len(pay) + 1  # +len(p)
            p = p[:4] + struct.pack("!H", tmp_len) + p[6:]
        return p + pay
Ejemplo n.º 25
0
class CookedLinux(Packet):
    # Documentation: http://www.tcpdump.org/linktypes/LINKTYPE_LINUX_SLL.html
    name = "cooked linux"
    # from wireshark's database
    fields_desc = [ShortEnumField("pkttype", 0, {0: "unicast",
                                                 1: "broadcast",
                                                 2: "multicast",
                                                 3: "unicast-to-another-host",
                                                 4: "sent-by-us"}),
                   XShortField("lladdrtype", 512),
                   ShortField("lladdrlen", 0),
                   StrFixedLenField("src", "", 8),
                   XShortEnumField("proto", 0x800, ETHER_TYPES)]
Ejemplo n.º 26
0
class GMLAN_TD(Packet):
    subfunctions = {0x00: "download", 0x80: "downloadAndExecuteOrExecute"}
    name = 'TransferData'
    fields_desc = [
        ByteEnumField('subfunction', 0, subfunctions),
        ConditionalField(XShortField('startingAddress', 0),
                         lambda pkt: GMLAN.determine_len(2)),
        ConditionalField(X3BytesField('startingAddress', 0),
                         lambda pkt: GMLAN.determine_len(3)),
        ConditionalField(XIntField('startingAddress', 0),
                         lambda pkt: GMLAN.determine_len(4)),
        StrField("dataRecord", None)
    ]
Ejemplo n.º 27
0
class UDS_RMBA(Packet):
    name = 'ReadMemoryByAddress'
    fields_desc = [
        BitField('memorySizeLen', 0, 4),
        BitField('memoryAddressLen', 0, 4),
        ConditionalField(XByteField('memoryAddress1', 0),
                         lambda pkt: pkt.memoryAddressLen == 1),
        ConditionalField(XShortField('memoryAddress2', 0),
                         lambda pkt: pkt.memoryAddressLen == 2),
        ConditionalField(X3BytesField('memoryAddress3', 0),
                         lambda pkt: pkt.memoryAddressLen == 3),
        ConditionalField(XIntField('memoryAddress4', 0),
                         lambda pkt: pkt.memoryAddressLen == 4),
        ConditionalField(XByteField('memorySize1', 0),
                         lambda pkt: pkt.memorySizeLen == 1),
        ConditionalField(XShortField('memorySize2', 0),
                         lambda pkt: pkt.memorySizeLen == 2),
        ConditionalField(X3BytesField('memorySize3', 0),
                         lambda pkt: pkt.memorySizeLen == 3),
        ConditionalField(XIntField('memorySize4', 0),
                         lambda pkt: pkt.memorySizeLen == 4),
    ]
Ejemplo n.º 28
0
class GRE(Packet):
    name = "GRE"
    deprecated_fields = {
        "seqence_number": ("sequence_number", "2.4.4"),
    }
    fields_desc = [
        BitField("chksum_present", 0, 1),
        BitField("routing_present", 0, 1),
        BitField("key_present", 0, 1),
        BitField("seqnum_present", 0, 1),
        BitField("strict_route_source", 0, 1),
        BitField("recursion_control", 0, 3),
        BitField("flags", 0, 5),
        BitField("version", 0, 3),
        XShortEnumField("proto", 0x0000, ETHER_TYPES),
        ConditionalField(
            XShortField("chksum", None), lambda pkt: pkt.chksum_present == 1 or
            pkt.routing_present == 1),  # noqa: E501
        ConditionalField(
            XShortField("offset", None), lambda pkt: pkt.chksum_present == 1 or
            pkt.routing_present == 1),  # noqa: E501
        ConditionalField(XIntField("key", None),
                         lambda pkt: pkt.key_present == 1),  # noqa: E501
        ConditionalField(XIntField("sequence_number", None),
                         lambda pkt: pkt.seqnum_present == 1),  # noqa: E501
    ]

    @classmethod
    def dispatch_hook(cls, _pkt=None, *args, **kargs):
        if _pkt and struct.unpack("!H", _pkt[2:4])[0] == 0x880b:
            return GRE_PPTP
        return cls

    def post_build(self, p, pay):
        p += pay
        if self.chksum_present and self.chksum is None:
            c = checksum(p)
            p = p[:4] + chb((c >> 8) & 0xff) + chb(c & 0xff) + p[6:]
        return p
Ejemplo n.º 29
0
class UDS_RC(Packet):
    routineControlTypes = {
        0: 'ISOSAEReserved',
        1: 'startRoutine',
        2: 'stopRoutine',
        3: 'requestRoutineResults'
    }
    name = 'RoutineControl'
    fields_desc = [
        ByteEnumField('routineControlType', 0, routineControlTypes),
        XShortField('routineIdentifier', 0),
        StrField('routineControlOptionRecord', 0, fmt="B"),
    ]
Ejemplo n.º 30
0
class OSPF_LSA_Hdr(Packet):
    name = "OSPF LSA Header"
    fields_desc = [ShortField("age", 1),
                   OSPFOptionsField(),
                   ByteEnumField("type", 1, _OSPF_LStypes),
                   IPField("id", "192.168.0.0"),
                   IPField("adrouter", "1.1.1.1"),
                   XIntField("seq", 0x80000001),
                   XShortField("chksum", 0),
                   ShortField("len", 36)]

    def extract_padding(self, s):
        return "", s