Labs / Recon / Recon: packets, banners and DNS

Lab 3 of 3 · Recon: packets, banners and DNS

DNS footprinting: a zone transfer maps the network

Footprint a domain through its own name server, then ask for the whole zone and read the internal network it hands over.

Start this lab 5 steps

The idea

Marek has an authorised engagement against Halcyon Media, a production company, and starts where almost every external test starts: the public DNS. A name server's whole job is to answer questions about a domain, so before Marek touches a single host he asks it the ordinary questions any client may ask (who is authoritative for the name, where its mail goes) and reads the answers for leads.

Then he asks the question the server should refuse: hand me the whole zone. Halcyon's name server was never told to say no, so it says yes: every name in halcyonmedia.test, public and internal alike, in one reply. His target is at 10.0.1.53; he names it directly rather than trusting a resolver to chase it.

The server that holds the zone
The server that holds the zone
Two records, one mail host
Two records, one mail host
By type, or the whole book at once
By type, or the whole book at once
The tool runs the same steps
The tool runs the same steps
One line refuses only the transfer
One line refuses only the transfer

Steps

  1. Ask who answers for the name

    DNS is a chain of servers, and footprinting starts by finding the one that speaks for your target: its authoritative name server, the server that holds the real records for halcyonmedia.test rather than a cached copy. Everything else you ask, you ask it.

    The NS record names that server. On a real engagement you find it with a dig +trace, or by asking the domain's parent (.test here) for the delegation; Marek was handed one address and confirms it is the right one to ask.

    dig is the standard tool for asking a name server a question: dig NS halcyonmedia.test @10.0.1.53 asks the server at 10.0.1.53 for the zone's NS records. The @ names the server to ask; without it dig would use the box's configured resolver, the server that normally looks names up for it.

    The reply's header carries flags, and the one to watch is aa, authoritative answer, set when the server holds the zone itself rather than quoting a cache.

    kali:~# dig NS halcyonmedia.test @10.0.1.53
  2. The records a domain volunteers

    Before the big ask, read what the server hands any client that asks politely. Two record types pay off first.

    MX (mail exchanger) names the host that receives the domain's email: a real server, usually reachable, and now on your list. TXT records hold free-form text: an SPF record says which hosts may send mail as the domain, and operators park all kinds of notes in TXT too. Each is a single ordinary lookup, the same kind a mail server or a browser makes a thousand times a day, so nothing here is yet unusual traffic.

    kali:~# dig MX halcyonmedia.test @10.0.1.53 +noall +answer
    kali:~# dig TXT halcyonmedia.test @10.0.1.53 +noall +answer
  3. Ask for the whole book

    A domain's records usually live on more than one name server, so the operator does not edit each by hand. One server is the primary; the others are secondaries that copy the entire zone from it with a single request called a zone transfer (AXFR). It is a legitimate, necessary mechanism: it is how a backup name server stays in sync.

    The catch is who may ask. A transfer should go only to the operator's own secondaries, and the allow-transfer setting is what restricts it. A server that was never given that line falls back to the default in BIND, the name-server software this zone runs on, and answers a transfer request from anyone.

    So Marek asks: dig AXFR requests the full zone, over TCP, from the server.

    kali:~# dig AXFR halcyonmedia.test @10.0.1.53
  4. The tool that does it for you

    dig AXFR proved the hole by hand. On a real engagement a tester reaches for a tool that does every part and formats the result: find the zone's name servers, try a transfer against each one, and print what comes back. dnsrecon is that tool, and it is already on this box.

    dnsrecon -n 10.0.1.53 -d halcyonmedia.test -t axfr: -d is the domain, -n is the name server to use, and -t axfr selects the zone-transfer test. Run it and read how it narrates the attack.

    kali:~# dnsrecon -n 10.0.1.53 -d halcyonmedia.test -t axfr
  5. Close it, and prove it is closed

    Swap seats. You run Halcyon's name server, and Marek's report names the hole: a transfer answered for anyone.

    The fix is the line the server never had: tell it who may transfer the zone. With no secondaries that need it, the honest answer is nobody: allow-transfer { none; };.

    Add that to the options block, reload the server, and then check two things: the bulk dump is refused, and ordinary resolution still works for everyone. A lock that breaks the website is no fix.

    ns1:~# sed -i '/allow-transfer { none; };/d; s/  allow-query { any; };/  allow-query { any; };\n  allow-transfer { none; };/' /etc/bind/named.conf
    ns1:~# named-checkconf
    ns1:~# rndc reload
    kali:~# dig AXFR halcyonmedia.test @10.0.1.53
    kali:~# dig +short www.halcyonmedia.test @10.0.1.53

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab