Pentesting DNS — A Cleaner, Restructured Guide
Pentesting DNS — A Cleaner, Restructured Guide
Below is a rewritten and improved version of the original document. Technical content is preserved, but structure, flow, and clarity are tightened: sections are logically grouped, commands are consistently formatted, corrections to ambiguous statements are made explicit, and warnings are highlighted.
1. Overview
The Domain Name System (DNS) is the internet's directory: it translates human-readable names (google.com) into IP addresses so browsers can load resources.
- Default port:
53(TCP and UDP) - Typical service detection:
PORT STATE SERVICE REASON53/tcp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)5353/udp open zeroconf udp-response53/udp open domain Microsoft DNS 6.1.7601 (1DB15D39) (Windows Server 2008 R2 SP1)
2. DNS Server Types
| Type | Role |
|---|---|
| Root servers | Top of the public DNS hierarchy; return referrals for top-level domains. There are 13 named identifiers (A–M), but each is implemented by many anycast instances — not 13 physical machines. |
| Authoritative nameservers | Provide authoritative answers for their configured zones: answers, referrals for delegated child zones, or negative responses. A recursive resolver — not the authoritative server — walks the hierarchy when further lookup is needed. |
| Non-authoritative nameservers | Do not own zones; gather information by querying other servers. |
| Caching DNS server | Memorizes previous answers for a period dictated by the authoritative server, speeding up future requests. |
| Forwarding server | Simply relays queries to another server. |
| Resolver | Runs locally on computers/routers; performs name resolution but is not authoritative. |
3. Enumeration
3.1 Banner Grabbing
DNS has no conventional service banner, but some BIND servers answer a version.bind CHAOS TXT query. Administrators can disable or replace this value, so an empty or customized response is not conclusive.
dig version.bind CHAOS TXT @DNSfpdns # fingerprinting toolnmap --script dns-nsid <IP> # nmap equivalent
3.2 ANY Query
An ANY query asks the server to return whatever record set it is willing and able to provide. Modern authoritative servers may intentionally return a minimal response (RFC 8482) rather than every record.
dig any victim.com @<DNS_IP>
3.3 Zone Transfer (AXFR)
AXFR is the mechanism for transferring a complete zone from an authoritative server (RFC 5936).
dig axfr @<DNS_IP> # try without specifying domaindig axfr @<DNS_IP> <DOMAIN> # try guessing the domainfierce --domain <DOMAIN> --dns-servers <DNS_IP># fierce tries every authoritative NS; if AXFR fails, it launches a dictionary attack
3.4 Record Queries with dig
dig ANY @<DNS_IP> <DOMAIN> # any informationdig A @<DNS_IP> <DOMAIN> # regular A recorddig AAAA @<DNS_IP> <DOMAIN> # IPv6dig TXT @<DNS_IP> <DOMAIN> # TXT / informationdig MX @<DNS_IP> <DOMAIN> # maildig NS @<DNS_IP> <DOMAIN> # nameservers for the namedig -x 192.168.0.2 @<DNS_IP> # reverse lookupdig -x 2a00:1450:400c:c06::93 @<DNS_IP> # reverse IPv6 lookup# Add [-p PORT] for non-standard ports, or -6 to use the IPv6 address of the DNS server
3.5 Automation
# Simple loop over a wordlistfor sub in $(cat <WORDLIST>); dodig $sub.<DOMAIN> @<DNS_IP> | grep -v ';\|SOA' | sed -r '/^\s*$/d' | grep $sub | tee -a subdomains.txtdone# dnsenumdnsenum --dnsserver <DNS_IP> --enum -p 0 -s 0 -o subdomains.txt -f <WORDLIST> <DOMAIN>
3.6 nslookup Interactive Mode
nslookup> SERVER <IP_DNS> # select DNS server> 127.0.0.1 # reverse lookup of 127.0.0.1> <IP_MACHINE> # reverse lookup of a machine
3.7 Metasploit / Nmap Modules
# Metasploitauxiliary/gather/enum_dns # enumeration actionsauxiliary/scanner/dns/dns_amp # DNS amplification check# Nmapnmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" <IP>
4. Brute-Force Techniques
4.1 Reverse DNS Brute Force
dnsrecon -r 127.0.0.0/24 -n <IP_DNS>dnsrecon -r 127.0.1.0/24 -n <IP_DNS>dnsrecon -r <IP_DNS>/24 -n <IP_DNS>dnsrecon -d active.htb -a -n <IP_DNS> # zone transfer
Tip: If subdomains resolve to internal IPs, run reverse-DNS brute force against the domain's nameservers for the relevant address range.
Additional tooling:
reverse-scan(github.com/amine7536/reverse-scan)- BGP/PTR lookups:
https://bgp.he.net/net/205.166.76.0/24#_dns(also useful for BGP recon)
4.2 Subdomain Brute Force
dnsenum --dnsserver <IP_DNS> --enum -p 0 -s 0 -o subdomains.txt -f subdomains-1000.txt <DOMAIN>dnsrecon -D subdomains-1000.txt -d <DOMAIN> -n <IP_DNS>dnscan -d <domain> -r -w subdomains-1000.txt # recursive brute force
4.3 Active Directory SRV Records
dig -t _gc._tcp.lab.domain.comdig -t _ldap._tcp.lab.domain.comdig -t _kerberos._tcp.lab.domain.comdig -t _kpasswd._tcp.lab.domain.comnslookup -type=srv _kerberos._tcp.<CLIENT_DOMAIN>nslookup -type=srv _kerberos._tcp.domain.comnmap --script dns-srv-enum --script-args "dns-srv-enum.domain='domain.com'"
For authenticated enumeration or modification of AD-integrated zones, see the AD DNS records resource.
5. DNSSEC
5.1 NSEC Enumeration
# Query PayPal subdomains against ns3.isc-sns.infonmap -sSU -p53 --script dns-nsec-enum --script-args dns-nsec-enum.domains=paypal.com ns3.isc-sns.info
5.2 NSEC3 Zone Enumeration (when AXFR is denied)
Unlike NSEC's cleartext successor names, NSEC3 denial-of-existence proofs expose a chain of hashed owner names (RFC 5155). Query an authoritative nameserver directly with DNSSEC enabled and inspect the authority section of a negative response. An NSEC3 record is a lead for collecting hashes, not a plaintext hostname list.
Nmap's dns-nsec3-enum collects hashes, salt, and iteration count. n3map maps the chain and converts output for offline candidate-name testing with hashcat mode 8300.
Rate-limit queries on authorized targets: a large zone can take many queries to map.
# Confirm DNSSEC/NSEC3 behaviordig @<NS_IP> random-nonexistent.<DOMAIN> A +dnssec +norecurse# Collect hashesnmap -sU -p53 --script dns-nsec3-enum --script-args dns-nsec3-enum.domains=<DOMAIN> <NS_IP># Map the chain and convert for hashcatn3map -3p -o <DOMAIN>.zone --limit-rate 20/s <NS_IP> <DOMAIN>n3map-hashcatify <DOMAIN>.zone <DOMAIN>.hashcathashcat -m 8300 <DOMAIN>.hashcat <WORDLIST>
Important: Only names matched by your wordlist are recovered. NSEC3 Opt-Out can omit unsigned delegations from the chain, so even a completed walk is not proof that every delegated name was found.
6. IPv6
Brute force using AAAA requests to gather IPv6 addresses for subdomains:
dnsdict6 -s -t <domain>
Brute-force reverse DNS with IPv6 addresses:
dnsrevenum6 pri.authdns.ripe.net 2001:67c:2e8::/48
7. DNS Recursion DDoS
If recursion is enabled, an attacker can spoof the source on a UDP packet so the DNS server sends its response to the victim. ANY and DNSSEC record types are attractive because they historically produced larger responses.
Check recursion availability — look for the `ra` (recursion available) flag:
dig google.com A @<IP>
- Unavailable → no
raflag. - Available →
raflag present. This exposes the server to reflection/amplification abuse.
8. DNS Auditor Checks (Manual Reference)
A practical set of checks for verification and abuse-path analysis.
8.1 NS Delegation Integrity / Lame Delegation
Checks:
- Delegated NS hostnames resolve to IPs
- Delegated NSs answer authoritatively for the zone
- SOA serial consistency across authoritative NSs
dig example.com NS +shortfor ns in $(dig +short example.com NS); do dig @${ns%?} example.com SOA +short; done
Impact: intermittent or full DNS outages; stale records depending on which NS a resolver hits.
Attacker abuse: exploit lame/out-of-sync delegation to increase the reliability of cache-poisoning windows and to cause selective traffic disruption.
For the separate provider-claimability workflow, see domain and subdomain takeover.
8.2 HTTPS / SVCB Modern Records
dig example.com HTTPS +shortdig example.com SVCB +shortdig www.example.com HTTPS +shortdig www.example.com SVCB +short
Impact: mostly hardening/operational maturity gap (less protocol steering, less explicit service binding).
Attacker abuse: rarely direct exploitation, but can reduce defensive control over client connection behavior.
8.3 EDNS + TCP Fallback Resilience
dig example.com DNSKEY +dnssec +bufsize=1232dig example.com DNSKEY +dnssec +tcp
Impact: DNSSEC breakage; intermittent resolution failures behind specific networks/firewalls.
Attacker abuse: trigger degraded availability by forcing large responses where TCP/53 is blocked or broken.
8.4 DNSSEC Lifecycle (CDS/CDNSKEY + DS Consistency)
dig example.com DS +shortdig example.com CDS +shortdig example.com CDNSKEY +short
Impact: broken key rollover → validation failures / SERVFAIL for validating resolvers.
Attacker abuse: abuse mis-rolled states to create DoS conditions for DNSSEC-validating clients.
8.5 DNSSEC Negative Trust Validation (NXDOMAIN Proofs)
dig @8.8.8.8 _random-does-not-exist.example.com A +dnssecdig @8.8.8.8 _random-does-not-exist.example.com A +dnssec +multi
Impact: broken denial-of-existence behavior can indicate chain/signer inconsistencies.
Attacker abuse: increase the probability of resolver-side failure states during targeted DNSSEC disruption attempts.
8.6 Very Low TTL on Critical Records
dig example.com A +ttliddig example.com AAAA +ttliddig example.com MX +ttliddig example.com NS +ttlid
Impact: faster global propagation of accidental or malicious DNS changes.
Attacker abuse: if an attacker gains brief write access to DNS, low TTL accelerates malicious redirection rollout.
8.7 CAA Policy Quality + CT Correlation
dig example.com CAA +shortcurl -s "https://crt.sh/?q=%25.example.com&output=json" | head
Impact: overly broad or inconsistent issuance policy increases certificate abuse surface.
Attacker abuse: mis-scoped CAA can make unauthorized/abusive certificate issuance easier after CA/process compromise.
9. Mail to Nonexistent Account
Sending email to a nonexistent address in the target's domain may trigger a nondelivery notification whose headers disclose internal server names or IP addresses.
10. Post-Exploitation
When reviewing a BIND server, inspect:
allow-transfer— who can request zone transfersallow-recursion— who can send recursive queriesallow-query— who can send general queries
DNS-related files worth reviewing on compromised hosts:
host.conf/etc/resolv.conf/etc/bind/named.conf/etc/bind/named.conf.local/etc/bind/named.conf.options/etc/bind/named.conf.log/etc/bind/*
11. Automatic Commands
Protocol_Name: DNSPort_Number: 53Protocol_Description: Domain Name ServiceEntry_1:Name: NotesDescription: Notes for DNSNote: |# Commands to run every time an open DNS port is seendnsrecon -r 127.0.0.0/24 -n {IP} -d {Domain_Name}dnsrecon -r 127.0.1.0/24 -n {IP} -d {Domain_Name}dnsrecon -r {Network}{CIDR} -n {IP} -d {Domain_Name}dig axfr @{IP}dig axfr {Domain_Name} @{IP}nslookupSERVER {IP}127.0.0.1{IP}Domain_NameexitEntry_2:Name: Banner GrabDescription: Grab DNS BannerCommand: dig version.bind CHAOS TXT @DNSEntry_3:Name: Nmap Vuln ScanDescription: Scan for vulnerabilities with NmapCommand: nmap -n --script "(default and *dns*) or fcrdns or dns-srv-enum or dns-random-txid or dns-random-srcport" {IP}Entry_4:Name: Zone TransferDescription: Three attempts at forcing a zone transferCommand: dig axfr @{IP} && dig axfr @{IP} {Domain_Name} && fierce --dns-servers {IP} --domain {Domain_Name}Entry_5:Name: Active DirectoryDescription: Enumerate a DC via DNSCommand: dig -t _gc._{Domain_Name} && dig -t _ldap._{Domain_Name} && dig -t _kerberos._{Domain_Name} && dig -t _kpasswd._{Domain_Name} && nmap --script dns-srv-enum --script-args "dns-srv-enum.domain={Domain_Name}"Entry_6:Name: msfconsole-less enumerationDescription: DNS enumeration without the need to run msfconsoleNote: sourced from https://github.com/carlospolop/legionCommand: msfconsole -q -x 'use auxiliary/scanner/dns/dns_amp; set RHOSTS {IP}; set RPORT 53; run; exit' && msfconsole -q -x 'use auxiliary/gather/enum_dns; set RHOSTS {IP}; set RPORT 53; run; exit'
Corrections vs. original:
dix axfr→dig axfr;Eunuerate→Enumerate; added the seconddig axfrform to match Entry 1.
12. Source Review: ECS Response Context & Cache Admission (Unbound CVE-2025-5994)
Unbound's CVE-2025-5994 advisory describes a cache-admission boundary when EDNS Client Subnet (ECS) partitions outgoing queries.
Applicability:
- Affects Unbound 1.6.2 through 1.23.0
- Only when compiled with ECS support (
--enable-subnet) and configured to send ECS upstream - Historical fix: Unbound 1.23.1
Review guidance:
- Examine how outstanding-query state records the expected ECS context, and how reply validation binds that context before cache insertion.
- The documented fix rejects a reply lacking ECS when ECS was expected, then issues an explicit non-ECS subquery that can be aggregated with matching queries.
- Preserve the distinction between rejecting an unexpected reply and deliberately initiating a fallback query.
- Establish effective build/configuration and installed-version evidence before assigning applicability.
- Historical fixed versions are not current support recommendations.
13. References
- DNS (Domain Name System): definition, function, risks
- IANA — Root Servers
- RFC 5936 — DNS Zone Transfer Protocol (AXFR)
- RFC 8482 — Minimal Responses to DNS Queries That Have QTYPE=ANY
- RFC 5155 — DNSSEC Hashed Authenticated Denial of Existence
- Nmap
dns-nsec3-enumscript nsec3mapDNSSEC zone enumerator
Summary of Improvements Made
| Area | Change |
|---|---|
| Structure | Reorganized into 13 numbered sections; enumeration, brute-force, DNSSEC, auditor checks, and post-exploitation clearly separated. |
| Accuracy | Clarified root-server statement (13 identifiers, many anycast instances); ANY response caveat (RFC 8482); AXFR RFC 5936; NSEC3 RFC 5155 and Opt-Out limitation. |
| Consistency | Uniform dig command blocks; aligned dnsrecon/dnsenum/dnscan examples; consistent variable placeholders (<DNS_IP>, <DOMAIN>, <WORDLIST>). |
| Corrections | Fixed typos: dix axfr → dig axfr, Eunuerate → Enumerate; completed the fierce command spacing; added missing dig axfr form in Entry 4. |
| Warnings | Boxed cautions for NSEC3 rate-limiting and Opt-Out incompleteness, ECS applicability (build/config evidence required), and low-TTL/attack-surface caveats. |
| Auditor checks | Converted each check into a consistent Checks / How to check / Impact / Attacker abuse format with code blocks. |
| Readability | Added tables (server types, summary of improvements); grouped automatic commands into a clean YAML block. |
Author
Discussion · 0
No comments yet — start the discussion.
Sign in to join the discussion.