Exemple #1
0
class Redundancy(Packet):
    name = "Redundancy"
    fields_desc = [
        XBitField("RFU", 0, 1),
        XBitField("ChMaskCntl", 0, 3),
        XBitField("NbTrans", 0, 4)
    ]
Exemple #2
0
class DLsettings(Packet):
    name = "DLsettings"
    fields_desc = [
        BitField("OptNeg", 0, 1),
        XBitField("RX1DRoffset", 0, 3),
        XBitField("RX2_Data_rate", 0, 4)
    ]
Exemple #3
0
class IE_NSAPI(IE_Base):
    # Identifies a PDP context in a mobility management context specified by TEICP  # noqa: E501
    name = "NSAPI"
    fields_desc = [
        ByteEnumField("ietype", 20, IEType),
        XBitField("sparebits", 0x0000, 4),
        XBitField("NSAPI", RandNum(0, 15), 4)
    ]
Exemple #4
0
class SDEntry_EventGroup(_SDPacketBase):
    name = "Eventgroup Entry"
    fields_desc = _MAKE_SDENTRY_COMMON_FIELDS_DESC(
        SDENTRY_TYPE_EVTGRP_SUBSCRIBE)
    fields_desc += [
        XBitField("res", 0, 12),
        XBitField("cnt", 0, 4),
        XShortField("eventgroup_id", 0)
    ]
Exemple #5
0
class LoRa(Packet):  # default frame (unclear specs => taken from https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5677147/)  # noqa: E501
    name = "LoRa"
    version = "1.1"  # default version to parse
    encrypted = True
    fields_desc = [XBitField("Preamble", 0, 4),
                   XBitField("PHDR", 0, 16),
                   XBitField("PHDR_CRC", 0, 4),
                   PHYPayload,
                   ConditionalField(XShortField("CRC", 0),
                                    lambda pkt:(pkt.MType & 0b1 == 0))]
Exemple #6
0
def _MAKE_SDENTRY_COMMON_FIELDS_DESC(type):
    return [
        XByteField("type", type),
        XByteField("index_1", 0),
        XByteField("index_2", 0),
        XBitField("n_opt_1", 0, 4),
        XBitField("n_opt_2", 0, 4),
        XShortField("srv_id", 0),
        XShortField("inst_id", 0),
        XByteField("major_ver", 0),
        X3BytesField("ttl", 0)
    ]
Exemple #7
0
class GRH(Packet):
    name = "GRH"
    fields_desc = [
        BitField("ipver", 6, 4),
        BitField("tclass", 0, 8),
        BitField("flowlabel", 6, 20),
        ShortField("paylen", 0),
        ByteField("nexthdr", 0),
        ByteField("hoplmt", 0),
        XBitField("sgid", 0, 128),
        XBitField("dgid", 0, 128),
    ]
Exemple #8
0
class OFPFlowStats(Packet):
    def post_build(self, p, pay):
        if self.length is None:
            l = len(p) + len(pay)
            p = struct.pack("!H", l) + p[2:]
        return p + pay

    name = "OFP_FLOW_STATS"
    fields_desc = [
        ShortField("length", None),
        ByteField("table_id", 0),
        XByteField("pad1", 0),
        PacketField("match", OFPMatch(), OFPMatch),
        IntField("duration_sec", 0),
        IntField("duration_nsec", 0),
        ShortField("priority", 0),
        ShortField("idle_timeout", 0),
        ShortField("hard_timeout", 0),
        XBitField("pad2", 0, 48),
        LongField("cookie", 0),
        LongField("packet_count", 0),
        LongField("byte_count", 0),
        ActionPacketListField("actions", [],
                              Packet,
                              length_from=lambda pkt: pkt.length - 88)
    ]  # noqa: E501
