示例#1
0
class IODWriteMultipleReq(Block):
    """IODWriteMultiple request"""
    fields_desc = [
        BlockHeader,
        ShortField("seqNum", 0),
        UUIDField("ARUUID", None),
        XIntField("API", 0xffffffff),
        XShortField("slotNumber", 0xffff),
        XShortField("subslotNumber", 0xffff),
        StrFixedLenField("padding", "", length=2),
        XShortEnumField("index", 0, IOD_WRITE_REQ_INDEX),
        FieldLenField("recordDataLength", None, fmt="I", length_of="blocks"),
        StrFixedLenField("RWPadding", "", length=24),
        FieldListField("blocks", [],
                       PadFieldWithLen(PacketField("", None, IODWriteReq), 4),
                       length_from=lambda pkt: pkt.recordDataLength)
    ]
    # default values
    block_type = 0x0008
    index = 0xe040
    API = 0xffffffff
    slotNumber = 0xffff
    subslotNumber = 0xffff

    def post_build(self, p, pay):
        # patch the update of block_length, as requests field must not be
        # included. block_length is always 60
        if self.block_length is None:
            p = p[:2] + struct.pack("!H", 60) + p[4:]

        # Remove the final padding added in requests
        fld, val = self.getfield_and_val("blocks")
        if fld.i2count(self, val) > 0:
            length = len(val[-1])
            pad = fld.field.padlen(length)
            if pad > 0:
                p = p[:-pad]
                # also reduce the recordDataLength accordingly
                if self.recordDataLength is None:
                    val = struct.unpack("!I", p[36:40])[0]
                    val -= pad
                    p = p[:36] + struct.pack("!I", val) + p[40:]

        return Packet.post_build(self, p, pay)

    def get_response(self):
        """Generate the response block of this request.
        Careful: it only sets the fields which can be set from the request
        """
        res = IODWriteMultipleRes()
        for field in ["seqNum", "ARUUID", "API", "slotNumber",
                      "subslotNumber", "index"]:
            res.setfieldval(field, self.getfieldval(field))

        # append all block response
        res_blocks = []
        for block in self.getfieldval("blocks"):
            res_blocks.append(block.get_response())
        res.setfieldval("blocks", res_blocks)
        return res
示例#2
0
class TacacsAuthorizationReply(Packet):
    '''

    Tacacs authorization reply body from section 5.2
    https://tools.ietf.org/html/draft-ietf-opsawg-tacacs-06#section-5.2

    '''

    name = 'Tacacs Authorization Reply Body'
    fields_desc = [
        ByteEnumField('status', 0, TACACSAUTHORSTATUS),
        FieldLenField('arg_cnt', None, fmt='!B',
                      count_of='arg_len_list'),  # noqa: E501
        FieldLenField('server_msg_len', None, fmt='!H',
                      length_of='server_msg'),  # noqa: E501
        FieldLenField('data_len', None, fmt='!H', length_of='data'),
        FieldListField('arg_len_list', [],
                       ByteField('', 0),
                       length_from=lambda pkt: pkt.arg_cnt),
        StrLenField('server_msg', '',
                    length_from=lambda x: x.server_msg_len),  # noqa: E501
        StrLenField('data', '', length_from=lambda x: x.data_len)
    ]

    def guess_payload_class(self, pay):
        if self.arg_cnt > 0:
            return TacacsPacketArguments
        return conf.padding_layer
示例#3
0
class IODWriteMultipleRes(Block):
    """IODWriteMultiple response"""
    fields_desc = [
        BlockHeader,
        ShortField("seqNum", 0),
        UUIDField("ARUUID", None),
        XIntField("API", 0xffffffff),
        XShortField("slotNumber", 0xffff),
        XShortField("subslotNumber", 0xffff),
        StrFixedLenField("padding", "", length=2),
        XShortEnumField("index", 0, IOD_WRITE_REQ_INDEX),
        FieldLenField("recordDataLength", None, fmt="I", length_of="blocks"),
        XShortField("additionalValue1", 0),
        XShortField("additionalValue2", 0),
        IntEnumField("status", 0, ["OK"]),
        StrFixedLenField("RWPadding", "", length=16),
        FieldListField("blocks", [], PacketField("", None, IODWriteRes),
                       length_from=lambda pkt: pkt.recordDataLength)
    ]
    # default values
    block_type = 0x8008
    index = 0xe040

    def post_build(self, p, pay):
        # patch the update of block_length, as requests field must not be
        # included. block_length is always 60
        if self.block_length is None:
            p = p[:2] + struct.pack("!H", 60) + p[4:]

        return Packet.post_build(self, p, pay)
