scapy icon indicating copy to clipboard operation
scapy copied to clipboard

DNSQR does not accept a list of strings

Open dexteradeus opened this issue 2 years ago • 3 comments

Brief description

In the past (ie; v2.4.5), DNSQR would accept a list of qname values, which would then be iterated over when sending packets. It now raises a traceback as it tries to convert each item in the list to its ord value (since it now expects the value to always be a string)

Scapy version

2.5.0

Python version

3.10

Operating system

Linux 6.1.5

Additional environment information

No response

How to reproduce

This stub script will show the error

from scapy.all import DNSQR
DNSQR(qname=["domain1.com", "domain2.com"], qtype="A")

Actual result

This traceback is generated:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/chand/src/scapy/scapy/base_classes.py", line 399, in __call__
    i.__init__(*args, **kargs)
  File "/home/chand/src/scapy/scapy/layers/dns.py", line 278, in __init__
    Packet.__init__(self, _pkt=_pkt, *args, **kwargs)
  File "/home/chand/src/scapy/scapy/packet.py", line 178, in __init__
    self.get_field(fname).any2i(self, value)
  File "/home/chand/src/scapy/scapy/fields.py", line 1392, in any2i
    return super(_StrField, self).any2i(pkt, x)  # type: ignore
  File "/home/chand/src/scapy/scapy/fields.py", line 228, in any2i
    return self.h2i(pkt, x)
  File "/home/chand/src/scapy/scapy/layers/dns.py", line 292, in h2i
    if x[-1:] != b"." and not _is_ptr(x):
  File "/home/chand/src/scapy/scapy/layers/dns.py", line 151, in _is_ptr
    (x and orb(x[-1]) == 0) or
  File "/home/chand/src/scapy/scapy/compat.py", line 331, in orb
    return ord(x)
TypeError: ord() expected a character, but string of length 11 found

Expected result

The object should be created and should look like this:

<DNSQR  qname=['domain1.com', 'domain2.com'] qtype=A |>

Related resources

No response

dexteradeus avatar Jan 23 '23 17:01 dexteradeus

@p-l- Is this still a valid issue up for grabs? If so, how can I assign this issue to myself?

rmhowe425 avatar Mar 14 '23 01:03 rmhowe425

Yep, that's a valid issue and you are more than welcome to work on it!

p-l- avatar Mar 14 '23 17:03 p-l-

FTR, the DNS layer is being rewritten in #4012.

guedou avatar May 31 '23 07:05 guedou