Skip to content
Visual explainer 3h to learn 4 steps

DNS & subdomain discovery

Map an in-scope domain's hosts using DNS data in your authorized scope.

By Invicly Tech, , in Ethical Hacking & Penetration Testing. About 9 minutes to read.

Topic 7 of 32

In short

DNS enumeration maps an in-scope domain's hosts by querying its records and discovering subdomains. Within the agreed scope it reveals servers and services worth examining later, and it is a staple of the recon phase.

Explained simply

DNS (Domain Name System) is the internet's phone book. It turns names like shop.example.com into IP addresses that computers use. Every domain publishes records in DNS, and many of them are public by design, because the whole internet needs to read them.

DNS enumeration means reading those records carefully to build a list of the domain's hosts. Where is the mail server? Which name servers answer for the domain? Which subdomains exist, like vpn, dev or staging? Each answer is a possible target for later, authorised testing.

Some of this is passive, such as reading certificate logs. Some is active, such as asking the domain's own name servers thousands of guessed names. Active steps touch the client's systems, so they must be in scope.

One rule matters more than any tool: a name under the client's domain is not always the client's server. A subdomain might point to a cloud service or another company. You check who owns the IP address before treating it as in scope.

Press Play on a diagram to walk through it one step at a time.

MapDNS records
example.com
  • A / AAAA
    • Host addresses
  • MX
    • Mail servers
  • NS
    • Name servers
  • TXT
    • SPF, verification
LayersWhat a domain's DNS tells you, layer by layer
  1. 1
    Registrar and NS

    Who manages the domain and its DNS

  2. 2
    Mail: MX, SPF, DMARC

    Email providers and policy

  3. 3
    Web: A, AAAA, CNAME

    Servers, CDNs and hosting platforms

  4. 4
    TXT verification tokens

    SaaS tools the company uses

  5. 5
    Subdomains

    vpn, dev, staging, api and more

In depth

The records that matter in recon

Beyond A, AAAA, MX and NS, several records reveal a lot. CNAME is an alias: shop.example.com may be a CNAME to a hosting platform, which tells you who really runs it. SOA (Start of Authority) names the primary name server and a contact mailbox. TXT records hold SPF rules that list every service allowed to send the domain's email, plus verification tokens that reveal SaaS tools, for example google-site-verification or MS= for Microsoft 365. SRV records advertise services such as _sip._tcp. CAA records list which certificate authorities may issue certificates for the domain. PTR records map an IP back to a name (reverse DNS).

DMARC lives at _dmarc.example.com and describes the domain's email authentication policy, which you can note in the report as an email security finding.

  • CNAME: who really hosts a name
  • TXT: SPF senders and SaaS verification tokens
  • SOA: primary name server and contact
  • SRV: service locations; CAA: allowed CAs
  • PTR: reverse lookup from IP to name

Zone transfers and why they are usually blocked

A zone transfer (AXFR) is how a primary name server copies the whole zone to its secondary servers, over TCP port 53. If a server allows AXFR from anyone, one query reveals every record in the zone, including internal names. That is a classic misconfiguration and a real finding.

Testing it is one query per name server: dig axfr @ns1.example.com example.com. A refusal ("Transfer failed") is the healthy result. Only run it against name servers in your scope. For practice, zonetransfer.me was set up by its owner to allow transfers on purpose.

The fix is to allow transfers only to the known secondary servers, for example with allow-transfer in BIND, and ideally to protect them with TSIG keys (shared secrets that sign the transfer).

SequenceA zone transfer request, safe and unsafe
Tester
Name server
  1. 1SOA query: who is primary?
    Tester to Name server: SOA query: who is primary?
  2. 2SOA record and serial
    Name server to Tester: SOA record and serial
  3. 3AXFR request over TCP 53
    Tester to Name server: AXFR request over TCP 53
  4. 4Secure: REFUSED
    Name server to Tester: Secure: REFUSED
  5. 5Misconfigured: every record
    Name server to Tester: Misconfigured: every record

Finding subdomains: passive first, then active

Start with passive sources: certificate logs, search results, archives and tools like subfinder that combine many public sources. They often find most names without touching the client.

Active brute force comes next if the RoE allows it. A tool sends DNS queries for words from a list (www, vpn, dev, api, and thousands more) and keeps the names that resolve. This sends traffic to the client's name servers, so it is active recon. Keep the rate moderate.

Watch for wildcard DNS: if *.example.com is set, every guessed name seems to exist. Test it by resolving a random name like q7x2k9-nothere.example.com. If it returns an address, filter out every result that matches that wildcard answer.

FlowFrom names to an in-scope host list
  1. 1
    Passive names

    CT logs, search, subfinder

  2. 2
    Active guesses

    Wordlist brute force if allowed

  3. 3
    Remove wildcards

    Drop answers matching a random name

  4. 4
    Resolve to IPs

    A, AAAA and CNAME targets

  5. 5
    Check ownership

    whois each IP, compare with scope

  6. 6
    Final list

    In scope, out of scope, ask client