示例#4
0
class ISIS_ProtocolsSupportedTlv(ISIS_GenericTlv):
    name = "ISIS Protocols Supported TLV"
    fields_desc = [
        ByteEnumField("type", 129, _isis_tlv_names),
        FieldLenField("len", None, count_of="nlpids", fmt="B"),
        FieldListField("nlpids", [], ByteEnumField("", "IPv4", network_layer_protocol_ids), count_from=lambda pkt: pkt.len)
    ]
示例#5
0
class TacacsAccountingRequest(Packet):

    '''

    Tacacs accounting request body from section 6.1
    https://tools.ietf.org/html/draft-ietf-opsawg-tacacs-06#section-6.1

    '''

    name = 'Tacacs Accounting Request Body'
    fields_desc = [ByteEnumField('flags', 0, TACACSACNTFLAGS),
                   ByteEnumField('authen_method', 0, TACACSAUTHORTYPE),
                   ByteEnumField('priv_lvl', 1, TACACSPRIVLEVEL),
                   ByteEnumField('authen_type', 1, TACACSAUTHENTYPE),
                   ByteEnumField('authen_service', 1, TACACSAUTHENSERVICE),
                   FieldLenField('user_len', None, fmt='!B', length_of='user'),
                   FieldLenField('port_len', None, fmt='!B', length_of='port'),
                   FieldLenField('rem_addr_len', None, fmt='!B', length_of='rem_addr'),  # noqa: E501
                   FieldLenField('arg_cnt', None, fmt='!B', count_of='arg_len_list'),  # noqa: E501
                   FieldListField('arg_len_list', [], ByteField('', 0),
                                  length_from=lambda pkt: pkt.arg_cnt),
                   StrLenField('user', '', length_from=lambda x: x.user_len),
                   StrLenField('port', '', length_from=lambda x: x.port_len),
                   StrLenField('rem_addr', '', length_from=lambda x: x.rem_addr_len)]  # noqa: E501

    def guess_payload_class(self, pay):
        if self.arg_cnt > 0:
            return TacacsPacketArguments
        return conf.padding_layer
示例#6
0
文件: IGMP.py 项目: netsia/voltha_doc
class IGMPv3gr(Packet):
    """IGMPv3 Group Record, used in membership report"""

    name = "IGMPv3gr"

    igmp_v3_gr_types = {
        IGMP_V3_GR_TYPE_INCLUDE: "Include Mode",
        IGMP_V3_GR_TYPE_EXCLUDE: "Exclude Mode",
        IGMP_V3_GR_TYPE_CHANGE_TO_INCLUDE: "Change to Include Mode",
        IGMP_V3_GR_TYPE_CHANGE_TO_EXCLUDE: "Change to Exclude Mode",
        IGMP_V3_GR_TYPE_ALLOW_NEW: "Allow New Sources",
        IGMP_V3_GR_TYPE_BLOCK_OLD: "Block Old Sources"
    }

    fields_desc = [
        ByteEnumField("rtype", IGMP_V3_GR_TYPE_INCLUDE, igmp_v3_gr_types),
        ByteField("aux_data_len", 0),
        FieldLenField("numsrc", None, count_of="sources"),
        IPField("mcaddr", "0.0.0.0"),
        FieldListField("sources", None, IPField("src", "0.0.0.0"), "numsrc")
    ]

    def post_build(self, pkt, payload):
        pkt += payload
        if self.aux_data_len != 0:
            print "WARNING: Auxiliary Data Length must be zero (0)"
        return pkt
