zmap / zdns

Fast DNS Lookup Library and CLI Tool
Apache License 2.0
939 stars 123 forks source link

Fix all ns mode #305

Closed vishalmohanty closed 2 months ago

vishalmohanty commented 2 years ago

This diff does the following.

Test:

» echo "google.com" | ./zdns A --retries=10 --all-nameservers  | python -m json.tool
{
    "data": {
        "results": [
            {
                "nameserver": "ns4.google.com",
                "result": {
                    "answers": [
                        {
                            "answer": "142.251.32.46",
                            "class": "IN",
                            "name": "google.com",
                            "ttl": 300,
                            "type": "A"
                        }
                    ],
                    "protocol": "udp",
                    "resolver": "216.239.38.10:53"
                },
                "status": "NOERROR"
            },
            {
                "nameserver": "ns3.google.com",
                "result": {
                    "answers": [
                        {
                            "answer": "142.251.32.46",
                            "class": "IN",
                            "name": "google.com",
                            "ttl": 300,
                            "type": "A"
                        }
                    ],
                    "protocol": "udp",
                    "resolver": "216.239.36.10:53"
                },
                "status": "NOERROR"
            },
            {
                "nameserver": "ns1.google.com",
                "result": {
                    "answers": [
                        {
                            "answer": "142.251.32.46",
                            "class": "IN",
                            "name": "google.com",
                            "ttl": 300,
                            "type": "A"
                        }
                    ],
                    "protocol": "udp",
                    "resolver": "216.239.32.10:53"
                },
                "status": "NOERROR"
            },
            {
                "nameserver": "ns2.google.com",
                "result": {
                    "answers": [
                        {
                            "answer": "142.251.32.46",
                            "class": "IN",
                            "name": "google.com",
                            "ttl": 300,
                            "type": "A"
                        }
                    ],
                    "protocol": "udp",
                    "resolver": "216.239.34.10:53"
                },
                "status": "NOERROR"
            }
        ]
    },
    "name": "google.com",
    "status": "NOERROR",
    "timestamp": "2022-04-28T11:38:48-07:00"
}
LizIzhikevich commented 2 years ago

do you know why when running your example, but with the iterative flag, some results still are missing the protocol/resolver?

echo "google.com" | sudo ./zdns A --retries=10 --all-nameservers --iterative | jq

{
  "data": {
    "results": [
      {
        "nameserver": "ns2.google.com",
        "result": {
          "answers": [
            {
              "answer": "142.251.46.238",
              "class": "IN",
              "name": "google.com",
              "ttl": 300,
              "type": "A"
            }
          ],
          "protocol": "udp",
          "resolver": "216.239.36.10:53"
        },
        "status": "NOERROR"
      },
      {
        "nameserver": "ns1.google.com",
        "result": {
          "answers": [
            {
              "answer": "142.251.46.238",
              "class": "IN",
              "name": "google.com",
              "ttl": 300,
              "type": "A"
            }
          ],
          "protocol": "",
          "resolver": ""
        },
        "status": "NOERROR"
      },
      {
        "nameserver": "ns3.google.com",
        "result": {
          "answers": [
            {
              "answer": "142.251.46.238",
              "class": "IN",
              "name": "google.com",
              "ttl": 300,
              "type": "A"
            }
          ],
          "protocol": "",
          "resolver": ""
        },
        "status": "NOERROR"
      },
      {
        "nameserver": "ns4.google.com",
        "result": {
          "answers": [
            {
              "answer": "142.251.46.238",
              "class": "IN",
              "name": "google.com",
              "ttl": 300,
              "type": "A"
            }
          ],
          "protocol": "",
          "resolver": ""
        },
        "status": "NOERROR"
      }
    ]
  },
  "name": "google.com",
  "status": "NOERROR",
  "timestamp": "2022-04-28T19:33:24Z"
}
vishalmohanty commented 2 years ago

@LizIzhikevich that is because in the --iterative mode, the response is getting cached and hence the requests after the first all get back the cached response (with missing resolver). I need some help in running the --iterative mode without using the cache. --cache-size=0 still returns cached response.

LizIzhikevich commented 2 years ago

ok. im happy to approve this PR on my end---since it does solve the root problem--- but sounds like you might need to open a new issue that addresses cache=0 not working haha.

zakird commented 2 years ago

I want to take a pass on this before we merge. I'm not sure this is the right place for the code.

phillip-stephens commented 2 months ago

I'm going to close this PR but we'll be addressing --all-nameservers soon.