Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions scapy/layers/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ def dns_get_str(s, p, pkt=None, _internal=False):
break
p = ((cur & ~0xc0) << 8) + orb(s[p]) - 12 # Follow the pointer
burned += 1
if p in processed_pointers:
warning("DNS decompression loop detected")
break
if pkt and hasattr(pkt, "_orig_s") and pkt._orig_s:
# There should not be a loop as pkt is None
name += dns_get_str(pkt._orig_s, p, None, _internal=True)[0]
if burned == max_length:
break
elif p in processed_pointers:
warning("DNS decompression loop detected")
break
elif not _internal:
raise Scapy_Exception("DNS message can't be compressed" +
"at this point!")
Expand Down
11 changes: 9 additions & 2 deletions test/regression.uts
Original file line number Diff line number Diff line change
Expand Up @@ -6667,8 +6667,10 @@ assert raw(recompressed) == raw(pkt)

assert dns_get_str(b"\x06cheese\x00blobofdata....\x06hamand\xc0\x0c", 22, _internal=True)[0] == b'hamand.cheese.'

from scapy.tools.UTscapy import Bunch
assert dns_get_str(b"\x06hamand\xc0\x0c", 0, pkt=Bunch(_orig_s=b"\x06cheese\x00blobofdata", _orig_p=22))[0] == b'hamand.cheese.'
# This non-regression test is meaningless. Should use real DNS payload
# in non-regression tests.
#from scapy.tools.UTscapy import Bunch
#assert dns_get_str(b"\x06hamand\xc0\x0c", 0, pkt=Bunch(_orig_s=b"\x06cheese\x00blobofdata", _orig_p=22))[0] == b'hamand.cheese.'

= Decompression loop in dns_get_str
~ dns
Expand All @@ -6681,6 +6683,11 @@ assert dns_get_str(b"\x04data\xc0\x0c", 0, _internal=True)[0] == b"data."
assert dns_get_str(b"\x06da", 0, _internal=True)[0] == b"da."
assert dns_get_str(b"\x04data\xc0\x01", 0, _internal=True)[0] == b"data."

= Other decompression loop in dns_get_str
~ dns
s = b'\x00\x00\x84\x00\x00\x00\x00\x02\x00\x00\x00\x06\x0bGourmandise\x04_smb\x04_tcp\x05local\x00\x00!\x80\x01\x00\x00\x00x\x00\x14\x00\x00\x00\x00\x01\xbd\x0bGourmandise\xc0"\x0bGourmandise\x0b_afpovertcp\xc0\x1d\x00!\x80\x01\x00\x00\x00x\x00\x08\x00\x00\x00\x00\x02$\xc09\xc09\x00\x1c\x80\x01\x00\x00\x00x\x00\x10\xfe\x80\x00\x00\x00\x00\x00\x00\x00s#\x99\xca\xf7\xea\xdc\xc09\x00\x01\x80\x01\x00\x00\x00x\x00\x04\xc0\xa8\x01x\xc09\x00\x1c\x80\x01\x00\x00\x00x\x00\x10*\x01\xcb\x00\x0bD\x1f\x00\x18k\xb1\x99\x90\xdf\x84.\xc0\x0c\x00/\x80\x01\x00\x00\x00x\x00\t\xc0\x0c\x00\x05\x00\x00\x80\x00@\xc0G\x00/\x80\x01\x00\x00\x00x\x00\t\xc0G\x00\x05\x00\x00\x80\x00@\xc09\x00/\x80\x01\x00\x00\x00x\x00\x08\xc09\x00\x04@\x00\x00\x08'
DNS(s)

= Layer binding

* Test DestMACField & DestIPField
Expand Down