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