Example #1
0
class SCTPChunkError(_SCTPChunkGuessPayload, Packet):
    fields_desc = [ByteEnumField("type", 9, sctpchunktypes),
                   XByteField("flags", None),
                   FieldLenField("len", None, length_of="error_causes", adjust=lambda pkt, x:x + 4),  # noqa: E501
                   PadField(StrLenField("error_causes", "", length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"),
                   ]
Example #2
0
class SCTPChunkCookieEcho(SCTPChunkError):
    fields_desc = [ByteEnumField("type", 10, sctpchunktypes),
                   XByteField("flags", None),
                   FieldLenField("len", None, length_of="cookie", adjust=lambda pkt, x:x + 4),  # noqa: E501
                   PadField(StrLenField("cookie", "", length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"),
                   ]
Example #3
0
class L2TP(Packet):
    name = "L2TP"
    fields_desc = [
        FlagsField("hdr", 0, 12, ['res00', 'res01', 'res02', 'res03', 'priority', 'offset',  # noqa: E501
                                  'res06', 'sequence', 'res08', 'res09', 'length', 'control']),  # noqa: E501
        BitEnumField("version", 2, 4, {2: 'L2TPv2'}),

        ConditionalField(ShortField("len", 0),
                         lambda pkt: pkt.hdr & 'control+length'),
        ShortField("tunnel_id", 0),
        ShortField("session_id", 0),
        ConditionalField(ShortField("ns", 0),
                         lambda pkt: pkt.hdr & 'sequence+control'),
        ConditionalField(ShortField("nr", 0),
                         lambda pkt: pkt.hdr & 'sequence+control'),
        ConditionalField(
            PadField(ShortField("offset", 0), 4, b"\x00"),
            lambda pkt: not (pkt.hdr & 'control') and pkt.hdr & 'offset'
        )
    ]

    def post_build(self, pkt, pay):
        if self.len is None and self.hdr & 'control+length':
            tmp_len = len(pkt) + len(pay)
            pkt = pkt[:2] + struct.pack("!H", tmp_len) + pkt[4:]
        return pkt + pay
Example #4
0
class NetflowDataflowsetV9(Packet):
    name = "Netflow DataFlowSet V9"
    fields_desc = [
        ShortField("templateID", 255),
        FieldLenField("length",
                      None,
                      length_of="records",
                      adjust=lambda pkt, x: x + 4),  # noqa: E501
        PadField(
            PacketListField(
                "records", [],
                NetflowRecordV9,
                length_from=lambda pkt: pkt.length - 4),  # noqa: E501
            4,
            padwith=b"\x00")
    ]

    @classmethod
    def dispatch_hook(cls, _pkt=None, *args, **kargs):
        if _pkt:
            if _pkt[:2] == b"\x00\x01":
                return NetflowOptionsFlowsetV9
            if _pkt[:2] == b"\x00\x00":
                return NetflowFlowsetV9
        return cls
Example #5
0
class MKABasicParamSet(Packet):
    """
    Basic Parameter Set (802.1X-2010, section 11.11).
    """

    #########################################################################
    #
    # IEEE 802.1X-2010 standard
    # Section 11.11
    #########################################################################
    #

    name = "Basic Parameter Set"
    fields_desc = [
        ByteField("mka_version_id", 0),
        ByteField("key_server_priority", 0),
        BitField("key_server", 0, 1),
        BitField("macsec_desired", 0, 1),
        BitField("macsec_capability", 0, 2),
        BitField("param_set_body_len", 0, 12),
        PacketField("SCI", MACsecSCI(), MACsecSCI),
        XStrFixedLenField("actor_member_id", "", length=12),
        XIntField("actor_message_number", 0),
        XIntField("algorithm_agility", 0),
        PadField(XStrLenField("cak_name",
                              "",
                              length_from=lambda pkt:
                              (pkt.param_set_body_len - 28)),
                 4,
                 padwith=b"\x00")
    ]

    def extract_padding(self, s):
        return "", s
Example #6
0
class MKADistributedCAKParamSet(MKAParamSet):
    """
    Distributed CAK Parameter Set (802.1X-2010, section 11.11).
    """

    #########################################################################
    #
    # IEEE 802.1X-2010 standard
    # Section 11.11
    #########################################################################
    #

    name = "Distributed CAK parameter set"
    fields_desc = [
        PadField(
            ByteEnumField(
                "param_set_type",
                5,
                _parameter_set_types
            ),
            2,
            padwith=b"\x00"
        ),
        ShortField("param_set_body_len", 0),
        XStrFixedLenField(
            "cak_aes_key_wrap",
            "",
            length=MKAParamSet.EAPOL_MKA_DEFAULT_KEY_WRAP_LEN
        ),
        XStrField("cak_key_name", "")
    ]
Example #7
0
class MKAICVSet(MKAParamSet):
    """
    ICV (802.1X-2010, section 11.11).
    """

    #########################################################################
    #
    # IEEE 802.1X-2010 standard
    # Section 11.11
    #########################################################################
    #

    name = "ICV"
    fields_desc = [
        PadField(
            ByteEnumField(
                "param_set_type",
                255,
                _parameter_set_types
            ),
            2,
            padwith=b"\x00"
        ),
        ShortField("param_set_body_len", 0),
        XStrFixedLenField("icv", "", length=MKAParamSet.MACSEC_DEFAULT_ICV_LEN)
    ]
Example #8
0
class DCPControlBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 5, DCP_OPTIONS),
        MultiEnumField("sub_option",
                       4,
                       DCP_SUBOPTIONS,
                       fmt='B',
                       depends_on=lambda p: p.option),
        LenField("dcp_block_length", 3),
        ByteEnumField("response", 2, DCP_OPTIONS),
        MultiEnumField("response_sub_option",
                       2,
                       DCP_SUBOPTIONS,
                       fmt='B',
                       depends_on=lambda p: p.option),
        ByteEnumField("block_error", 0, BLOCK_ERRORS),
        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
Example #9
0
class MKAPotentialPeerListParamSet(MKAParamSet):
    """
    Potential Peer List parameter sets (802.1X-2010, section 11.11).
    """

    #########################################################################
    #
    # IEEE 802.1X-2010 standard
    # Section 11.11
    #########################################################################
    #

    name = "Potential Peer List Parameter Set"
    fields_desc = [
        PadField(
            ByteEnumField(
                "param_set_type",
                2,
                _parameter_set_types
            ),
            2,
            padwith=b"\x00"
        ),
        ShortField("param_set_body_len", 0),
        PacketListField("member_id_message_num", [], MKAPeerListTuple)
    ]
Example #10
0
class DCPAliasNameBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 2, DCP_OPTIONS),
        MultiEnumField("sub_option",
                       6,
                       DCP_SUBOPTIONS,
                       fmt='B',
                       depends_on=lambda p: p.option),
        FieldLenField("dcp_block_length",
                      None,
                      length_of="alias_name",
                      adjust=lambda p, x: x + 2),
        ShortEnumField("block_info", 0, BLOCK_INFOS),
        StrLenField("alias_name",
                    "et200sp",
                    length_from=lambda x: x.dcp_block_length - 2),
        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
Example #11
0
class DCPFullIPBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 1, DCP_OPTIONS),
        MultiEnumField("sub_option",
                       3,
                       DCP_SUBOPTIONS,
                       fmt='B',
                       depends_on=lambda p: p.option),
        LenField("dcp_block_length", None),
        ShortEnumField("block_info", 1, IP_BLOCK_INFOS),
        IPField("ip", "192.168.0.2"),
        IPField("netmask", "255.255.255.0"),
        IPField("gateway", "192.168.0.1"),
        FieldListField("dnsaddr", [],
                       IPField("", "0.0.0.0"),
                       count_from=lambda x: 4),
        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
Example #12
0
class DCPNameOfStationBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 2, DCP_OPTIONS),
        MultiEnumField("sub_option",
                       2,
                       DCP_SUBOPTIONS,
                       fmt='B',
                       depends_on=lambda p: p.option),
        FieldLenField("dcp_block_length",
                      None,
                      length_of="name_of_station",
                      adjust=lambda p, x: x + 2),
        # FieldLenField("dcp_block_length", None, length_of= "name_of_station", adjust=lambda p,x: x +2),

        # TODO it should take the len from name_of_station, but it takes the len of the rest of the packet
        ShortEnumField("block_info", 0, BLOCK_INFOS),
        StrLenField(
            "name_of_station",
            "et200sp",
            length_from=lambda x: x.dcp_block_length - 2),  # this works
        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
