Performing DNS Enumeration and Zone Transfer
When to Use
- Mapping the external attack surface of a target organization during authorized penetration tests
- Discovering hidden subdomains, internal hostnames, and IP addresses exposed via DNS records
- Testing whether DNS servers allow unauthorized zone transfers that leak the entire zone file
- Identifying mail servers, name servers, and service records for further targeted testing
- Validating DNS security configurations including DNSSEC, SPF, DKIM, and DMARC
Do not use against domains you do not have authorization to test, for DNS amplification or reflection attacks, or to overwhelm DNS servers with excessive query volumes.
Most Often Missed & How to Confirm
- Every nameserver, not just the first: AXFR is often refused on ns1 but allowed on a forgotten secondary. Loop
dig AXFR example.com @<ns> over all NS records before calling zone transfer "blocked."
- Wildcard DNS poisons brute force: resolve a random
nonexistent-$RANDOM.example.com first; if it answers, a wildcard exists and gobuster/dnsenum hits are false positives — filter on the wildcard IP.
- Passive + active + CT, not one source: passive subfinder/amass misses internal-only names, brute force misses oddly-named hosts, and CT logs (
crt.sh) reveal both. Combine and dedupe or you under-report attack surface.
- TXT/SRV gold often skipped: enumerate
_dmarc, _domainkey selectors, _sip._tcp, _ldap._tcp, _kerberos._tcp and read SPF include: chains — these leak SaaS providers, AD, and internal hostnames.
- How to confirm a real finding: a successful AXFR returns SOA + the full record set (not
; Transfer failed); an internal-IP leak is a name resolving to RFC1918 (grep -E '^10\.|^192\.168\.'); a misconfig is ?all/+all in SPF or a missing _dmarc record.
- Don't conclude "no subdomains" until you've tried a 20k+ wordlist, passive sources, CT logs, and reverse-PTR sweeps of the resolved IP ranges.
Prerequisites
- Written authorization to perform DNS enumeration against the target domain
- DNS enumeration tools installed: dig, nslookup, host, dnsrecon, dnsenum, subfinder, amass
- Network access to the target's DNS servers (UDP/TCP port 53)
- Wordlist for subdomain brute-forcing (SecLists dns-wordlist or similar)
- Understanding of DNS record types (A, AAAA, CNAME, MX, NS, TXT, SOA, SRV, PTR)
Workflow
Step 1: Identify DNS Servers and Basic Records
# Find authoritative name servers
dig NS example.com +short
# ns1.example.com.
# ns2.example.com.
# Get SOA record for zone metadata
dig SOA example.com +short
# ns1.example.com. admin.example.com. 2024031501 3600 900 604800 86400
# Enumerate all common record types
dig example.com ANY +noall +answer
# Get MX records (mail servers)
dig MX example.com +short
# 10 mail.example.com.
# 20 mail-backup.example.com.
# Get TXT records (SPF, DKIM, DMARC, verification)
dig TXT example.com +short
# Check for DMARC policy
dig TXT _dmarc.example.com +short
# Check for DKIM selectors
dig TXT default._domainkey.example.com +short
dig TXT selector1._domainkey.example.com +short
dig TXT google._domainkey.example.com +short
# Get SRV records for common services
dig SRV _sip._tcp.example.com +short
dig SRV _ldap._tcp.example.com +short
dig SRV _kerberos._tcp.example.com +short
Step 2: Attempt Zone Transfers
# Attempt AXFR zone transfer against each name server
dig AXFR example.com @ns1.example.com
dig AXFR example.com @ns2.example.com
# Use host command for zone transfer
host -t axfr example.com ns1.example.com
# Use dnsrecon for automated zone transfer attempts
dnsrecon -d example.com -t axfr
# If zone transfer succeeds, save the output
dig AXFR example.com @ns1.example.com > zone_transfer_results.txt
# Test for IXFR (incremental zone transfer)
dig IXFR=2024031500 example.com @ns1.example.com
Step 3: Subdomain Enumeration via Brute Force
# Use dnsenum for comprehensive enumeration
dnsenum --dnsserver ns1.example.com --enum -f /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -r example.com -o dnsenum_output.xml
# Use dnsrecon with brute force
dnsrecon -d example.com -t brt -D /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
# Use gobuster for fast DNS brute forcing
gobuster dns -d example.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -t 50 -o gobuster_dns.txt
# Use subfinder for passive subdomain discovery
subfinder -d example.com -all -o subfinder_results.txt
# Use amass for comprehensive enumeration (passive + active)
amass enum -d example.com -passive -o amass_passive.txt
amass enum -d example.com -active -brute -o amass_active.txt
# Combine and deduplicate results
cat subfinder_results.txt amass_passive.txt amass_active.txt gobuster_dns.txt | sort -u > all_subdomains.txt
Step 4: Reverse DNS and PTR Enumeration
# Reverse DNS lookup on discovered IP ranges
dnsrecon -d example.com -t rvl -r 10.10.0.0/24
# PTR record enumeration for IP range
for ip in $(seq 1 254); do
result=$(dig -x 10.10.1.$ip +short 2>/dev/null)
if [ -n "$result" ]; then
echo "10.10.1.$ip -> $result"
fi
done
# Use Nmap for reverse DNS on a subnet
nmap -sL 10.10.0.0/24 | grep "(" | awk '{print $5, $6}'
# Check for DNS cache snooping (information about queried domains)
dig @ns1.example.com www.competitor.com +norecurse
Step 5: Analyze DNS Security Configuration
# Check DNSSEC validation
dig example.com +dnssec +short
dig DNSKEY example.com +short
dig DS example.com +short
# Test for DNS rebinding vulnerability
# Check if the DNS server has a short TTL that could enable rebinding
dig example.com +noall +answer | grep -i ttl
# Check for open recursive resolver (misconfiguration)
dig @ns1.example.com google.com +recurse
# If it resolves, the server is an open resolver
# Check for wildcard DNS records
dig nonexistent-subdomain-xyz123.example.com +short
# If it resolves, a wildcard record exists
# Test DNS over HTTPS/TLS support
# DoH test
curl -s -H 'accept: application/dns-json' 'https://dns.google/resolve?name=example.com&type=A'
# Verify SPF record for email security
dig TXT example.com +short | grep "v=spf1"
# Check for overly permissive SPF (+all, ?all)
Step 6: Resolve and Map All Discovered Subdomains
# Resolve all discovered subdomains to IP addresses
while read subdomain; do
ip=$(dig +short A "$subdomain" | head -1)
if [ -n "$ip" ]; then
echo "$subdomain,$ip"
fi
done < all_subdomains.txt > resolved_subdomains.csv
# Identify unique IP addresses and their locations
cut -d',' -f2 resolved_subdomains.csv | sort -u > unique_ips.txt
# Check for internal IP addresses leaked via DNS
grep -E "^10\.|^172\.(1[6-9]|2[0-9]|3[01])\.|^192\.168\." resolved_subdomains.csv > internal_ip_leaks.txt
# Use httpx to probe web services on discovered subdomains
cat all_subdomains.txt | httpx -title -status-code -tech-detect -o httpx_results.txt
# Screenshot web services for documentation
cat all_subdomains.txt | httpx -screenshot -o screenshots/
Key Concepts
| Term |
Definition |
| Zone Transfer (AXFR) |
DNS mechanism that replicates the complete zone file from a primary to secondary server; unauthorized transfers expose all records in the zone |
| Subdomain Enumeration |
Process of discovering valid subdomains through brute force, certificate transparency logs, search engines, and passive DNS databases |
| DNSSEC |
DNS Security Extensions that add cryptographic signatures to DNS responses, preventing cache poisoning and spoofing attacks |
| SPF/DKIM/DMARC |
Email authentication protocols defined in DNS TXT records that prevent email spoofing and domain impersonation |
| Wildcard DNS |
A DNS record using an asterisk (*) that matches any query for non-existent subdomains, potentially masking enumeration results |
| PTR Record |
Reverse DNS record that maps an IP address to a hostname, often revealing internal naming conventions and server roles |
Tools & Systems
- dig: Standard DNS lookup utility with full support for all record types, DNSSEC validation, and zone transfer queries
- dnsrecon: Comprehensive DNS enumeration tool supporting zone transfers, brute force, reverse lookup, cache snooping, and Google dork queries
- subfinder: Fast passive subdomain discovery tool that queries certificate transparency logs, search engines, and DNS databases
- Amass (OWASP): Advanced attack surface mapping tool with both passive and active DNS enumeration, graph analysis, and data source integration
- gobuster: Fast brute-force tool for DNS subdomain enumeration using configurable wordlists and concurrent threads
Common Scenarios
Scenario: External Reconnaissance for a Web Application Penetration Test
Context: A security consultant is performing external reconnaissance for a web application penetration test. The client's primary domain is example.com, and the scope includes all subdomains and related infrastructure. The consultant has authorization to enumerate DNS records and probe discovered web services.
Approach:
- Query NS, MX, TXT, and SOA records for example.com to map the DNS infrastructure
- Attempt zone transfers against both nameservers -- ns2 succeeds, revealing 347 DNS records including internal staging environments
- Run subfinder and amass in passive mode to discover 89 additional subdomains from certificate transparency logs
- Brute-force subdomains with a 20,000-word list using gobuster, discovering 12 more subdomains not found in passive sources
- Resolve all subdomains and identify 15 that resolve to internal RFC1918 addresses (information disclosure)
- Probe all web-accessible subdomains with httpx, discovering a staging environment (staging.example.com) with default credentials
- Report zone transfer vulnerability, internal IP disclosure, and exposed staging environment to the client
Pitfalls:
- Sending thousands of DNS queries per second and triggering rate limiting or DNS-based DDoS protection
- Not checking for wildcard DNS records, resulting in false positive subdomain discoveries
- Missing subdomains that use separate DNS providers or CDN-specific CNAME records
- Overlooking TXT records that contain API keys, verification tokens, or internal comments
Output Format
## DNS Enumeration Report
**Target Domain**: example.com
**Authorized Nameservers**: ns1.example.com (203.0.113.10), ns2.example.com (203.0.113.11)
### Zone Transfer Status
| Nameserver | AXFR Result | Records Obtained |
|------------|-------------|------------------|
| ns1.example.com | REFUSED | 0 |
| ns2.example.com | SUCCESS | 347 records |
### Subdomain Discovery Summary
| Method | Subdomains Found |
|--------|-----------------|
| Zone Transfer | 347 |
| Passive (subfinder + amass) | 89 |
| Active Brute Force | 12 |
| **Total Unique** | **412** |
### Critical Findings
1. **Zone Transfer Allowed** (High): ns2.example.com allows AXFR from any source
2. **Internal IP Disclosure** (Medium): 15 subdomains resolve to RFC1918 addresses
3. **Exposed Staging Environment** (High): staging.example.com accessible with default credentials
4. **Missing DMARC Policy** (Medium): No DMARC record found, enabling email spoofing
5. **Weak SPF Record** (Low): SPF uses ~all (soft fail) instead of -all (hard fail)
1---2name: performing-dns-enumeration-and-zone-transfer3description: Enumerates DNS records, attempts zone transfers, brute-forces subdomains, and maps DNS infrastructure during authorized reconnaissance to identify attack surface, misconfigurations, and information disclosure in target domains.4license: Apache-2.05---6# Performing DNS Enumeration and Zone Transfer
7
8## When to Use
9
10- Mapping the external attack surface of a target organization during authorized penetration tests
11- Discovering hidden subdomains, internal hostnames, and IP addresses exposed via DNS records
12- Testing whether DNS servers allow unauthorized zone transfers that leak the entire zone file
13- Identifying mail servers, name servers, and service records for further targeted testing
14- Validating DNS security configurations including DNSSEC, SPF, DKIM, and DMARC
15
16**Do not use** against domains you do not have authorization to test, for DNS amplification or reflection attacks, or to overwhelm DNS servers with excessive query volumes.
17
18## Most Often Missed & How to Confirm
19
20- **Every nameserver, not just the first:** AXFR is often refused on ns1 but allowed on a forgotten secondary. Loop `dig AXFR example.com @<ns>` over *all* NS records before calling zone transfer "blocked."
21- **Wildcard DNS poisons brute force:** resolve a random `nonexistent-$RANDOM.example.com` first; if it answers, a wildcard exists and gobuster/dnsenum hits are false positives — filter on the wildcard IP.
22- **Passive + active + CT, not one source:** passive subfinder/amass misses internal-only names, brute force misses oddly-named hosts, and CT logs (`crt.sh`) reveal both. Combine and dedupe or you under-report attack surface.
23- **TXT/SRV gold often skipped:** enumerate `_dmarc`, `_domainkey` selectors, `_sip._tcp`, `_ldap._tcp`, `_kerberos._tcp` and read SPF `include:` chains — these leak SaaS providers, AD, and internal hostnames.
24- **How to confirm a real finding:** a successful AXFR returns SOA + the full record set (not `; Transfer failed`); an internal-IP leak is a name resolving to RFC1918 (`grep -E '^10\.|^192\.168\.'`); a misconfig is `?all`/`+all` in SPF or a missing `_dmarc` record.
25- **Don't conclude "no subdomains"** until you've tried a 20k+ wordlist, passive sources, CT logs, and reverse-PTR sweeps of the resolved IP ranges.
26
27## Prerequisites
28
29- Written authorization to perform DNS enumeration against the target domain
30- DNS enumeration tools installed: dig, nslookup, host, dnsrecon, dnsenum, subfinder, amass
31- Network access to the target's DNS servers (UDP/TCP port 53)
32- Wordlist for subdomain brute-forcing (SecLists dns-wordlist or similar)
33- Understanding of DNS record types (A, AAAA, CNAME, MX, NS, TXT, SOA, SRV, PTR)
34
35## Workflow
36
37### Step 1: Identify DNS Servers and Basic Records
38
39```bash
40# Find authoritative name servers
41dig NS example.com +short
42# ns1.example.com.
43# ns2.example.com.
44
45# Get SOA record for zone metadata
46dig SOA example.com +short
47# ns1.example.com. admin.example.com. 2024031501 3600 900 604800 86400
48
49# Enumerate all common record types
50dig example.com ANY +noall +answer
51
52# Get MX records (mail servers)
53dig MX example.com +short
54# 10 mail.example.com.
55# 20 mail-backup.example.com.
56
57# Get TXT records (SPF, DKIM, DMARC, verification)
58dig TXT example.com +short
59
60# Check for DMARC policy
61dig TXT _dmarc.example.com +short
62
63# Check for DKIM selectors
64dig TXT default._domainkey.example.com +short
65dig TXT selector1._domainkey.example.com +short
66dig TXT google._domainkey.example.com +short
67
68# Get SRV records for common services
69dig SRV _sip._tcp.example.com +short
70dig SRV _ldap._tcp.example.com +short
71dig SRV _kerberos._tcp.example.com +short
72```
73
74### Step 2: Attempt Zone Transfers
75
76```bash
77# Attempt AXFR zone transfer against each name server
78dig AXFR example.com @ns1.example.com
79dig AXFR example.com @ns2.example.com
80
81# Use host command for zone transfer
82host -t axfr example.com ns1.example.com
83
84# Use dnsrecon for automated zone transfer attempts
85dnsrecon -d example.com -t axfr
86
87# If zone transfer succeeds, save the output
88dig AXFR example.com @ns1.example.com > zone_transfer_results.txt
89
90# Test for IXFR (incremental zone transfer)
91dig IXFR=2024031500 example.com @ns1.example.com
92```
93
94### Step 3: Subdomain Enumeration via Brute Force
95
96```bash
97# Use dnsenum for comprehensive enumeration
98dnsenum --dnsserver ns1.example.com --enum -f /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -r example.com -o dnsenum_output.xml
99
100# Use dnsrecon with brute force
101dnsrecon -d example.com -t brt -D /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
102
103# Use gobuster for fast DNS brute forcing
104gobuster dns -d example.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-20000.txt -t 50 -o gobuster_dns.txt
105
106# Use subfinder for passive subdomain discovery
107subfinder -d example.com -all -o subfinder_results.txt
108
109# Use amass for comprehensive enumeration (passive + active)
110amass enum -d example.com -passive -o amass_passive.txt
111amass enum -d example.com -active -brute -o amass_active.txt
112
113# Combine and deduplicate results
114cat subfinder_results.txt amass_passive.txt amass_active.txt gobuster_dns.txt | sort -u > all_subdomains.txt
115```
116
117### Step 4: Reverse DNS and PTR Enumeration
118
119```bash
120# Reverse DNS lookup on discovered IP ranges
121dnsrecon -d example.com -t rvl -r 10.10.0.0/24
122
123# PTR record enumeration for IP range
124for ip in $(seq 1 254); do
125 result=$(dig -x 10.10.1.$ip +short 2>/dev/null)
126 if [ -n "$result" ]; then
127 echo "10.10.1.$ip -> $result"
128 fi
129done
130
131# Use Nmap for reverse DNS on a subnet
132nmap -sL 10.10.0.0/24 | grep "(" | awk '{print $5, $6}'
133
134# Check for DNS cache snooping (information about queried domains)
135dig @ns1.example.com www.competitor.com +norecurse
136```
137
138### Step 5: Analyze DNS Security Configuration
139
140```bash
141# Check DNSSEC validation
142dig example.com +dnssec +short
143dig DNSKEY example.com +short
144dig DS example.com +short
145
146# Test for DNS rebinding vulnerability
147# Check if the DNS server has a short TTL that could enable rebinding
148dig example.com +noall +answer | grep -i ttl
149
150# Check for open recursive resolver (misconfiguration)
151dig @ns1.example.com google.com +recurse
152# If it resolves, the server is an open resolver
153
154# Check for wildcard DNS records
155dig nonexistent-subdomain-xyz123.example.com +short
156# If it resolves, a wildcard record exists
157
158# Test DNS over HTTPS/TLS support
159# DoH test
160curl -s -H 'accept: application/dns-json' 'https://dns.google/resolve?name=example.com&type=A'
161
162# Verify SPF record for email security
163dig TXT example.com +short | grep "v=spf1"
164# Check for overly permissive SPF (+all, ?all)
165```
166
167### Step 6: Resolve and Map All Discovered Subdomains
168
169```bash
170# Resolve all discovered subdomains to IP addresses
171while read subdomain; do
172 ip=$(dig +short A "$subdomain" | head -1)
173 if [ -n "$ip" ]; then
174 echo "$subdomain,$ip"
175 fi
176done < all_subdomains.txt > resolved_subdomains.csv
177
178# Identify unique IP addresses and their locations
179cut -d',' -f2 resolved_subdomains.csv | sort -u > unique_ips.txt
180
181# Check for internal IP addresses leaked via DNS
182grep -E "^10\.|^172\.(1[6-9]|2[0-9]|3[01])\.|^192\.168\." resolved_subdomains.csv > internal_ip_leaks.txt
183
184# Use httpx to probe web services on discovered subdomains
185cat all_subdomains.txt | httpx -title -status-code -tech-detect -o httpx_results.txt
186
187# Screenshot web services for documentation
188cat all_subdomains.txt | httpx -screenshot -o screenshots/
189```
190
191## Key Concepts
192
193| Term | Definition |
194|------|------------|
195| **Zone Transfer (AXFR)** | DNS mechanism that replicates the complete zone file from a primary to secondary server; unauthorized transfers expose all records in the zone |
196| **Subdomain Enumeration** | Process of discovering valid subdomains through brute force, certificate transparency logs, search engines, and passive DNS databases |
197| **DNSSEC** | DNS Security Extensions that add cryptographic signatures to DNS responses, preventing cache poisoning and spoofing attacks |
198| **SPF/DKIM/DMARC** | Email authentication protocols defined in DNS TXT records that prevent email spoofing and domain impersonation |
199| **Wildcard DNS** | A DNS record using an asterisk (*) that matches any query for non-existent subdomains, potentially masking enumeration results |
200| **PTR Record** | Reverse DNS record that maps an IP address to a hostname, often revealing internal naming conventions and server roles |
201
202## Tools & Systems
203
204- **dig**: Standard DNS lookup utility with full support for all record types, DNSSEC validation, and zone transfer queries
205- **dnsrecon**: Comprehensive DNS enumeration tool supporting zone transfers, brute force, reverse lookup, cache snooping, and Google dork queries
206- **subfinder**: Fast passive subdomain discovery tool that queries certificate transparency logs, search engines, and DNS databases
207- **Amass (OWASP)**: Advanced attack surface mapping tool with both passive and active DNS enumeration, graph analysis, and data source integration
208- **gobuster**: Fast brute-force tool for DNS subdomain enumeration using configurable wordlists and concurrent threads
209
210## Common Scenarios
211
212### Scenario: External Reconnaissance for a Web Application Penetration Test
213
214**Context**: A security consultant is performing external reconnaissance for a web application penetration test. The client's primary domain is example.com, and the scope includes all subdomains and related infrastructure. The consultant has authorization to enumerate DNS records and probe discovered web services.
215
216**Approach**:
2171. Query NS, MX, TXT, and SOA records for example.com to map the DNS infrastructure
2182. Attempt zone transfers against both nameservers -- ns2 succeeds, revealing 347 DNS records including internal staging environments
2193. Run subfinder and amass in passive mode to discover 89 additional subdomains from certificate transparency logs
2204. Brute-force subdomains with a 20,000-word list using gobuster, discovering 12 more subdomains not found in passive sources
2215. Resolve all subdomains and identify 15 that resolve to internal RFC1918 addresses (information disclosure)
2226. Probe all web-accessible subdomains with httpx, discovering a staging environment (staging.example.com) with default credentials
2237. Report zone transfer vulnerability, internal IP disclosure, and exposed staging environment to the client
224
225**Pitfalls**:
226- Sending thousands of DNS queries per second and triggering rate limiting or DNS-based DDoS protection
227- Not checking for wildcard DNS records, resulting in false positive subdomain discoveries
228- Missing subdomains that use separate DNS providers or CDN-specific CNAME records
229- Overlooking TXT records that contain API keys, verification tokens, or internal comments
230
231## Output Format
232
233```
234## DNS Enumeration Report
235
236**Target Domain**: example.com
237**Authorized Nameservers**: ns1.example.com (203.0.113.10), ns2.example.com (203.0.113.11)
238
239### Zone Transfer Status
240| Nameserver | AXFR Result | Records Obtained |
241|------------|-------------|------------------|
242| ns1.example.com | REFUSED | 0 |
243| ns2.example.com | SUCCESS | 347 records |
244
245### Subdomain Discovery Summary
246| Method | Subdomains Found |
247|--------|-----------------|
248| Zone Transfer | 347 |
249| Passive (subfinder + amass) | 89 |
250| Active Brute Force | 12 |
251| **Total Unique** | **412** |
252
253### Critical Findings
2541. **Zone Transfer Allowed** (High): ns2.example.com allows AXFR from any source
2552. **Internal IP Disclosure** (Medium): 15 subdomains resolve to RFC1918 addresses
2563. **Exposed Staging Environment** (High): staging.example.com accessible with default credentials
2574. **Missing DMARC Policy** (Medium): No DMARC record found, enabling email spoofing
2585. **Weak SPF Record** (Low): SPF uses ~all (soft fail) instead of -all (hard fail)
259```