Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: return CODE #17

Closed
bananabr opened this issue Oct 13, 2020 · 7 comments
Closed

Feature request: return CODE #17

bananabr opened this issue Oct 13, 2020 · 7 comments

Comments

@bananabr
Copy link

bananabr commented Oct 13, 2020

In some applications it is useful to know which was the DNS reply return code, specially SERVFAIL, NXDOMAIN and REFUSED. I am trying to use the lib to build a DNS brute-forcer for domain enumeration and performance looks great. However it would be of great value to also store those failed requests to detect subdomain takeover opportunities.

If you can give me some basic guidance I could probably implement this myself.

Thanks!

@bananabr
Copy link
Author

I found the return code but to be more precise I would like to have all the information massdns provides. Can you point me out where these fields exist in the DNSMessage returned by resolver.query?

Example:

{
  "name": "www.acronis.com.hk.",
  "type": "A",
  "class": "IN",
  "status": "NOERROR",
  "data": {
    "answers": [
      {
        "ttl": 300,
        "type": "CNAME",
        "class": "IN",
        "name": "www.acronis.com.hk.",
        "data": "www.acronis.com."
      },
      {
        "ttl": 1463,
        "type": "A",
        "class": "IN",
        "name": "www.acronis.com.",
        "data": "34.120.97.237"
      }
    ]
  },
  "resolver": "205.171.2.65:53"
}

@gera2ld
Copy link
Owner

gera2ld commented Oct 13, 2020

DNSMessage should contain all the information returned from a server, it's just a result of deserialization of the binary data.
The properties are named as described in RFC1035's Header section format.

class DNSMessage:
def __init__(self, qr=RESPONSE, qid=0, o=0, aa=0, tc=0, rd=1, ra=0, r=0):
self.qr = qr # 0 for request, 1 for response
self.qid = qid # id for UDP package
self.o = o # opcode: 0 for standard query
self.aa = aa # Authoritative Answer
self.tc = tc # TrunCation, will be updated on .pack()
self.rd = rd # Recursion Desired for request
self.ra = ra # Recursion Available for response
self.r = r # rcode: 0 for success
self.qd = []
self.an = [] # answers
self.ns = [] # authority records, aka nameservers
self.ar = [] # additional records

@bananabr
Copy link
Author

The SERVFAIL status currently raises an Assertion Exception. I believe, the DNSMessage should be returned and it should be up to the developer to determine what to do with that status. Another solution would be having an specific query method that does that. What do you think?

python -m async_dns.resolver -n 8.8.8.8 -t a -- message.acronis.com
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/__main__.py", line 57, in <module>
    loop.run_until_complete(resolve_hostnames(_parse_args()))
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/__main__.py", line 46, in resolve_hostnames
    res = fut.result()
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/__main__.py", line 24, in resolve_hostname
    return await resolver.query(hostname, qtype)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/__init__.py", line 38, in query
    result, _cached = await self.query_with_timeout(fqdn, qtype, timeout, tick)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/__init__.py", line 51, in query_with_timeout
    return await asyncio.wait_for(self._query(fqdn, qtype, tick), timeout)
  File "/usr/lib/python3.8/asyncio/tasks.py", line 483, in wait_for
    return fut.result()
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/__init__.py", line 66, in _query
    return await self._query_once(fqdn, qtype, tick)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/query.py", line 33, in query
    remote_res = await self.query_remote(domain, nameservers)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/query.py", line 90, in query_remote
    inter_res = await self.query_remote_once(domain, nameservers)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/query.py", line 148, in query_remote_once
    inter_res = await self.request_remote(nameservers, req)
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/query.py", line 178, in request_remote
    raise last_err
  File "/home/kali/Documents/mapless/samples/.venv/lib/python3.8/site-packages/async_dns/resolver/query.py", line 160, in request_remote
    assert inter_res.r != 2, 'Remote server fail'
AssertionError: Remote server fail

@bananabr
Copy link
Author

bananabr commented Oct 13, 2020

Or maybe have an specific Exception type so handling it is more straight forward.

@gera2ld
Copy link
Owner

gera2ld commented Oct 15, 2020

I believe, the DNSMessage should be returned and it should be up to the developer to determine what to do with that status.

I agree with this, so there should be a way to make a raw response.
Currently it tries several nameservers and fails when none of them returns a successful answer. It's more like a high level API so I guess it's not proper to give an internal response to the developer.

@Gulruhbet
Copy link

can you write the code here

@gera2ld
Copy link
Owner

gera2ld commented Apr 29, 2021

There is a client to get the raw response from remote server now. See readme for more detail.

@gera2ld gera2ld closed this as completed Apr 29, 2021
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

No branches or pull requests

3 participants