DNS Reconnaissance on the Lab Zone
DNS is the client's own map of its network, published for anyone to read. Mail records name the mail servers and often the e-mail provider; SPF records list every system allowed to send mail; reverse records name the machines behind addresses; a misconfigured server may hand over the whole zone. For a tester, DNS turns a short scope list into a list of named services with roles. This lesson works through the standard DNS checks against the lab zone lab.test, served by a small DNS server inside your sandbox, then shows the zone-transfer misconfiguration as a lab transcript with its detection and fix.
The record types and the resolution process are explained in DNS Resolution and Record Types; this lesson is about what a tester does with them.
Scope of the session
The session starts dnsmasq on 127.0.0.1:5353 with the lab zone, queries only that server, and stops it. Names outside lab.test are refused (the server has no upstream), and the container has no network. On a real engagement, queries to the client's authoritative name servers are active reconnaissance and belong inside the test window.
The standard checks
dnsmasq --conf-file=$SAMPLES/dns/lab.test.conf --pid-file="$PWD/dns.pid"
for i in $(seq 50); do dig @127.0.0.1 -p 5353 +short lab.test >/dev/null 2>&1 && break; sleep 0.1; done
D="dig @127.0.0.1 -p 5353"
echo "== apex records"
$D +noall +answer lab.test ANY | sort
echo "== mail exchanger, and what it resolves to"
$D +short lab.test MX
$D +short mail.lab.test
echo "== zone transfer attempt (AXFR)"
$D lab.test AXFR | grep -i 'transfer'
kill "$(cat dns.pid)"== apex records
lab.test. 0 IN A 10.10.0.10
lab.test. 0 IN MX 10 mail.lab.test.
lab.test. 0 IN TXT "v=spf1 ip4:10.10.0.25 -all"
== mail exchanger, and what it resolves to
10 mail.lab.test.
10.10.0.25
== zone transfer attempt (AXFR)
; Transfer failed.
Three facts came out of a handful of queries:
- The apex
lab.testpoints at10.10.0.10, the web server. - Mail goes to
mail.lab.test(10.10.0.25), and the SPF recordv=spf1 ip4:10.10.0.25 -allsays that host is the only system allowed to send mail for the domain. In real zones, SPFinclude:entries name the client's e-mail and marketing providers: third parties, so out of scope, but worth knowing. - The zone transfer is refused. That is the correct configuration and a negative result to record: "AXFR tested against the lab name server, refused".
Guessing names
Without a zone transfer, names are found by asking. A wordlist of common host names, each queried once, separates names that exist from NXDOMAIN answers. Real wordlists have thousands of entries; on a client's name servers that is a burst of queries the client will notice, so it belongs in the window and at a modest rate.
dnsmasq --conf-file=$SAMPLES/dns/lab.test.conf --pid-file="$PWD/dns.pid"
for i in $(seq 50); do dig @127.0.0.1 -p 5353 +short lab.test >/dev/null 2>&1 && break; sleep 0.1; done
printf '%s\n' www mail ns intranet vpn dev staging admin api backup > words.txt
while read -r w; do
ans=$(dig @127.0.0.1 -p 5353 +short "$w.lab.test" A | paste -sd' ')
status=$(dig @127.0.0.1 -p 5353 "$w.lab.test" A | grep -o 'status: [A-Z]*' | cut -d' ' -f2)
[ -n "$ans" ] && printf '%-18s %-8s %s\n' "$w.lab.test" "$status" "$ans"
done < words.txt
echo "names tried: $(wc -l < words.txt)"
echo "== reverse lookups of 10.10.0.1-60"
for i in $(seq 1 60); do
ptr=$(dig @127.0.0.1 -p 5353 +short -x "10.10.0.$i")
[ -n "$ptr" ] && echo "10.10.0.$i $ptr"
done
kill "$(cat dns.pid)"www.lab.test NOERROR 10.10.0.10
mail.lab.test NOERROR 10.10.0.25
ns.lab.test NOERROR 10.10.0.53
intranet.lab.test NOERROR www.lab.test. 10.10.0.10
names tried: 10
== reverse lookups of 10.10.0.1-60
10.10.0.10 lab.test.
10.10.0.25 mail.lab.test.
10.10.0.53 ns.lab.test.
Four of ten guesses exist. intranet.lab.test is a CNAME to www: the "intranet" is the public web server, or a virtual host on it, which is worth a test case of its own (does the web server serve internal content for that host name?). The reverse sweep found three named addresses in the first 60; addresses with no PTR record may still be live, so reverse DNS adds names but never proves absence.
A misconfigured zone, as a lab transcript
Lab session, authorised internal test of 10.10.0.0/24, from the tester's host 10.10.0.99, inside the window. The lab's BIND server ns.lab.test (10.10.0.53) was deliberately configured to allow zone transfers to anyone:
tester@lab:~$ dig @10.10.0.53 lab.test AXFR +nocmd +nostats
lab.test. 3600 IN SOA ns.lab.test. hostmaster.lab.test. 2026120101 3600 600 604800 300
lab.test. 3600 IN NS ns.lab.test.
lab.test. 3600 IN A 10.10.0.10
lab.test. 3600 IN MX 10 mail.lab.test.
backup01.lab.test. 3600 IN A 10.10.0.203
dev-db.lab.test. 3600 IN A 10.10.0.61
jenkins.lab.test. 3600 IN A 10.10.0.62
mail.lab.test. 3600 IN A 10.10.0.25
ns.lab.test. 3600 IN A 10.10.0.53
www.lab.test. 3600 IN A 10.10.0.10
lab.test. 3600 IN SOA ns.lab.test. hostmaster.lab.test. 2026120101 3600 600 604800 300The transfer hands over every name, including dev-db and jenkins, which no wordlist guess found, and backup01, which sits on an address the scope excludes (10.10.0.200/29), so it is reported as observed but not tested. The finding itself is usually rated low on its own (it discloses information, nothing more), but it shortens every later step for an attacker.
How it is detected
- On the name server: BIND's
xfer-outlog category records each transfer it serves (client @0x… 10.10.0.99#… (lab.test): transfer of 'lab.test/IN': AXFR started (serial 2026120101), then… AXFR ended: …), and refused attempts appear aszone transfer 'lab.test/AXFR/IN' denied; a served transfer to an address that is not a secondary server is an alert. - On the network: an IDS rule for TCP port 53 queries of type AXFR (252) from unexpected sources; DNS over TCP from a workstation is unusual in itself.
- In configuration review: any zone without an
allow-transferrestriction.
How it is fixed
Restrict transfers to the secondary servers, and authenticate them:
// named.conf (BIND 9), lab example
key "xfer-key" { algorithm hmac-sha256; secret "<base64 secret from tsig-keygen>"; };
zone "lab.test" {
type primary;
file "/var/lib/bind/db.lab.test";
allow-transfer { key xfer-key; }; // only secondaries holding the TSIG key
};
options { allow-transfer { none; }; }; // default for every other zoneThen retest with the same dig … AXFR from a non-secondary host: the expected result is Transfer failed. Also split DNS: internal names (dev-db, jenkins) belong in an internal-only view or zone, not in the one the Internet can query.
Pitfalls
- Wildcard records. A zone with
*.lab.testanswers every guess, so the brute-force reports thousands of "names". Query a random-looking name first (zz9-not-real.lab.test); if it resolves, filter by that answer. - Treating names as scope. Every name found is screened against the scope by its address.
- Querying public resolvers at high rate. It is rude, it may be rate-limited, and results may be cached and stale.
- Forgetting IPv6 (
AAAA) and the other types:TXT(SPF, verification tokens naming SaaS providers),SRV(_ldap._tcp,_sip._tls: service locations),CAA(which certificate authorities may issue).
Practice
- Add
AAAA,TXTandSRVqueries for_ldap._tcp.lab.testto the first session. What does the lab zone answer, and what would an answer for the SRV query tell you on a real network? - The AXFR transcript lists
dev-db.lab.testat10.10.0.61. What do you write in your notes before testing it?
Answers
- The lab zone has no AAAA or SRV records, so dig prints nothing for them with
+short; TXT returns the SPF record. On a real Windows network,_ldap._tcp.<domain>SRV records list the domain controllers: the identity infrastructure of the client, see Enumerating SMB and LDAP. - Source (AXFR from
ns.lab.test, time), the address, the scope check result (10.10.0.61is inside10.10.0.0/24and not excluded, so in scope), and a note that a development database reachable from the internal network is a priority test case.
Test yourself
What does the SPF record v=spf1 ip4:10.10.0.25 -all tell a tester?
- The web server's address
- That 10.10.0.25 is the only system allowed to send mail for the domain
- The DNS server's address
- That SPF is disabled
dig ... AXFR prints 'Transfer failed.' How do you record it?
- As a finding
- As a negative result: zone transfer tested and refused
- Not at all
- As a false positive
How is an open zone transfer fixed in BIND?
- Delete the zone
- allow-transfer restricted to secondaries, ideally authenticated with a TSIG key
- Use UDP only
- Rename the hosts
A reverse lookup of 10.10.0.5 returns nothing. What can you conclude?
- The host is down
- Nothing about liveness: the address simply has no PTR record
- It is out of scope
- The DNS server is broken