Skip to content

Commit 71c23da

Browse files
authored
Merge pull request #1204 from gpotter2/bind-udp
Additional Loopback bind + LLMNR bind + SNMP bind
2 parents 55d7120 + 20a7d50 commit 71c23da

5 files changed

Lines changed: 38 additions & 18 deletions

File tree

scapy/layers/inet6.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4023,7 +4023,9 @@ def ra_reply_callback(req, iface):
40234023
bind_layers(CookedLinux, IPv6, proto = 0x86dd )
40244024
bind_layers(GRE, IPv6, proto = 0x86dd )
40254025
bind_layers(SNAP, IPv6, code = 0x86dd )
4026+
bind_layers(Loopback, IPv6, type = 0x18 )
40264027
bind_layers(Loopback, IPv6, type = 0x1c )
4028+
bind_layers(Loopback, IPv6, type = 0x1e )
40274029
bind_layers(IPerror6, TCPerror, nh = socket.IPPROTO_TCP )
40284030
bind_layers(IPerror6, UDPerror, nh = socket.IPPROTO_UDP )
40294031
bind_layers(IPv6, TCP, nh = socket.IPPROTO_TCP )

scapy/layers/l2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,13 @@ def m2i(self, pkt, x):
398398
def i2m(self, pkt, x):
399399
return x << 24
400400

401-
LOOPBACK_TYPES = { 0x2: "IPv4", 0x1c: "IPv6" }
401+
# https://github.com/wireshark/wireshark/blob/fe219637a6748130266a0b0278166046e60a2d68/epan/dissectors/packet-null.c
402+
# https://www.wireshark.org/docs/wsar_html/epan/aftypes_8h.html
403+
LOOPBACK_TYPES = { 0x2: "IPv4",
404+
0x7: "OSI",
405+
0x10: "Appletalk",
406+
0x17: "Netware IPX/SPX",
407+
0x18: "IPv6", 0x1c: "IPv6", 0x1e: "IPv6" }
402408

403409
class Loopback(Packet):
404410
"""*BSD loopback layer"""

scapy/layers/llmnr.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,19 @@ def answers(self, other):
4848
self.qr == 1 and
4949
other.qr == 0)
5050

51-
def _llmnr_dispatcher(x, *args, **kargs):
52-
cls = conf.raw_layer
53-
if len(x) >= 2:
54-
if (orb(x[2]) & 0x80): # Response
55-
cls = LLMNRResponse
56-
else: # Query
57-
cls = LLMNRQuery
58-
return cls(x, *args, **kargs)
51+
class _LLMNR(Packet):
52+
@classmethod
53+
def dispatch_hook(cls, _pkt=None, *args, **kargs):
54+
if len(_pkt) >= 2:
55+
if (orb(_pkt[2]) & 0x80): # Response
56+
return LLMNRResponse
57+
else: # Query
58+
return LLMNRQuery
59+
return cls
5960

60-
bind_bottom_up(UDP, _llmnr_dispatcher, { "dport": 5355 })
61-
bind_bottom_up(UDP, _llmnr_dispatcher, { "sport": 5355 })
61+
bind_bottom_up(UDP, _LLMNR, dport=5355)
62+
bind_bottom_up(UDP, _LLMNR, sport=5355)
63+
bind_layers(UDP, _LLMNR, sport=5355, dport=5355)
6264

6365
# LLMNRQuery(id=RandShort(), qd=DNSQR(qname="vista.")))
6466

scapy/layers/snmp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,11 @@ def answers(self, other):
238238
isinstance(other.PDU, SNMPset) ) and
239239
self.PDU.id == other.PDU.id )
240240

241-
bind_layers( UDP, SNMP, sport=161)
242-
bind_layers( UDP, SNMP, dport=161)
243-
bind_layers( UDP, SNMP, sport=162)
244-
bind_layers( UDP, SNMP, dport=162)
241+
bind_bottom_up(UDP, SNMP, sport=161)
242+
bind_bottom_up(UDP, SNMP, dport=161)
243+
bind_bottom_up(UDP, SNMP, sport=162)
244+
bind_bottom_up(UDP, SNMP, dport=162)
245+
bind_layers(UDP, SNMP, sport=161, dport=161)
245246

246247
def snmpwalk(dst, oid="1", community="public"):
247248
try:

test/regression.uts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,15 @@ assert(x.PDU.varbindlist[0].value == b"172.31.19.2")
800800
assert(x.PDU.varbindlist[2].oid == "1.3.6.1.4.1.253.8.64.4.2.1.5.10.14130400")
801801
assert(x.PDU.varbindlist[2].value == 1)
802802

803+
= Basic UDP/SNMP bindings
804+
~ SNMP ASN1
805+
z = UDP()/x
806+
z = UDP(raw(z))
807+
assert SNMP in z
808+
809+
x = UDP()/SNMP()
810+
assert x.sport == x.dport == 161
811+
803812
= ASN1 - ASN1_Object
804813
assert ASN1_Object(1) == ASN1_Object(1)
805814
assert ASN1_Object(1) > ASN1_Object(0)
@@ -3596,10 +3605,10 @@ test_show()
35963605
saved_AS_resolver = conf.AS_resolver
35973606
conf.AS_resolver = None
35983607
tr6.make_graph()
3599-
len(tr6.graphdef) == 492
3600-
tr6.graphdef.startswith("digraph trace {") == True
3608+
assert len(tr6.graphdef) == 530
3609+
assert tr6.graphdef.startswith("digraph trace {")
36013610
'"2001:db8::1 53/udp";' in tr6.graphdef
3602-
conf.AS_resolver = conf.AS_resolver
3611+
conf.AS_resolver = saved_AS_resolver
36033612

36043613
############
36053614
############

0 commit comments

Comments
 (0)