Skip to content

Commit 2b220b9

Browse files
authored
dns: fix off-by-four in EDNS0 OWNER Option (#4955)
The lengths taken from https://datatracker.ietf.org/doc/html/draft-cheshire-edns0-owner-option-01 are off by four because they include the length of the two-byte EDNS0 option code and the length of the two-byte EDNS0 option length but according to https://datatracker.ietf.org/doc/html/rfc6891#section-6.1.2 the length should include the size of data only so all the lengths should be decreased by 4 to parse the OWNER option containing the wakeup MAC correctly. Without this patch the wakeup MAC gets cut off: ``` >>> EDNS0OWN(b'\x00\x04\x00\x0e\x00\x9b\x11"3DUffUD3"\x11') <EDNS0OWN optcode=Owner optlen=14 v=0 s=155 primary_mac=11:22:33:44:55:66 |<Padding load=b'fUD3"\x11' |>> ``` With this patch it's included as expected ``` <EDNS0OWN optcode=Owner optlen=14 v=0 s=155 primary_mac=11:22:33:44:55:66 wakeup_mac=66:55:44:33:22:11 |> ```
1 parent 04b99c3 commit 2b220b9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

scapy/layers/dns.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,11 @@ class EDNS0OWN(_EDNS0Dummy):
494494
MACField("primary_mac", "00:00:00:00:00:00"),
495495
ConditionalField(
496496
MACField("wakeup_mac", "00:00:00:00:00:00"),
497-
lambda pkt: (pkt.optlen or 0) >= 18),
497+
lambda pkt: (pkt.optlen or 0) >= 14),
498498
ConditionalField(
499499
StrLenField("password", "",
500-
length_from=lambda pkt: pkt.optlen - 18),
501-
lambda pkt: (pkt.optlen or 0) >= 22)]
500+
length_from=lambda pkt: pkt.optlen - 14),
501+
lambda pkt: (pkt.optlen or 0) >= 18)]
502502

503503
def post_build(self, pkt, pay):
504504
pkt += pay

test/scapy/layers/dns_edns0.uts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,32 @@ for opt_class in EDNS0OPT_DISPATCHER.values():
212212
p = DNSRROPT(raw(DNSRROPT(rdata=[EDNS0TLV(), opt_class(), opt_class()])))
213213
assert len(p.rdata) == 3
214214
assert all(Raw not in opt for opt in p.rdata)
215+
216+
217+
+ EDNS0 - Owner
218+
219+
= Dissection
220+
221+
p = EDNS0OWN(b'\x00\x04\x00\x08\x00\x9b\x11"3DUf')
222+
assert p.optcode == 4
223+
assert p.optlen == 8
224+
assert p.v == 0
225+
assert p.s == 155
226+
assert p.primary_mac == '11:22:33:44:55:66'
227+
228+
p = EDNS0OWN(b'\x00\x04\x00\x0e\x00\x9b\x11"3DUffUD3"\x11')
229+
assert p.optcode == 4
230+
assert p.optlen == 14
231+
assert p.v == 0
232+
assert p.s == 155
233+
assert p.primary_mac == '11:22:33:44:55:66'
234+
assert p.wakeup_mac == '66:55:44:33:22:11'
235+
236+
p = EDNS0OWN(b'\x00\x04\x00\x12\x00\x9b\x11"3DUffUD3"\x11abcd')
237+
assert p.optcode == 4
238+
assert p.optlen == 18
239+
assert p.v == 0
240+
assert p.s == 155
241+
assert p.primary_mac == '11:22:33:44:55:66'
242+
assert p.wakeup_mac == '66:55:44:33:22:11'
243+
assert p.password == b'abcd'

0 commit comments

Comments
 (0)