示例#7
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
示例#8
0
class IGMPv3gr(Packet):
    """IGMP Group Record for IGMPv3 Membership Report

    This class is derived from class Packet and should be added in the records
    of an instantiation of class IGMPv3mr.
    """
    name = "IGMPv3gr"
    igmpv3grtypes = {
        1: "Mode Is Include",
        2: "Mode Is Exclude",
        3: "Change To Include Mode",
        4: "Change To Exclude Mode",
        5: "Allow New Sources",
        6: "Block Old Sources"
    }

    fields_desc = [
        ByteEnumField("rtype", 1, igmpv3grtypes),
        ByteField("auxdlen", 0),
        FieldLenField("numsrc", None, count_of="srcaddrs"),
        IPField("maddr", "0.0.0.0"),
        FieldListField("srcaddrs", [],
                       IPField("sa", "0.0.0.0"),
                       count_from=lambda x: x.numsrc)
    ]  # noqa: E501

    def mysummary(self):
        """Display a summary of the IGMPv3 group record."""
        return self.sprintf(
            "IGMPv3 Group Record %IGMPv3gr.type% %IGMPv3gr.maddr%"
        )  # noqa: E501

    def default_payload_class(self, payload):
        return conf.padding_layer
示例#9
0
class PAS5211GetOnuAllocsResponse(PAS5211Msg):
    opcode = 9
    name = "PAS5211GetOnuAllocsResponse"
    fields_desc = [
        LEShortField("allocs_number", None),
        FieldListField("alloc_ids", None, LEShortField("alloc_id", None))
    ]
示例#10
0
class SMB2_Compression_Capabilities(Packet):
    name = "SMB2 Compression Capabilities"
    fields_desc = [
        FieldLenField(
            "CompressionAlgorithmCount", 0,
            fmt="<H",
            count_of="CompressionAlgorithms"
        ),
        ShortField("Padding", 0x0),
        IntEnumField("Flags", 0x0, {
            0x00000000: "SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE",
            0x00000001: "SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED",
        }),
        FieldListField(
            "CompressionAlgorithms",
            None,
            LEShortEnumField("", 0x0, SMB2_COMPRESSION_ALGORITHMS),
            count_from=lambda pkt: pkt.CompressionAlgorithmCount,
        ),
        # Pad the whole packet on 8 bytes
        XStrLenField(
            "Padding2", "",
            length_from=lambda pkt:
                    (8 - (2 + 2 + 4 + pkt.CompressionAlgorithmCount * 2)) % 8
        ),
    ]
示例#11
0
class VRRP(Packet):
    fields_desc = [
        BitField("version", 2, 4),
        BitField("type", 1, 4),
        ByteField("vrid", 1),
        ByteField("priority", 100),
        FieldLenField("ipcount", None, count_of="addrlist", fmt="B"),
        ByteField("authtype", 0),
        ByteField("adv", 1),
        XShortField("chksum", None),
        FieldListField("addrlist", [],
                       IPField("", "0.0.0.0"),
                       count_from=lambda pkt: pkt.ipcount),
        IntField("auth1", 0),
        IntField("auth2", 0)
    ]

    def post_build(self, p, pay):
        if self.chksum is None:
            ck = checksum(p)
            p = p[:6] + chb(ck >> 8) + chb(ck & 0xff) + p[8:]
        return p

    @classmethod
    def dispatch_hook(cls, _pkt=None, *args, **kargs):
        if _pkt and len(_pkt) >= 9:
            ver_n_type = orb(_pkt[0])
            if ver_n_type >= 48 and ver_n_type <= 57:  # Version == 3
                return VRRPv3
        return VRRP
示例#12
0
class UDS_RDBI(Packet):
    dataIdentifiers = ObservableDict()
    name = 'ReadDataByIdentifier'
    fields_desc = [
        FieldListField("identifiers", [],
                       XShortEnumField('dataIdentifier', 0, dataIdentifiers))
    ]