Exemple #9
0
class SignalHeader(CAN):
    """Special implementation of a CAN Packet to allow dynamic binding.

    This class can be provided to CANSockets as basecls.

    Example:
        >>> class floatSignals(SignalPacket):
        >>>     fields_desc = [
        >>>         LEFloatSignalField("floatSignal2", default=0, start=32),
        >>>         BEFloatSignalField("floatSignal1", default=0, start=7)]
        >>>
        >>> bind_layers(SignalHeader, floatSignals, identifier=0x321)
        >>>
        >>> dbc_sock = CANSocket("can0", basecls=SignalHeader)

    All CAN messages received from this dbc_sock CANSocket will be interpreted
    as SignalHeader. Through Scapys ``bind_layers`` mechanism, all CAN messages
    with CAN identifier 0x321 will interpret the payload bytes of these
    CAN messages as floatSignals packet.
    """
    fields_desc = [
        FlagsField('flags', 0, 3, ['error',
                                   'remote_transmission_request',
                                   'extended']),
        XBitField('identifier', 0, 29),
        LenField('length', None, fmt='B'),
        ThreeBytesField('reserved', 0)
    ]

    def extract_padding(self, s):
        # type: (bytes) -> Tuple[bytes, Optional[bytes]]
        return s, None
Exemple #10
0
class PCO_DNS_Server_IPv6(PCO_Option):
    name = "PCO DNS Server IPv6 Address Request"
    fields_desc = [ShortEnumField("type", None, PCO_PROTOCOL_TYPES),
                   ByteField("length", 0),
                   ConditionalField(XBitField("address",
                                              "2001:db8:0:42::", 128),
                                    lambda pkt: pkt.length)]
Exemple #11
0
class OFPQTMinRate(_ofp_header):
    name = "OFPQT_MIN_RATE"
    fields_desc = [ShortEnumField("type", 1, ofp_queue_property_types),
                   ShortField("len", 16),
                   XIntField("pad", 0),
                   ShortField("rate", 0),
                   XBitField("pad2", 0, 48)]
Exemple #12
0
class OFPATEnqueue(OpenFlow):
    name = "OFPAT_ENQUEUE"
    fields_desc = [ShortEnumField("type", 11, ofp_action_types),
                   ShortField("len", 16),
                   ShortEnumField("port", 0, ofp_port_no),
                   XBitField("pad", 0, 48),
                   IntField("queue_id", 0)]
Exemple #13
0
class LDPLabelReqM(_LDP_Packet):
    name = "LDPLabelReqM"
    fields_desc = [BitField("u", 0, 1),
                   XBitField("type", 0x0401, 15),
                   ShortField("len", None),
                   IntField("id", 0),
                   FecTLVField("fec", None)]
Exemple #14
0
class LDPAddressWM(_LDP_Packet):
    name = "LDPAddressWM"
    fields_desc = [BitField("u", 0, 1),
                   XBitField("type", 0x0301, 15),
                   ShortField("len", None),
                   IntField("id", 0),
                   AddressTLVField("address", None)]
Exemple #15
0
class LDPInit(_LDP_Packet):
    name = "LDPInit"
    fields_desc = [BitField("u", 0, 1),
                   XBitField("type", 0x0200, 15),
                   ShortField("len", None),
                   IntField("id", 0),
                   CommonSessionTLVField("params", None)]
Exemple #16
0
class PNIORealTime_IOxS(Packet):
    """ IOCS and IOPS packets for PROFINET Real-Time payload """
    name = "PNIO RTC IOxS"
    fields_desc = [
        # IOxS.DataState -- IEC-61158 - 6 - 10 / FDIS ED 3, Table 181
        BitEnumField("dataState", 1, 1, ["bad", "good"]),
        # IOxS.Instance -- IEC-61158 - 6 - 10 / FDIS ED 3, Table 180
        BitEnumField("instance", 0, 2,
                     ["subslot", "slot", "device", "controller"]),
        # IOxS.reserved -- IEC-61158 - 6 - 10 / FDIS ED 3, line 2649
        XBitField("reserved", 0, 4),
        # IOxS.Extension -- IEC-61158-6-10/FDIS ED 3, Table 179
        BitField("extension", 0, 1),
    ]

    @classmethod
    def is_extension_set(cls, _pkt, _lst, p, _remain):
        ret = cls if isinstance(p, type(None)) or p.extension != 0 else None
        return ret

    @classmethod
    def get_len(cls):
        return sum(type(fld).i2len(None, 0) for fld in cls.fields_desc)

    def guess_payload_class(self, p):
        return conf.padding_layer
Exemple #17
0
class IE_TraceReference(IE_Base):
    # Identifies a record or a collection of records for a particular trace.
    name = "Trace Reference"
    fields_desc = [
        ByteEnumField("ietype", 27, IEType),
        XBitField("Trace_reference", None, 16)
    ]
