Skip to content

dns: add tcp_reassemble for DNS over TCP - #5315

Open
varunswaika wants to merge 1 commit into
secdev:masterfrom
varunswaika:fix-4023
Open

varunswaika wants to merge 1 commit into
secdev:masterfrom
varunswaika:fix-4023

Conversation

@varunswaika

Copy link
Copy Markdown

Description

DNS has no tcp_reassemble, so streamcls falls back to DNS(data) and the RFC 1035 sect 4.2.2 length prefix is read as the id. This adds DNS.tcp_reassemble, which waits for the full message and returns DNSTCP. dns_resolve wraps its UDP socket in StreamSocket(sock, DNS), so it now uses SimpleSocket for UDP.

ans = DNSTCP(id=1, qr=1, qd=DNSQR(qname="example.com"), an=DNSRR(rrname="example.com", rdata="1.2.3.4"))
p = Ether(raw(Ether()/IP()/TCP(sport=53, dport=40000, flags="PA", seq=1)/raw(ans)))
sniff(offline=[p], session=TCPSession)[0][DNS].id   # 56 (the length), expected 1

fixes #4023

This message was written with the help of AI (Claude Opus 5.5).

TCPSession and StreamSocket dissected DNS over TCP as plain DNS, so the
two-byte length prefix was read as the id. dns_resolve now uses
SimpleSocket for UDP, since DNS datagrams have no length prefix.

AI-Assisted: yes (Claude Opus 5.5)
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.19%. Comparing base (0257318) to head (75c755c).

Files with missing lines Patch % Lines
scapy/layers/dns.py 86.66% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5315   +/-   ##
=======================================
  Coverage   81.19%   81.19%           
=======================================
  Files         376      376           
  Lines       99209    99222   +13     
=======================================
+ Hits        80550    80567   +17     
+ Misses      18659    18655    -4     
Files with missing lines Coverage Δ
scapy/layers/dns.py 83.14% <86.66%> (+0.02%) ⬆️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scapy doesn't assemble DNS queries/responses sent over TCP in more than one packet

1 participant