示例#13
0
文件: zigbee.py 项目: mingqian/scapy
class ZigbeeNWK(Packet):
    name = "Zigbee Network Layer"
    fields_desc = [
        BitField("discover_route", 0, 2),
        BitField("proto_version", 2, 4),
        BitEnumField("frametype", 0, 2, {0: 'data', 1: 'command'}),
        FlagsField("flags", 0, 8, ['multicast', 'security', 'source_route', 'extended_dst', 'extended_src', 'reserved1', 'reserved2', 'reserved3']),  # noqa: E501
        XLEShortField("destination", 0),
        XLEShortField("source", 0),
        ByteField("radius", 0),
        ByteField("seqnum", 1),

        # ConditionalField(XLongField("ext_dst", 0), lambda pkt:pkt.flags & 8),

        ConditionalField(dot15d4AddressField("ext_dst", 0, adjust=lambda pkt, x: 8), lambda pkt:pkt.flags & 8),  # noqa: E501
        ConditionalField(dot15d4AddressField("ext_src", 0, adjust=lambda pkt, x: 8), lambda pkt:pkt.flags & 16),  # noqa: E501

        ConditionalField(ByteField("relay_count", 1), lambda pkt:pkt.flags & 0x04),  # noqa: E501
        ConditionalField(ByteField("relay_index", 0), lambda pkt:pkt.flags & 0x04),  # noqa: E501
        ConditionalField(FieldListField("relays", [], XLEShortField("", 0x0000), count_from=lambda pkt:pkt.relay_count), lambda pkt:pkt.flags & 0x04),  # noqa: E501
    ]

    def guess_payload_class(self, payload):
        if self.flags & 0x02:
            return ZigbeeSecurityHeader
        elif self.frametype == 0:
            return ZigbeeAppDataPayload
        elif self.frametype == 1:
            return ZigbeeNWKCommandPayload
        else:
            return Packet.guess_payload_class(self, payload)
示例#14
0
class Fattr3(Packet):
    name = 'File Attributes'
    fields_desc = [
        IntEnumField('type', 0, ftype3),
        OIntField('mode', 0),
        IntField('nlink', 0),
        IntField('uid', 0),
        IntField('gid', 0),
        LongField('size', 0),
        LongField('used', 0),
        FieldListField('rdev', [0, 0],
                       IntField('', None),
                       count_from=lambda x: 2),
        XLongField('fsid', 0),
        XLongField('fileid', 0),
        IntField('atime_s', 0),
        IntField('atime_ns', 0),
        IntField('mtime_s', 0),
        IntField('mtime_ns', 0),
        IntField('ctime_s', 0),
        IntField('ctime_ns', 0)
    ]

    def extract_padding(self, s):
        return '', s
示例#15
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"), ]
示例#16
0
class TLS_Ext_UserMapping(TLS_Ext_Unknown):                         # RFC 4681
    name = "TLS Extension - User Mapping"
    fields_desc = [ShortEnumField("type", 6, _tls_ext),
                   ShortField("len", None),
                   FieldLenField("umlen", None, fmt="B", length_of="um"),
                   FieldListField("um", [],
                                  ByteField("umtype", 0),
                                  length_from=lambda pkt: pkt.umlen)]
示例#17
0
文件: modbus.py 项目: cbnoc/cbnoc2019
class ModbusPDU0CGetCommEventLogResponse(_ModbusPDUNoPayload):
    name = "Get Comm Event Log Response"
    fields_desc = [XByteField("funcCode", 0x0C),
                   ByteField("byteCount", 8),
                   XShortField("status", 0x0000),
                   XShortField("eventCount", 0x0108),
                   XShortField("messageCount", 0x0121),
                   FieldListField("event", [0x20, 0x00], XByteField("", 0x00))]
示例#18
0
class IE_ExtensionHeaderList(IE_Base):
    name = "Extension Header List"
    fields_desc = [
        ByteEnumField("ietype", 141, IEType),
        FieldLenField("length", None,
                      length_of="extension_headers"),  # noqa: E501
        FieldListField("extension_headers", [64, 192], ByteField("", 0))
    ]  # noqa: E501