Exemple #18
0
class IE_TraceType(IE_Base):
    # Indicates the type of the trace
    name = "Trace Type"
    fields_desc = [
        ByteEnumField("ietype", 28, IEType),
        XBitField("Trace_type", None, 16)
    ]
Exemple #19
0
class NewChannelAns_Status(Packet):
    name = "NewChannelAns_Status"
    fields_desc = [
        XBitField("RFU", 0, 6),
        BitField("Dataraterangeok", 0, 1),
        BitField("Channelfrequencyok", 0, 1)
    ]
Exemple #20
0
class IE_MSTimeZone(IE_Base):
    name = "MS Time Zone"
    fields_desc = [ByteEnumField("ietype", 153, IEType),
                   ShortField("length", None),
                   ByteField("timezone", 0),
                   BitField("spare", 0, 6),
                   XBitField("daylight_saving_time", 0x00, 2)]
Exemple #21
0
class OFPFlowStats(Packet):
    name = "OFP_FLOW_STATS"
    fields_desc = [
        ShortField("length", None),
        ByteField("table_id", 0),
        XByteField("pad1", 0),
        PacketField("match", OFPMatch(), OFPMatch),
        IntField("duration_sec", 0),
        IntField("duration_nsec", 0),
        ShortField("priority", 0),
        ShortField("idle_timeout", 0),
        ShortField("hard_timeout", 0),
        XBitField("pad2", 0, 48),
        LongField("cookie", 0),
        LongField("packet_count", 0),
        LongField("byte_count", 0),
        PacketListField("actions", [],
                        OFPAT,
                        ofp_action_cls,
                        length_from=lambda pkt: pkt.length - 88)
    ]

    def post_build(self, p, pay):
        if self.length is None:
            tmp_len = len(p) + len(pay)
            p = struct.pack("!H", tmp_len) + p[2:]
        return p + pay

    def extract_padding(self, s):
        return b"", s
Exemple #22
0
class CAN(Packet):
    """A minimal implementation of the CANopen protocol, based on
    Wireshark dissectors. See https://wiki.wireshark.org/CANopen

    """
    fields_desc = [
        FlagsField('flags', 0, 3, ['error',
                                   'remote_transmission_request',
                                   'extended']),
        XBitField('identifier', 0, 29),
        FieldLenField('length', None, length_of='data', fmt='B'),
        ThreeBytesField('reserved', 0),
        StrLenField('data', b'', length_from=lambda pkt: int(pkt.length)),
    ]

    @staticmethod
    def inv_endianness(pkt):
        # type: (bytes) -> bytes
        """ Invert the order of the first four bytes of a CAN packet

        This method is meant to be used specifically to convert a CAN packet
        between the pcap format and the socketCAN format

        :param pkt: str of the CAN packet
        :return: packet str with the first four bytes swapped
        """
        len_partial = len(pkt) - 4  # len of the packet, CAN ID excluded
        return struct.pack('<I{}s'.format(len_partial),
                           *struct.unpack('>I{}s'.format(len_partial), pkt))

    def pre_dissect(self, s):
        # type: (bytes) -> bytes
        """ Implements the swap-bytes functionality when dissecting """
        if conf.contribs['CAN']['swap-bytes']:
            data = CAN.inv_endianness(s)  # type: bytes
            return data
        return s

    def post_dissect(self, s):
        # type: (bytes) -> bytes
        self.raw_packet_cache = None  # Reset packet to allow post_build
        return s

    def post_build(self, pkt, pay):
        # type: (bytes, bytes) -> bytes
        """ Implements the swap-bytes functionality when building

        this is based on a copy of the Packet.self_build default method.
        The goal is to affect only the CAN layer data and keep
        under layers (e.g LinuxCooked) unchanged
        """
        if conf.contribs['CAN']['swap-bytes']:
            data = CAN.inv_endianness(pkt)  # type: bytes
            return data + pay
        return pkt + pay

    def extract_padding(self, p):
        # type: (bytes) -> Tuple[bytes, Optional[bytes]]
        return b'', p
Exemple #23
0
class OFPATSetDlSrc(_ofp_action_header):
    name = "OFPAT_SET_DL_SRC"
    fields_desc = [
        ShortEnumField("type", 4, ofp_action_types),
        ShortField("len", 16),
        MACField("dl_addr", "0"),
        XBitField("pad", 0, 48)
    ]
