DNS
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
TL;DR
DNS (Domain Name System). Resolves names to addresses. UDP and TCP 53. UDP serves normal queries. TCP serves zone transfers and any response over 512 bytes. A zone transfer (AXFR) is how a secondary server syncs the full zone from the primary, which is why a misconfigured one hands the whole zone to anyone who asks.
First checks: a zone transfer, the records, and subdomains. DNS enumeration needs a domain name.
On a box you often guess it (bank.htb) or read it from a certificate or another service, then set
$DOMAIN and add it to /etc/hosts.
Protocol background is in DNS Resolution.
Records
| Record | Returns |
|---|---|
| A / AAAA | IPv4 / IPv6 address. |
| NS | The zone’s nameservers. |
| MX | Mail servers. |
| TXT | Free text: SPF, DKIM, domain-verification tokens, sometimes secrets. |
| CNAME | Alias to another name. |
| SOA | Zone info and the admin email (the first . stands for @). |
| PTR | Reverse lookup, IP to name. |
| SRV | Service locations (_ldap, _kerberos). |
The records live in a zone file, which an AXFR returns in full:
$ORIGIN example.com. ; the zone root, written @ below$TTL 3600 ; default record cache time, in seconds
@ IN SOA ns1.example.com. admin.example.com. ( ; authority + contact [email protected] 2026101901 ; serial, bumped on every edit 7200 ; refresh, how often a secondary re-syncs 900 ; retry, wait after a failed refresh 1209600 ; expire, drop the zone if the primary stays unreachable 3600 ) ; negative-cache TTL, how long an NXDOMAIN is cached
@ IN NS ns1.example.com. ; authoritative nameserver@ IN NS ns2.example.com. ; second nameserver, for redundancy@ IN A 93.184.215.14 ; IPv4 of example.com@ IN AAAA 2606:2800:21f:cb07:6820:80da:af6b:8b2c ; IPv6 of example.com@ IN MX 10 mail.example.com. ; mail server, lowest number winsmail IN A 93.184.215.20 ; address the MX name resolves towww IN CNAME example.com. ; alias, www points to the apexftp IN A 93.184.215.21 ; a plain host record@ IN TXT "v=spf1 mx -all" ; SPF, only the MX may send mail for the domain@ IN TXT "google-site-verification=abc123" ; domain-ownership token_ldap._tcp IN SRV 0 100 389 dc01.example.com. ; service record, LDAP on dc01 port 389eu IN NS ns.eu-team.example.net. ; delegation, eu.example.com is its own zone
; reverse zone: IP back to name$ORIGIN 215.184.93.in-addr.arpa. ; the 93.184.215.0/24 reverse zone14 IN PTR example.com. ; 93.184.215.14 resolves back to this nameEnumeration
Workflow: query records with dig, try a zone transfer, then brute subdomains.
Query records.
dig any $DOMAIN @$TARGET # every record type, many servers refuse itdig ns $DOMAIN @$TARGET # nameserversdig mx $DOMAIN @$TARGET # mail serversdig txt $DOMAIN @$TARGET # text recordsdig soa $DOMAIN @$TARGET # admin contact and primary nameserverdig ch txt version.bind @$TARGET # BIND version, when the server exposes it@$TARGET sends the query to that server. ch txt version.bind asks for a CHAOS-class record.
Zone transfer (AXFR). The jackpot. A misconfigured server dumps every record:
dig axfr $DOMAIN @$TARGET # full zone transferfierce --domain $DOMAIN # find each nameserver and try AXFR on all of themThe reply holds internal hostnames, IPs, and subdomains.
All-in-one. dnsrecon and dnsenum run records, an AXFR attempt, and a brute in one command.
On a lab, point them at the box, since the system resolver does not know a .htb zone:
dnsrecon -d $DOMAIN -n $TARGET -t std # records plus an automatic zone-transfer attemptdnsenum --dnsserver $TARGET $DOMAIN # same idea, also sweeps reverse IP rangesdnsrecon is the maintained one, with NSEC zone walking and JSON output (--json). Convenient, but
the dedicated tools below find more.
Brute subdomains when AXFR fails. On a lab the box is the only resolver that knows the zone, so
point the brute at it. subfinder is passive OSINT and needs a public domain, so it is secondary.
gobuster dns --domain $DOMAIN --resolver $TARGET -w <wordlist> # preinstalled on Kaliecho $TARGET > resolvers.txt # puredns reads resolvers from a filepuredns bruteforce <wordlist> $DOMAIN -r resolvers.txt # faster, needs go install plus massdnssubfinder -d $DOMAIN -silent | dnsx -silent # public domain: passive names, resolvedgobuster dns ships with Kali and takes the resolver inline, the easy lab default. puredns is faster
for big runs. dnsx -r also takes a resolver inline (-r $TARGET).
Wordlists come from SecLists, under /usr/share/seclists/Discovery/DNS/ (sudo apt install seclists
if the directory is missing):
| Wordlist | Names | Use |
|---|---|---|
subdomains-top1million-5000.txt |
5k | fast first pass |
subdomains-top1million-20000.txt |
20k | deeper |
bitquark-subdomains-top100000.txt |
100k | thorough |
dns-Jhaddix.txt |
~2M | exhaustive, slow |
Triage the results. A brute gives three kinds of result, and the errors are leads. Triage all three:
- A clean resolve: a normal record, a host or vhost. Add it to
/etc/hostsand enumerate it. NXDOMAIN: nothing there. Ignore.- An error that is neither (
SERVFAIL, “server misbehaving”,REFUSED): something answers oddly, often a delegated subzone. Investigate it withdig.
A subdomain with its own NS record is a separate zone, and the parent transfer never held its records.
Transfer it against the box, since a subzone often allows AXFR where the parent refuses:
dig ns <name>.$DOMAIN @$TARGET # NS records here mean a delegated zonedig axfr <name>.$DOMAIN @$TARGET # transfer the subzoneInternal zones (internal., hr., dev.) hold records the parent zone hides.
nmap.
# recursion, nameserver ID, and zone transfersudo nmap -p53 -sV --script dns-recursion,dns-nsid,dns-zone-transfer --script-args dns-zone-transfer.domain=$DOMAIN -oA scans/dns $TARGETCommon misconfigurations
- Zone transfer (AXFR) allowed to any client.
- Internal records answered to external queries (split-horizon leak).
- Dynamic updates allowed without authentication.
- DNSSEC NSEC records let an attacker walk the whole zone.
- Open recursion, which enables cache poisoning and amplification.
- A dangling CNAME to an unclaimed third-party host, open to subdomain takeover.
Attack playbook
DNS is reconnaissance. Search it to map the environment.
- Zone transfer.
dig axfrfirst. One misconfig dumps the whole internal namespace. Transfer any internal zones it reveals too. They leak domain controllers, VPN, and workstation hosts.dig axfr internal.$DOMAIN @$TARGET # transfer an internal zone - Brute subdomains. When AXFR fails, brute and resolve. New names are vhosts, dev and staging
hosts, and internal services. Add each to
/etc/hosts, then enumerate the web and other services on it. - Harvest records. MX names the mail server. TXT leaks SPF entries, keys, and verification
tokens. SRV locates services (
_ldap,_kerberospoint to Active Directory). NS names the authoritative servers. - Zone walking. DNSSEC NSEC chains leak every name even without AXFR:
ldns-walk @$TARGET $DOMAIN # walk the NSEC chain
- Cache poisoning on the LAN. Situational, and needs a man-in-the-middle position. Bettercap
answers chosen domains with your IP.
The same steps run one at a time inside the bettercap prompt:# arp.spoof gets between the victim and the gateway, dns.spoof forges the repliessudo bettercap -iface eth0 -eval "set dns.spoof.domains $DOMAIN; set dns.spoof.address <you>; arp.spoof on; dns.spoof on"sudo bettercap -iface eth0# at the bettercap prompt:set dns.spoof.domains $DOMAIN,*.$DOMAINset dns.spoof.address <you>set arp.spoof.targets <victim>arp.spoof ondns.spoof on
dns.spoof.domainsis what to forge (the wildcard also catches subdomains),dns.spoof.addressis the IP handed back, andarp.spoof.targetsis the victim. Without targets,arp.spoofpoisons the whole subnet. Covered deeper in the MITM material.
Subdomain takeover
A subdomain takeover happens when a subdomain’s CNAME points to a third-party host that no longer
exists. The organization once pointed shop.example.com at a provider such as an S3 bucket, GitHub
Pages, or an Azure site, then deleted the resource but left the DNS record. The name still resolves to
the provider, but nothing there answers for it. Register that resource yourself and you serve content
on shop.example.com.
The impact is high because users and apps trust the name. You can phish under the real domain and read cookies scoped to the parent domain.
Find the danglers. Put the subdomains from enumeration in subs.txt, one host per line, then read
their CNAME targets:
dig cname shop.$DOMAIN @$TARGET # show where the alias pointsA target at a known provider, with a service error on the page, is the tell. For S3 it is
NoSuchBucket. Scan subs.txt for these fingerprints:
subzy run --targets subs.txt # flag takeover-able subdomainsnuclei -l subs.txt -t http/takeovers/ # same, nuclei templatesClaim it. Match the fingerprint against can-i-take-over-xyz, which lists each provider and whether it is exploitable. Register the same resource name at that provider, then host your content.
Practice boxes
| Box | Difficulty | DNS’s role |
|---|---|---|
| Cronos | Easy | Zone transfer reveals admin.cronos.htb, the foothold. |
| FriendZone | Easy | Zone transfer reveals subdomains leading to an LFI-to-RCE panel. |
| Bank | Easy | Zone transfer reveals the bank.htb vhost to enumerate. |
DNS is almost always recon, not the foothold itself. The win is the hostnames and subdomains it leaks, which point you at the real target.