示例#19
0
class OBD_IID0B(Packet):
    name = "IID_0B_InUsePerformanceTrackingForCompressionIgnitionVehicles"
    fields_desc = [
        FieldLenField('count', None, count_of='data', fmt='B'),
        FieldListField('data', None,
                       ShortField(b'', 0),
                       count_from=lambda pkt: pkt.count)
    ]
示例#20
0
class OBD_IID08(Packet):
    name = "IID_08_InUsePerformanceTracking"
    fields_desc = [
        FieldLenField('count', None, count_of='data', fmt='B'),
        FieldListField('data', None,
                       ShortField(b'', 0),
                       count_from=lambda pkt: pkt.count)
    ]
示例#21
0
class SDP_ServiceSearchAttributeRequest(Packet):
    fields_desc = [
        ByteField("pdu_id", 0x06),
        ShortField("transaction_id", 0x00),
        ShortField("param_len", 0),
        FieldListField("search_pattern", 0x00, ByteField("", None)),
        ShortField("max_attr_byte_count", 0),
        FieldListField("attr_id_list", 0x00, ByteField("", None)),
        ByteField("cont_state_len", 0),
    ]

    def post_build(self, p, pay):
        if not self.param_len:
            p = p[:3] + struct.pack("!H", len(p[5:]) + len(pay)) + p[5:]
        if not self.cont_state_len:
            p = p[:-1] + struct.pack("B", len(pay))
        return p + pay
示例#22
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"), ]
示例#23
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"), ]
示例#24
0
class EIR_CompleteList128BitServiceUUIDs(EIR_Element):
    name = "Complete list of 128-bit service UUIDs"
    fields_desc = [
        FieldListField("svc_uuids",
                       None,
                       BTUUID128Field("uuid", None),
                       length_from=EIR_Element.length_from)
    ]
示例#25
0
class OBD_IID0A(Packet):
    name = "IID_0A_EcuName"
    fields_desc = [
        FieldLenField('count', None, count_of='ecu_names', fmt='B'),
        FieldListField('ecu_names', None,
                       StrFixedLenField('', 0, 20),
                       count_from=lambda pkt: pkt.count)
    ]
示例#26
0
class EIR_CompleteList128BitServiceUUIDs(EIR_Element):
    name = "Complete list of 128-bit service UUIDs"
    fields_desc = [
        FieldListField("svc_uuids",
                       None,
                       UUIDField("uuid", None, uuid_fmt=UUIDField.FORMAT_REV),
                       length_from=EIR_Element.length_from)
    ]
示例#27
0
class EIR_CompleteList16BitServiceUUIDs(EIR_Element):
    name = "Complete list of 16-bit service UUIDs"
    fields_desc = [
        FieldListField("svc_uuids",
                       None,
                       XLEShortField("uuid", 0),
                       length_from=EIR_Element.length_from)
    ]
示例#28
0
class OBD_IID04(Packet):
    name = "IID_04_CalibrationId"
    fields_desc = [
        FieldLenField('count', None, count_of='calibration_identifications',
                      fmt='B'),
        FieldListField('calibration_identifications', None,
                       StrFixedLenField(b'', 0, 16),
                       count_from=lambda pkt: pkt.count)
    ]
示例#29
0
class OBD_IID02(Packet):
    name = "IID_02_VehicleIdentificationNumber"
    fields_desc = [
        FieldLenField('count', None, count_of='vehicle_identification_numbers',
                      fmt='B'),
        FieldListField('vehicle_identification_numbers', None,
                       StrFixedLenField(b'', 0, 17),
                       count_from=lambda pkt: pkt.count)
    ]
class Dot11EltRates(Dot11Elt):
    name = "802.11 Rates"
    fields_desc = [
        ByteField("ID", 1),
        ByteField("len", None),
        FieldListField("rates", [],
                       XByteField("", 0),
                       count_from=lambda p: p.len)
    ]
示例#31
0
文件: dhcp.py 项目: commial/scapy
 def getfield(self, pkt, s):
     ret = []
     while s:
         s, val = FieldListField.getfield(self, pkt, s)
         ret.append(val)
     return b"", [x[0] for x in ret]