How to use the scapy.fields.IntField function in scapy

To help you get started, we’ve selected a few scapy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github secdev / scapy / scapy / contrib / ikev2.py View on Github external
return IKEv2_class.guess_payload_class(self, payload)

    def answers(self, other):
        if isinstance(other, IKEv2):
            if other.init_SPI == self.init_SPI:
                return 1
        return 0

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


class IKEv2_Key_Length_Attribute(IntField):
    # We only support the fixed-length Key Length attribute (the only one currently defined)  # noqa: E501
    def __init__(self, name):
        IntField.__init__(self, name, 0x800E0000)

    def i2h(self, pkt, x):
        return IntField.i2h(self, pkt, x & 0xFFFF)

    def h2i(self, pkt, x):
        return IntField.h2i(self, pkt, (x if x is not None else 0) | 0x800E0000)  # noqa: E501


class IKEv2_payload_Transform(IKEv2_class):
    name = "IKE Transform"
    fields_desc = [
        ByteEnumField("next_payload", None, {0: "last", 3: "Transform"}),
        ByteField("res", 0),
github secdev / scapy / scapy / contrib / sebek.py View on Github external
return self.sprintf("Sebek v3 (%SebekV3.cmd%)")


class SebekV2(SebekV3):
    def mysummary(self):
        if isinstance(self.underlayer, SebekHead):
            return self.underlayer.sprintf("Sebek v%SebekHead.version% %SebekHead.type% (%SebekV2.cmd%)")  # noqa: E501
        else:
            return self.sprintf("Sebek v2 (%SebekV2.cmd%)")


class SebekV3Sock(Packet):
    name = "Sebek v2 socket"
    fields_desc = [IntField("parent_pid", 0),
                   IntField("pid", 0),
                   IntField("uid", 0),
                   IntField("fd", 0),
                   IntField("inode", 0),
                   StrFixedLenField("cmd", "", 12),
                   IntField("data_length", 15),
                   IPField("dip", "127.0.0.1"),
                   ShortField("dport", 0),
                   IPField("sip", "127.0.0.1"),
                   ShortField("sport", 0),
                   ShortEnumField("call", 0, {"bind": 2,
                                              "connect": 3, "listen": 4,
                                              "accept": 5, "sendmsg": 16,
                                              "recvmsg": 17, "sendto": 11,
                                              "recvfrom": 12}),
                   ByteEnumField("proto", 0, IP_PROTOS)]

    def mysummary(self):
github secdev / scapy / scapy / layers / netflow.py View on Github external
NetflowFlowsetV9,
                NetflowDataflowsetV9,
                NetflowOptionsFlowsetV9]
            )
            pkt = struct.pack("!H", count) + pkt[2:]
        return pkt + pay


# https://tools.ietf.org/html/rfc5655#appendix-B.1.1
class NetflowHeaderV10(Packet):
    """IPFix (Netflow V10) Header"""
    name = "IPFix (Netflow V10) Header"
    fields_desc = [ShortField("length", None),
                   UTCTimeField("ExportTime", 0),
                   IntField("flowSequence", 0),
                   IntField("ObservationDomainID", 0)]


class NetflowTemplateFieldV9(Packet):
    name = "Netflow Flowset Template Field V9/10"
    fields_desc = [BitField("enterpriseBit", 0, 1),
                   BitEnumField("fieldType", None, 15,
                                NetflowV910TemplateFieldTypes),
                   ShortField("fieldLength", 0),
                   ConditionalField(IntField("enterpriseNumber", 0),
                                    lambda p: p.enterpriseBit)]

    def __init__(self, *args, **kwargs):
        Packet.__init__(self, *args, **kwargs)
        if self.fieldType is not None and not self.fieldLength and self.fieldType in NetflowV9TemplateFieldDefaultLengths:  # noqa: E501
            self.fieldLength = NetflowV9TemplateFieldDefaultLengths[self.fieldType]  # noqa: E501
