Repository: secdev/scapy (language: python)

Issue:
An NAPTR format has been added



Discussion / hints:

Fix patch:
diff --git a/scapy/layers/dns.py b/scapy/layers/dns.py
index eb3301876e5..2da34cebce3 100644
--- a/scapy/layers/dns.py
+++ b/scapy/layers/dns.py
@@ -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


Test patch:
diff --git a/test/scapy/layers/dns.uts b/test/scapy/layers/dns.uts
index e2912ac4943..3abe180e34d 100644
--- a/test/scapy/layers/dns.uts
+++ b/test/scapy/layers/dns.uts
@@ -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'