How to use the scapy.layers.inet.UDP 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 filvarga / srv6-mobile / test / test_reassembly.py View on Github external
def test_missing_upper(self):
        """ missing upper layer """
        p = (Ether(dst=self.src_if.local_mac, src=self.src_if.remote_mac) /
             IPv6(src=self.src_if.remote_ip6,
                  dst=self.src_if.local_ip6) /
             UDP(sport=1234, dport=5678) /
             Raw())
        self.extend_packet(p, 1000, self.padding)
        fragments = fragment_rfc8200(p, 1, 500)
        bad_fragment = p.__class__(scapy.compat.raw(fragments[1]))
        bad_fragment[IPv6ExtHdrFragment].nh = 59
        bad_fragment[IPv6ExtHdrFragment].offset = 0
        self.pg_enable_capture()
        self.src_if.add_stream([bad_fragment])
        self.pg_start()
        pkts = self.src_if.get_capture(expected_count=1)
        icmp = pkts[0]
        self.assertIn(ICMPv6ParamProblem, icmp)
        self.assert_equal(icmp[ICMPv6ParamProblem].code, 3, "ICMP code")
github filvarga / srv6-mobile / test / test_gre.py View on Github external
def create_tunnel_stream_4o4(self, src_if,
                                 tunnel_src, tunnel_dst,
                                 src_ip, dst_ip):
        pkts = []
        for i in range(0, 257):
            info = self.create_packet_info(src_if, src_if)
            payload = self.info_to_payload(info)
            p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
                 IP(src=tunnel_src, dst=tunnel_dst) /
                 GRE() /
                 IP(src=src_ip, dst=dst_ip) /
                 UDP(sport=1234, dport=1234) /
                 Raw(payload))
            info.data = p.copy()
            pkts.append(p)
        return pkts
github tintinweb / scapy-ssl_tls / scapy_ssl_tls / ssl_tls.py View on Github external
def pre_dissect(self, raw_bytes):
        # figure out if we're UDP or TCP
        if self.underlayer is not None and self.underlayer.haslayer(UDP):
            self.guessed_next_layer = DTLSRecord
        elif ord(raw_bytes[0]) & 0x80:
            self.guessed_next_layer = SSLv2Record
        else:
            self.guessed_next_layer = TLSRecord
        self.fields_desc = [PacketListField("records", None, self.guessed_next_layer)]
        return raw_bytes
github 4shadoww / hakkuframework / core / lib / scapy / contrib / ikev2.py View on Github external
def ikev2scan(ip):
    return sr(IP(dst=ip)/UDP()/IKEv2(init_SPI=RandString(8),
                                      exch_type=34)/IKEv2_payload_SA(prop=IKEv2_payload_Proposal()))
github secdev / scapy / scapy / layers / tftp.py View on Github external
def ack_WRQ(self, pkt):
        ip = pkt[IP]
        self.ip = ip.dst
        self.dst = ip.src
        self.filename = pkt[TFTP_WRQ].filename
        options = pkt.getlayer(TFTP_Options)
        self.l3 = IP(src=ip.dst, dst=ip.src) / UDP(sport=self.my_tid, dport=pkt.sport) / TFTP()  # noqa: E501
        if options is None:
            self.last_packet = self.l3 / TFTP_ACK(block=0)
            self.send(self.last_packet)
        else:
            opt = [x for x in options.options if x.oname.upper() == "BLKSIZE"]
            if opt:
                self.blksize = int(opt[0].value)
                self.debug(2, "Negotiated new blksize at %i" % self.blksize)
            self.last_packet = self.l3 / TFTP_OACK() / TFTP_Options(options=opt)  # noqa: E501
            self.send(self.last_packet)
github nccgroup / BLESuite / scapy / scapy / layers / l2tp.py View on Github external
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:
            tmp_len = len(pkt) + len(pay)
            pkt = pkt[:2] + struct.pack("!H", tmp_len) + pkt[4:]
        return pkt + pay


bind_bottom_up(UDP, L2TP, dport=1701)
bind_bottom_up(UDP, L2TP, sport=1701)
bind_layers(UDP, L2TP, dport=1701, sport=1701)
bind_layers(L2TP, PPP,)
github opencord / voltha / ponsim / ponsim.py View on Github external
def get_udp_dst(f):
            if f.haslayer(UDP):
                return f.getlayer(UDP).dport
github nccgroup / BLESuite / scapy / scapy / layers / hsrp.py View on Github external
StrFixedLenField("authdigest", b"\00" * 16, 16)]

    def post_build(self, p, pay):
        if self.len is None and pay:
            tmp_len = len(pay)
            p = p[:1] + hex(tmp_len)[30:] + p[30:]
        return p


bind_bottom_up(UDP, HSRP, dport=1985)
bind_bottom_up(UDP, HSRP, sport=1985)
bind_bottom_up(UDP, HSRP, dport=2029)
bind_bottom_up(UDP, HSRP, sport=2029)
bind_layers(UDP, HSRP, dport=1985, sport=1985)
bind_layers(UDP, HSRP, dport=2029, sport=2029)
DestIPField.bind_addr(UDP, "224.0.0.2", dport=1985)
DestIP6Field.bind_addr(UDP, "ff02::66", dport=2029)
github tklab-tud / ID2T / code / Lib / Memcached.py View on Github external
import scapy.layers.inet as inet


memcached_port = 11211


class Memcached_Request(packet.Packet):
    namez = "Memcached UDP request packet"
    fields_desc = [field.ShortField("RequestID", 0),
                   field.ShortField("SequenceNumber", 0),
                   field.ShortField("DatagramCount", 1),
                   field.ShortField("Reserved", 0),
                   field.StrField("Request", "\r\n")]


packet.bind_layers(inet.UDP, Memcached_Request, dport=11211)
github cisco-system-traffic-generator / trex-core / scripts / external_libs / scapy-2.3.1 / python3 / scapy / contrib / vqp.py View on Github external
ConditionalField(MACField("data", "00:00:00:00:00:00"),
                        lambda p:p.datatype==3078),
                ConditionalField(MACField("data", "00:00:00:00:00:00"),
                        lambda p:p.datatype==3080), 
                ConditionalField(StrLenField("data", None,
                        length_from=lambda p:p.len), 
                        lambda p:p.datatype not in [3073, 3078, 3080]),
        ]
        def post_build(self, p, pay):
                if self.len is None:
                        l = len(p.data)
                        p = p[:2]+struct.pack("!H",l)+p[4:]
                return p

bind_layers(UDP,        VQP,            sport=1589)
bind_layers(UDP,        VQP,            dport=1589)
bind_layers(VQP,        VQPEntry,       )
bind_layers(VQPEntry,   VQPEntry,       )