github SecureAuthCorp / pysap / pysap / SAPMS.py View on Github external
ConditionalField(StrNullFixedLenPaddedField("parameter", "", 100), lambda pkt:pkt.opcode in [0x01, 0x2e]),

        # AD_RZL_STRG opcode
        ConditionalField(ByteEnumKeysField("rzl_strg_type", 1, ms_adm_rzl_strg_type_values), lambda pkt:pkt.opcode in [0x15]),
        ConditionalField(ByteField("rzl_strg_name_length", 0), lambda pkt:pkt.opcode in [0x15]),
        ConditionalField(ByteField("rzl_strg_value_offset", 0), lambda pkt:pkt.opcode in [0x15]),
        ConditionalField(ByteField("rzl_strg_value_length", 0), lambda pkt:pkt.opcode in [0x15]),
        ConditionalField(StrFixedLenField("rzl_strg_name", None, 20), lambda pkt:pkt.opcode in [0x15]),
        ConditionalField(IntField("rzl_strg_uptime", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_integer1", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_delay", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_integer3", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_users", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_quality", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_integer6", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_integer7", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_integer8", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(IntField("rzl_strg_integer9", 0), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type in [11, 15, 21, 31, 41, 51]),
        ConditionalField(StrFixedLenField("rzl_strg_value", None, 40), lambda pkt:pkt.opcode in [0x15] and pkt.rzl_strg_type not in [11, 15, 21, 31, 41, 51]),
        ConditionalField(StrFixedLenField("rzl_strg_padd2", None, 36), lambda pkt:pkt.opcode in [0x15]),
    ]


class SAPMSClient1(PacketNoPadded):
    """SAP Message Server Client packet version 1

    Packet that contains information about a client of the Message Server
    service. This packet is for version 1, which has been seen only on old
    releases (SAP NW 2004s).
    """
    name = "SAP Message Server Client version 1"
    fields_desc = [
github opencord / voltha / voltha / extensions / omci / omci_entities.py View on Github external
class_id = 257
    attributes = [
        ECA(ShortField("managed_entity_id", None), {AA.R},
            range_check=lambda x: x == 0),
        ECA(StrFixedLenField("equipment_id", None, 20), {AA.R}),
        ECA(ByteField("omcc_version", None), {AA.R}, avc=True),
        ECA(ShortField("vendor_product_code", None), {AA.R}),
        ECA(ByteField("security_capability", None), {AA.R},
            range_check=lambda x: 0 <= x <= 1),
        ECA(ByteField("security_mode", None), {AA.R, AA.W},
            range_check=lambda x: 0 <= x <= 1),
        ECA(ShortField("total_priority_queue_number", None), {AA.R}),
        ECA(ByteField("total_traffic_scheduler_number", None), {AA.R}),
        ECA(ByteField("mode", None), {AA.R}, deprecated=True),
        ECA(ShortField("total_gem_port_id_number", None), {AA.R}),
        ECA(IntField("sys_uptime", None), {AA.R}),
        ECA(BitField("connectivity_capability", None, size=16), {AA.R}),
        ECA(ByteField("current_connectivity_mode", None), {AA.R, AA.W},
            range_check=lambda x: 0 <= x <= 7),
        ECA(BitField("qos_configuration_flexibility", None, size=16),
            {AA.R}, optional=True),
        ECA(ShortField("priority_queue_scale_factor", None), {AA.R, AA.W},
            optional=True),
    ]
    mandatory_operations = {OP.Get, OP.Set}
    notifications = {OP.AttributeValueChange}


class Tcont(EntityClass):
    class_id = 262
    attributes = [
        ECA(ShortField("managed_entity_id", None), {AA.R}),
github opencord / voltha / voltha / extensions / eoam / EOAM_TLV.py View on Github external
class TibitStatsOptions(Packet):
    """ Variable Descriptor: Tibit Stats Options """
    name = "Tibit Stats Options"
    fields_desc = [ByteEnumField("branch", 0xB7, OamBranchEnum),
                   XShortField("leaf", 0x0111),
                   ]

class TibitStatsOptionsSet(Packet):
    """ Variable Descriptor: Tibit Stats Options Set"""
    name = "Tibit Stats Options Set"
    fields_desc = [ByteEnumField("branch", 0xB7, OamBranchEnum),
                   XShortField("leaf", 0x0111),
                   ByteField("length", 5),
                   ByteField("enable", 0),
                   IntField("period", 0),
                   ]


UpstreamSlaSubtypeEnum = { 0x00: "Terminator",
                           0x01: "Header",
                           0x02: "Max Grant Period",
                           0x03: "Min Grant Period",
                           0x04: "Service Limit",
                           0x05: "Fixed Rate",
                           0x06: "Guaranteed Rate",
                           0x07: "Best Effort Rate",
                           0x08: "Max Burst Size",
                           0x09: "Priority",
                         }

class UpstreamSla(Packet):
github opencord / voltha / voltha / extensions / omci / omci_entities.py View on Github external
4: 'XGEM HEC loss count',
        5: 'XGEM key errors',
        6: 'XGEM HEC error count',
    }


class XgPonDownstreamPerformanceMonitoringHistoryData(EntityClass):
    class_id = 345
    hidden = True
    attributes = [
        ECA(ShortField("managed_entity_id", None), {AA.R, AA.SBC}),
        ECA(ByteField("interval_end_time", None), {AA.R},),
        ECA(ShortField("threshold_data_1_2_id", None), {AA.R, AA.W, AA.SBC}),
        ECA(IntField("ploam_mic_error_count", None), {AA.R}, tca=True, counter=True),
        ECA(IntField("downstream_ploam_messages_count", None), {AA.R}, counter=True),
        ECA(IntField("profile_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("ranging_time_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("deactivate_onu_id_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("disable_serial_number_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("request_registration_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("assign_alloc_id_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("key_control_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("sleep_allow_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("baseline_omci_messages_received_count", None), {AA.R}, counter=True),
        ECA(IntField("extended_omci_messages_received_count", None), {AA.R}, counter=True),
        ECA(IntField("assign_onu_id_messages_received", None), {AA.R}, counter=True),
        ECA(IntField("omci_mic_error_count", None), {AA.R}, tca=True, counter=True),
    ]
    mandatory_operations = {OP.Create, OP.Delete, OP.Get, OP.Set}
    optional_operations = {OP.GetCurrentData}
    notifications = {OP.AlarmNotification}
    alarms = {
github secdev / scapy / scapy / layers / ntp.py View on Github external
IntField("unused9", 0),
        IP6Field("dstaddr6", "::"),
        IP6Field("srcaddr6", "::"),
    ]


class NTPInfoLoop(Packet):
    """
    Loop filter variables.
    """

    name = "info_loop"
    fields_desc = [
        TimeStampField("last_offset", 0),
        TimeStampField("drift_comp", 0),
        IntField("compliance", 0),
        IntField("watchdog_timer", 0)
    ]


class NTPInfoSys(Packet):
    """
    System info. Mostly the sys.* variables, plus a few unique to
    the implementation.
    """

    name = "info_sys"
    fields_desc = [
        IPField("peer", "0.0.0.0"),
        ByteField("peer_mode", 0),
        ByteField("leap", 0),
        ByteField("stratum", 0),
github secdev / scapy / scapy / contrib / bgp.py View on Github external
name = "MULTI_EXIT_DISC"
    fields_desc = [IntField("med", 0)]


#
# LOCAL_PREF
#

class BGPPALocalPref(Packet):
    """
    Packet handling the LOCAL_PREF attribute value.
    References: RFC 4271
    """

    name = "LOCAL_PREF"
    fields_desc = [IntField("local_pref", 0)]


#
# ATOMIC_AGGREGATE
#

class BGPPAAtomicAggregate(Packet):
    """
    Packet handling the ATOMIC_AGGREGATE attribute value.
    References: RFC 4271
    """

    name = "ATOMIC_AGGREGATE"


#
github SecureAuthCorp / pysap / pysap / SAPMS.py View on Github external
# MS_PROPERTY_PARAM
        ConditionalField(FieldLenField("param_len", 0, length_of="param", fmt="I"), lambda pkt:pkt.id in [0x04]),
        ConditionalField(StrLenField("param", "", length_from=lambda pkt: pkt.param_len), lambda pkt:pkt.id in [0x04]),
        ConditionalField(StrLenField("param_padding", "", length_from=lambda pkt: 100 - pkt.param_len), lambda pkt:pkt.id in [0x04]),
        ConditionalField(ShortField("pad3", 0), lambda pkt:pkt.id in [0x04]),
        ConditionalField(FieldLenField("value_len", 0x0, length_of="value", fmt="H"), lambda pkt:pkt.id in [0x04]),
        ConditionalField(StrLenField("value", "", length_from=lambda pkt:pkt.value_len), lambda pkt:pkt.id in [0x04]),

        # MS_PROPERTY_SERVICE
        ConditionalField(ShortField("service", 0), lambda pkt:pkt.id in [0x05]),
        ConditionalField(ByteField("value", 0), lambda pkt:pkt.id in [0x05]),

        # Release Information fields
        ConditionalField(StrNullFixedLenField("release", "720", length=10), lambda pkt:pkt.id in [0x07]),
        ConditionalField(IntField("patchno", 0), lambda pkt:pkt.id in [0x07]),
        ConditionalField(IntField("supplvl", 0), lambda pkt:pkt.id in [0x07]),
        ConditionalField(IntField("platform", 0), lambda pkt:pkt.id in [0x07]),
    ]


class SAPMSJ2EECluster(Packet):
    """SAP Message Server J2EE Cluster packet

    This packet is used for the Message Server protocol for J2EE cluster nodes.
    """
    name = "SAP Message Server J2EE Cluster"
    cluster_no = 68199
    node_no = 5
    cluster_no_id = cluster_no + 100 + 50 + node_no
    icm_port = 5020