Skip to content

Commit

Permalink
[DNS] add NAPTR RRs (#4456)
Browse files Browse the repository at this point in the history
* An NAPTR format has been added

* tests: cover NAPTR RRs

* dns: refine NAPTR RRs

by making it consistent with the other RRs and fixing a bug where the
lengths of "flags", "services" and "regexp" weren't computed correctly
when they were instantiated because their default lengths were 0 instead
of None.

---------

Co-authored-by: Ivan Stepanenko <stepanenko-i@protei.ru>
  • Loading branch information
evverx and Ivan Stepanenko committed Jul 11, 2024
1 parent a1afb9a commit 3333075
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
22 changes: 22 additions & 0 deletions scapy/layers/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,11 +1111,33 @@ class DNSRRTSIG(_DNSRRdummy):
]


class DNSRRNAPTR(_DNSRRdummy):
name = "DNS NAPTR Resource Record"
fields_desc = [DNSStrField("rrname", ""),
ShortEnumField("type", 35, dnstypes),
BitField("cacheflush", 0, 1), # mDNS RFC 6762
BitEnumField("rclass", 1, 15, dnsclasses),
IntField("ttl", 0),
ShortField("rdlen", None),
ShortField("order", 0),
ShortField("preference", 0),
FieldLenField("flags_len", None, fmt="!B", length_of="flags"),
StrLenField("flags", "", length_from=lambda pkt: pkt.flags_len),
FieldLenField("services_len", None, fmt="!B", length_of="services"),
StrLenField("services", "",
length_from=lambda pkt: pkt.services_len),
FieldLenField("regexp_len", None, fmt="!B", length_of="regexp"),
StrLenField("regexp", "", length_from=lambda pkt: pkt.regexp_len),
DNSStrField("replacement", ""),
]


DNSRR_DISPATCHER = {
6: DNSRRSOA, # RFC 1035
13: DNSRRHINFO, # RFC 1035
15: DNSRRMX, # RFC 1035
33: DNSRRSRV, # RFC 2782
35: DNSRRNAPTR, # RFC 2915
41: DNSRROPT, # RFC 1671
43: DNSRRDS, # RFC 4034
46: DNSRRRSIG, # RFC 4034
Expand Down
11 changes: 11 additions & 0 deletions test/scapy/layers/dns.uts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,17 @@ assert DNSRR(raw(rr)).rdata == []
rr = DNSRR(rrname='scapy', type='TXT', rdata=[])
assert raw(rr) == b

= DNS record type 35 (NAPTR)

b = b'\x00\x00#\x00\x01\x00\x00\x00\x00\x00+\x00\n\x00d\x01u\x07E2U+sip\x1b!^.*$!sip:info@example.com!\x00'

p = DNSRRNAPTR(b)
assert p.order == 10 and p.preference == 100 and p.flags == b'u' and p.services == b'E2U+sip'
assert p.regexp == b'!^.*$!sip:info@example.com!' and p.replacement == b'.'

p = DNSRRNAPTR(order=10, preference=100, flags="u", services="E2U+sip", regexp="!^.*$!sip:info@example.com!")
assert raw(p) == b

= DNS record type 39 (DNAME)

b = b'\x05local\x00\x00\x27\x00\x01\x00\x00\x00\x00\x00\x07\x05local\x00'
Expand Down

0 comments on commit 3333075

Please sign in to comment.