Staying in scope and the defender's side

After resolving names, group the IPs by owner. Addresses in the client's own ranges are usually in scope. Addresses belonging to a CDN, a SaaS vendor or a hosting company need explicit written confirmation, and some can never be tested by you at all.

Two DNS issues are findings in themselves. A dangling CNAME points to a cloud resource that was deleted; if someone else can claim that resource name, they could serve content on the client's subdomain (subdomain takeover). Report it, but do not claim the resource yourself unless the RoE explicitly allows it. The other is an open zone transfer.

Defenders should keep an inventory of DNS records, remove stale ones when services are retired, restrict AXFR, and watch DNS query logs for brute-force patterns: many NXDOMAIN (non-existent name) answers from one source.

  • Group resolved IPs by owner before testing
  • Dangling CNAME: report possible subdomain takeover
  • Defenders: remove stale records when services retire
  • Many NXDOMAIN replies from one source suggest brute forcing

Learn it in 4 short steps

About 45m each. Track them with a timer in your plan.

  1. 1
    Explain DNS record types~45m
  2. 2
    Enumerate subdomains of a scope~45m
  3. 3
    Resolve hosts to addresses~45m
  4. 4
    Keep results inside the agreed scope~45m

Key points

  • DNS records reveal hosts, mail and name servers.
  • Subdomain discovery expands the known attack surface.
  • Stay strictly within the authorized scope.
  • Resolve discovered names to addresses for later phases.

Key terms

Tap a card to flip it. 0/4 known

Examples

Read a domain's public records with dig

Your scope includes example.com. Step 1: ask for the name servers and the SOA. Step 2: ask for mail and TXT records; the SPF line shows which providers send mail. Step 3: check the DMARC policy. Step 4: check whether ANY works; many servers now give a minimal answer to ANY queries (RFC 8482), so ask for each type instead. Step 5: do a reverse lookup on the web server's IP.

bash
D=example.com
dig +short NS $D
dig +short SOA $D
dig +short MX $D
dig +short TXT $D          # SPF and verification tokens
dig +short TXT _dmarc.$D
dig +short CAA $D
IP=$(dig +short A $D | head -n1)
dig +short -x "$IP"        # reverse DNS (PTR)

Test zone transfers on every in-scope name server

Step 1: list the domain's name servers. Step 2: ask each one for a zone transfer. Step 3: a "Transfer failed" line is the healthy, secure result; a long list of records is a finding. Step 4: if it works, save the output as evidence, report it as a misconfiguration, and recommend restricting transfers to the secondary servers. Practise first on zonetransfer.me, which allows it on purpose.

bash
D=zonetransfer.me    # practice domain; use your in-scope domain at work
for ns in $(dig +short NS $D); do
  echo "== $ns"
  dig axfr @"$ns" "$D" +noall +answer | head -n 20
done
# Secure servers print: ; Transfer failed.

Quick reference

  • dig +short TYPE name, where TYPE is A, AAAA, MX, NS, TXT, SOA, CAA or SRV
  • dig -x IP does a reverse (PTR) lookup
  • dig axfr @ns1.example.com example.com tests a zone transfer; refused is good
  • Resolve a random name first to detect wildcard DNS
  • subfinder -d example.com -silent collects subdomains from passive sources
  • dnsrecon -d example.com -t std runs standard record checks
  • whois each resolved IP: a name under the domain may be a third party's server

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which record would tell you the domain uses Microsoft 365 or Google Workspace?

Question 2

2A name server answers a zone transfer request with every record. What is the fix?

Question 3

3Every guessed subdomain resolves to the same IP. What is the most likely reason?

Question 4

4help.example.com is a CNAME to a SaaS help-desk vendor. Is the vendor's server in scope?

0/4 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    For a domain you own or example.com, list the NS, MX, TXT and SOA records and explain each in one sentence.

  2. Exercise 2medium

    Practise zone transfers on zonetransfer.me and list the record types you received.

  3. Exercise 3hard

    Write a script that takes a file of subdomains, removes wildcard answers, resolves the rest and prints name, IP and the IP's owning organisation.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

What is the difference between subfinder and a brute-force tool?
subfinder asks public sources such as certificate logs, so it is passive. A brute-force tool sends guesses to the target's DNS servers, so it is active and must be in scope.
Why does dig ANY return almost nothing?
Many DNS servers now answer ANY queries with a minimal response (RFC 8482) to prevent abuse. Ask for each record type separately instead.
What is a subdomain takeover?
It happens when a DNS record points to a cloud resource that was deleted, and someone else can claim that resource and serve content on the subdomain. The fix is to remove DNS records when services are retired.
ShareXLinkedInWhatsApp