Example #13
0
class SCTPChunkParamRandom(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 0x8002, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="random",
                                 adjust=lambda pkt, x:x + 4),
                   PadField(StrLenField("random", RandBin(32),
                                        length_from=lambda pkt: pkt.len - 4),
                            4, padwith=b"\x00"), ]
Example #14
0
class SCTPChunkParamHostname(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 11, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="hostname",
                                 adjust=lambda pkt, x:x + 4),
                   PadField(StrLenField("hostname", "",
                                        length_from=lambda pkt: pkt.len - 4),
                            4, padwith=b"\x00"), ]
Example #15
0
class QueryCmdHcaCapOut(Packet):
    fields_desc = [
        ByteField('status', 0),
        BitField('reserved1', 0, 24),
        IntField('syndrome', 0),
        StrFixedLenField('reserved2', None, length=8),
        PadField(PacketField('capability', CmdHcaCap(), CmdHcaCap), 2048, padwith=b"\x00"),
    ]
Example #16
0
class SCTPChunkParamRequestedHMACFunctions(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 0x8004, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="HMAC_functions_list",
                                 adjust=lambda pkt, x:x + 4),
                   PadField(FieldListField("HMAC_functions_list", ["SHA-1"],
                                           ShortEnumField("HMAC_function", 1, hmactypes),  # noqa: E501
                                           length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"), ]
Example #17
0
class SCTPChunkAbort(_SCTPChunkGuessPayload, Packet):
    fields_desc = [ByteEnumField("type", 6, sctpchunktypes),
                   BitField("reserved", None, 7),
                   BitField("TCB", 0, 1),
                   FieldLenField("len", None, length_of="error_causes", adjust=lambda pkt, x:x + 4),  # noqa: E501
                   PadField(StrLenField("error_causes", "", length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"),
                   ]
Example #18
0
class SCTPChunkParamErrorIndication(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 0xc003, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="error_causes",
                                 adjust=lambda pkt, x:x + 8),
                   XIntField("correlation_id", None),
                   PadField(StrLenField("error_causes", "",
                                        length_from=lambda pkt: pkt.len - 4),
                            4, padwith=b"\x00"), ]
Example #19
0
class SCTPChunkParamChunkList(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 0x8003, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="chunk_list",
                                 adjust=lambda pkt, x:x + 4),
                   PadField(FieldListField("chunk_list", None,
                                           ByteEnumField("chunk", None, sctpchunktypes),  # noqa: E501
                                           length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"), ]
Example #20
0
class SCTPChunkParamSupportedAddrTypes(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 12, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="addr_type_list",
                                 adjust=lambda pkt, x:x + 4),
                   PadField(FieldListField("addr_type_list", ["IPv4"],
                                           ShortEnumField("addr_type", 5, sctpchunkparamtypes),  # noqa: E501
                                           length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"), ]
Example #21
0
class HCI_Cmd_LE_Set_Advertising_Data(Packet):
    name = "LE Set Advertising Data"
    fields_desc = [
        FieldLenField("len", None, length_of="data", fmt="B"),
        PadField(PacketListField("data", [],
                                 EIR_Hdr,
                                 length_from=lambda pkt: pkt.len),
                 align=31,
                 padwith=b"\0"),
    ]
Example #22
0
class SCTPChunkAuthentication(_SCTPChunkGuessPayload, Packet):
    fields_desc = [ByteEnumField("type", 15, sctpchunktypes),
                   XByteField("flags", None),
                   FieldLenField("len", None, length_of="HMAC",
                                 adjust=lambda pkt, x:x + 8),
                   ShortField("shared_key_id", None),
                   ShortField("HMAC_function", None),
                   PadField(StrLenField("HMAC", "", length_from=lambda pkt: pkt.len - 8),  # noqa: E501
                            4, padwith=b"\x00"),
                   ]
Example #23
0
class SCTPChunkParamSupportedExtensions(_SCTPChunkParam, Packet):
    fields_desc = [ShortEnumField("type", 0x8008, sctpchunkparamtypes),
                   FieldLenField("len", None, length_of="supported_extensions",
                                 adjust=lambda pkt, x:x + 4),
                   PadField(FieldListField("supported_extensions",
                                           ["authentication",
                                            "address-configuration",
                                            "address-configuration-ack"],
                                           ByteEnumField("supported_extensions",  # noqa: E501
                                                         None, sctpchunktypes),
                                           length_from=lambda pkt: pkt.len - 4),  # noqa: E501
                            4, padwith=b"\x00"), ]
Example #24
0
class Dot11EltCountry(Dot11Elt):
    name = "802.11 Country"
    fields_desc = [
        ByteField("ID", 7),
        ByteField("len", None),
        StrFixedLenField("country_string", b"\0\0\0", length=3),
        PadField(PacketListField("descriptors", [],
                                 Dot11EltCountryConstraintTriplet,
                                 length_from=lambda pkt: pkt.len -
                                 (pkt.len % 3)),
                 2,
                 padwith=b"\x00")
    ]
Example #25
0
class IFETlv(Packet):
    """
    Parent Class interhit by all ForCES TLV strucutures
    """
    name = "IFETlv"

    fields_desc = [
        ShortEnumField("type", 0, IFE_META_TYPES),
        FieldLenField("length",
                      None,
                      length_of="value",
                      adjust=lambda pkt, x: x + 4),
        MultipleTypeField([
            (PadField(ShortField("value", 0), 4, padwith=b'\x00'),
             lambda pkt: pkt.type in IFE_TYPES_SHORT),
            (PadField(IntField("value", 0), 4,
                      padwith=b'\x00'), lambda pkt: pkt.type in IFE_TYPES_INT),
        ], PadField(IntField("value", 0), 4, padwith=b'\x00')),
    ]

    def extract_padding(self, s):
        return "", s
Example #26
0
class SAPHDBPartError(PacketNoPadded):
    """SAP HANA SQL Command Network Protocol Error Part
    """
    part_kind = 6
    name = "SAP HANA SQL Command Network Protocol Error Part"
    fields_desc = [
        LESignedIntField("error_code", 0),
        LESignedIntField("error_position", 0),
        FieldLenField("error_text_length", None, length_of="error_text", fmt="<i"),
        EnumField("error_level", 0, hdb_error_level_vals, fmt="<b"),
        StrFixedLenField("sql_state", "HY000", 5),
        PadField(StrFixedLenField("error_text", "", length_from=lambda pkt: pkt.error_text_length), 8),
    ]
Example #27
0
 def __init__(self, tblfld):
     assert isinstance(tblfld, PacketField)
     assert hasattr(
         tblfld.cls,
         'index'), 'No index() method defined for OmciTableField row object'
     assert hasattr(
         tblfld.cls, 'is_delete'
     ), 'No delete() method defined for OmciTableField row object'
     super(OmciTableField,
           self).__init__([(IntField('table_length', 0),
                            (self.cond_pkt, self.cond_pkt_val)),
                           (PadField(StrField('me_type_table', None),
                                     OmciTableField.PDU_SIZE),
                            (self.cond_pkt2, self.cond_pkt_val2))], tblfld)
Example #28
0
class DCPMACBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 1, DCP_OPTIONS),
        MultiEnumField("sub_option", 1, DCP_SUBOPTIONS, fmt='B',
                       depends_on=lambda p: p.option),
        FieldLenField("dcp_block_length", None),
        ShortEnumField("block_info", 0, BLOCK_INFOS),
        MACField("mac", "00:00:00:00:00:00"),
        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
Example #29
0
class SCTPChunkData(_SCTPChunkGuessPayload, Packet):
    # TODO : add a padding function in post build if this layer is used to generate SCTP chunk data  # noqa: E501
    fields_desc = [ByteEnumField("type", 0, sctpchunktypes),
                   BitField("reserved", None, 4),
                   BitField("delay_sack", 0, 1),
                   BitField("unordered", 0, 1),
                   BitField("beginning", 0, 1),
                   BitField("ending", 0, 1),
                   FieldLenField("len", None, length_of="data", adjust=lambda pkt, x:x + 16),  # noqa: E501
                   XIntField("tsn", None),
                   XShortField("stream_id", None),
                   XShortField("stream_seq", None),
                   IntEnumField("proto_id", None, SCTP_PAYLOAD_PROTOCOL_INDENTIFIERS),  # noqa: E501
                   PadField(StrLenField("data", None, length_from=lambda pkt: pkt.len - 16),  # noqa: E501
                            4, padwith=b"\x00"),
                   ]
Example #30
0
class DCPDeviceInstanceBlock(Packet):
    fields_desc = [
        ByteEnumField("option", 2, DCP_OPTIONS),
        MultiEnumField("sub_option", 7, DCP_SUBOPTIONS, fmt='B',
                       depends_on=lambda p: p.option),
        LenField("dcp_block_length", 4),
        ShortEnumField("block_info", 0, BLOCK_INFOS),
        XByteField("device_instance_high", 0x00),
        XByteField("device_instance_low", 0x01),
        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