Exemple #24
0
class RXParamSetupAns_Status(Packet):
    name = "RXParamSetupAns_Status"
    fields_desc = [
        XBitField("RFU", 0, 5),
        BitField("RX1DRoffsetACK", 0, 1),
        BitField("RX2DatarateACK", 0, 1),
        BitField("ChannelACK", 0, 1)
    ]
Exemple #25
0
class _SOMEIP_MessageId(Packet):
    """ MessageId subpacket."""
    name = "MessageId"
    fields_desc = [
        XShortField("srv_id", 0),
        BitEnumField("sub_id", 0, 1, {
            0: "METHOD_ID",
            1: "EVENT_ID"
        }),
        ConditionalField(XBitField("method_id", 0, 15),
                         lambda pkt: pkt.sub_id == 0),
        ConditionalField(XBitField("event_id", 0, 15),
                         lambda pkt: pkt.sub_id == 1)
    ]

    def extract_padding(self, s):
        return "", s
Exemple #26
0
class OFPATSetDlDst(OpenFlow):
    name = "OFPAT_SET_DL_DST"
    fields_desc = [
        ShortEnumField("type", 5, ofp_action_types),
        ShortField("len", 16),
        MACField("dl_addr", "0"),
        XBitField("pad", 0, 48)
    ]
Exemple #27
0
class OBD_DTC(OBD_Packet):
    name = "DiagnosticTroubleCode"

    locations = {
        0b00: 'Powertrain',
        0b01: 'Chassis',
        0b10: 'Body',
        0b11: 'Network',
    }

    fields_desc = [
        BitEnumField('location', 0, 2, locations),
        XBitField('code1', 0, 2),
        XBitField('code2', 0, 4),
        XBitField('code3', 0, 4),
        XBitField('code4', 0, 4),
    ]
Exemple #28
0
class GTPPDUSessionContainer(Packet):
    name = "GTP PDU Session Container"
    fields_desc = [ByteField("ExtHdrLen", None),
                   BitField("type", 0, 4),
                   BitField("spare1", 0, 4),
                   BitField("P", 0, 1),
                   BitField("R", 0, 1),
                   BitField("QFI", 0, 6),
                   ConditionalField(XBitField("PPI", 0, 3),
                                    lambda pkt: pkt.P == 1),
                   ConditionalField(XBitField("spare2", 0, 5),
                                    lambda pkt: pkt.P == 1),
                   ConditionalField(ByteField("pad1", 0),
                                    lambda pkt: pkt.P == 1),
                   ConditionalField(ByteField("pad2", 0),
                                    lambda pkt: pkt.P == 1),
                   ConditionalField(ByteField("pad3", 0),
                                    lambda pkt: pkt.P == 1),
                   ConditionalField(StrLenField(
                       "extraPadding",
                       "",
                       length_from=lambda pkt: 4 * (pkt.ExtHdrLen) - 4),
                       lambda pkt: pkt.ExtHdrLen and pkt.ExtHdrLen > 1),
                   ByteEnumField("NextExtHdr", 0, ExtensionHeadersTypes), ]

    def guess_payload_class(self, payload):
        if self.NextExtHdr == 0:
            sub_proto = orb(payload[0])
            if sub_proto >= 0x45 and sub_proto <= 0x4e:
                return IP
            elif (sub_proto & 0xf0) == 0x60:
                return IPv6
            else:
                return PPP
        return GTPHeader.guess_payload_class(self, payload)

    def post_build(self, p, pay):
        p += pay
        if self.ExtHdrLen is None:
            if self.P == 1:
                hdr_len = 2
            else:
                hdr_len = 1
            p = struct.pack("!B", hdr_len) + p[1:]
        return p
Exemple #29
0
class IrLAPHead(Packet):
    name = "IrDA Link Access Protocol Header"
    fields_desc = [
        XBitField("Address", 0x7f, 7),
        BitEnumField("Type", 1, 1, {
            "Response": 0,
            "Command": 1
        })
    ]
Exemple #30
0
class IE_EvolvedAllocationRetentionPriority(IE_Base):
    name = "Evolved Allocation/Retention Priority"
    fields_desc = [ByteEnumField("ietype", 191, IEType),
                   ShortField("length", 1),
                   BitField("Spare", 0, 1),
                   BitField("PCI", 0, 1),
                   XBitField("PL", 0x0000, 4),
                   BitField("Spare", 0, 1),
                   BitField("PVI", 0, 1)]