Sub topic 14
Threats to DNS: spoofing, cache poisoning and eavesdropping
Prerequisites and scope
This chapter assumes you have read the chapters on the resolution walkthrough and on caching and TTL. You should know the roles of the stub resolver, the recursive resolver and the authoritative server. You should also know that a recursive resolver stores answers until their TTL expires.
DNS was designed in the 1980s for a small, cooperative network. The original protocol sends queries and answers in plain text over UDP, with no built-in way to prove who sent an answer. Most DNS attacks follow from those two facts. This chapter covers what the attacks are, why they work and what limits them. It names the defenses and leaves the details to the next two chapters.
What an attacker wants
Attackers attack DNS because it sits in front of almost everything else. If a client believes a false answer, it connects to the wrong address, and the attacker can then do any of these:
- Show a fake login page to steal credentials.
- Relay traffic to the real site while reading or changing it (a man-in-the-middle position).
- Block access by returning no address or an unusable one.
- Receive mail meant for the victim, by forging MX records.
- Watch which names a user looks up, without altering anything.
These goals lead to three broad threat classes: forged answers (spoofing), forged answers that are stored (cache poisoning), and passive observation (eavesdropping). A fourth class, abuse of DNS servers to attack others, is covered at the end.
Where an attacker can sit
The threat depends on where the attacker is relative to the lookup path.
There are three positions:
- On-path attacker. Can see and modify packets. Examples are an operator of a shared Wi-Fi hotspot, a compromised router, or an ISP. This attacker can read every plain-text query and can reply faster than the real server.
- Off-path attacker. Cannot see your packets but can send packets with a forged source address. This attacker must guess the values the resolver expects in a reply.
- Compromised data source. The attacker changes the real records at their origin, for example by taking over a registrar account or a DNS hosting account. No protocol defense helps here, because the answer is "correct" as far as DNS is concerned.
Spoofing
DNS spoofing means making a client or resolver accept an answer that did not come from the legitimate server.
Why UDP makes spoofing possible
A typical query is one UDP packet. UDP has no handshake, and the source address can be forged. A resolver therefore accepts a reply if it matches the outstanding query on a few fields:
| Field | Size | Purpose |
|---|---|---|
| Source and destination IP addresses | 32 bits each (IPv4) | The reply must come from the server that was asked |
| Destination port | 16 bits | Must equal the source port of the query |
| DNS transaction ID | 16 bits | Copied from the query into the reply |
| Question section | Variable | Must repeat the name, type and class asked |
An on-path attacker sees all of these values and can copy them into a forged reply. An off-path attacker must guess them.
Local spoofing on the client side
On a network you do not control, the attacker often needs no cleverness. A rogue DHCP server can hand out the attacker's resolver address, so every lookup goes to a machine the attacker runs. A compromised home router can do the same. The user sees nothing unusual, because the browser asks for bank.example and gets a plausible answer.
You can check which resolver your machine uses and which address it returns for a name. The example below prints the resolver addresses the operating system has configured on Linux systems that use a plain /etc/resolv.conf.
from pathlib import Path
for line in Path("/etc/resolv.conf").read_text().splitlines():
if line.startswith("nameserver"):
print(line.split()[1])On systems that use systemd-resolved, this file may list only a local stub address such as 127.0.0.53. In that case run resolvectl status to see the real upstream resolvers.
Cache poisoning
Cache poisoning is spoofing with a lasting effect. If a recursive resolver accepts a forged answer and stores it, every client of that resolver receives the false data until the TTL expires. One successful forgery then reaches thousands of users. This is why poisoning draws more attention than spoofing of a single client.
The race
An off-path attacker poisons a resolver in roughly this way:
- The attacker asks the target resolver for a name that is not cached, such as
a1b2.example.com. The name is random, so the resolver must query the authoritative server. - The resolver sends a query to the authoritative server and waits.
- The attacker floods the resolver with forged replies, each with a different guess of the transaction ID, claiming to come from the authoritative server.
- If one forged reply arrives before the real one and matches the query, the resolver accepts it and stores it.
With a fixed source port, only the 16-bit transaction ID has to be guessed. That is 65,536 possibilities, which a flood can cover in a fraction of a second. Using a fresh random name each time gives the attacker many tries, because a failed attempt does not leave a poisoned entry that blocks the next one.
The Kaminsky attack
In 2008 Dan Kaminsky showed how to make such a race far more valuable. The forged reply contained no useful answer for the random name. Instead, it carried extra records in the authority and additional sections, saying that the name servers for the whole domain example.com were at the attacker's address. A resolver that cached those records would then send all later queries for that domain to the attacker, and the poisoned delegation would last for the NS record's TTL, which is often a day or more.
The fix, deployed across the internet that year, was to add randomness. Resolvers now randomize the UDP source port as well as the transaction ID. Together these give roughly 32 bits of unpredictability instead of 16, which makes a blind guess about 65,000 times harder. Resolvers also became stricter about which extra records they trust.
Bailiwick checking
Resolvers apply a rule called bailiwick checking. A server answering for example.com is only trusted for names inside example.com. If its reply includes records for bank.example or for an unrelated domain, the resolver discards them. This prevents a malicious or compromised server from using extra records to overwrite cached data for other domains.
Other defenses that help
- 0x20 encoding. The resolver randomly changes the letter case in the query name, such as
eXaMpLe.CoM, because authoritative servers copy the question exactly into the reply. A forger must guess the case pattern too, which adds a few more bits. - Rate limiting and response validation. Resolvers limit how many unmatched replies they tolerate and may switch to TCP when they see signs of an attack.
- Not caching unsolicited data. Modern resolvers only cache data that answers the question they asked.
- Restricting who can query. An open resolver that answers anyone is easier to probe and abuse. Restrict recursion to your own clients.
Eavesdropping
Eavesdropping is passive. The attacker only reads traffic and changes nothing. Plain DNS exposes the full query name and type to every device between the client and the resolver, and again between the resolver and the authoritative server.
What leaks:
- The names a user looks up, which reveal sites visited, services used and often the software on the device.
- Timing and volume, which show when a user is active.
- The client's IP address, which ties the lookups to a household or person.
This leak happens even when the connection that follows is protected by TLS. HTTPS hides the page content, but the DNS lookup before it was sent in the clear. Observers can often learn the destination from the server name that the client sends in the TLS handshake, as well, so encrypting DNS alone does not hide everything.
The resolver operator is also a party that sees every query. Eavesdropping defenses protect the path, not the resolver itself. You still have to trust whoever runs it.
You can observe the exposure on your own machine. This command captures DNS packets on a Linux or macOS host, and you will be able to read the names in the output. Replace eth0 with your interface name, and only capture on networks you are allowed to monitor.
sudo tcpdump -i eth0 -n udp port 53Then run dig example.com in another terminal. The captured line will include the query type and the name in plain text.
Related abuse: amplification and tunneling
Two further problems use DNS as a tool without forging any answer.
- Amplification (reflection) attacks. An attacker sends small queries to open resolvers with the victim's address forged as the source. The resolvers send much larger replies to the victim. A 60-byte query for a record with a large answer can yield a reply many times bigger, so a modest flow of queries becomes a flood. Closing open resolvers and applying response rate limiting reduces this.
- DNS tunneling. Malware encodes data into query names such as
c2VjcmV0.attacker.exampleand reads instructions from TXT replies. Because DNS is rarely blocked, it can carry data past a firewall. Defenders look for unusually long names, high query volume to one domain and large TXT responses.
Summary of threats and defenses
| Threat | Attacker position | What goes wrong | Main defense |
|---|---|---|---|
| Spoofed reply to a client | On-path | Client connects to a wrong address | DNSSEC validation, encrypted transport |
| Cache poisoning | Off-path (guessing) or on-path | Resolver stores false data for the TTL | Port and ID randomization, bailiwick checks, DNSSEC |
| Rogue resolver via DHCP or router | Local network | All lookups go to the attacker | Network trust, authenticated encrypted resolver |
| Eavesdropping | On-path | Query names and timing visible | DoT or DoH between client and resolver |
| Registrar or account takeover | Compromised data source | Real records are replaced | Account security, registry locks, monitoring |
| Amplification | Abuse of open resolvers | Victim flooded with replies | Restrict recursion, response rate limiting |
Notice that each defense covers only some rows. Randomization makes blind guessing hard but does nothing against an on-path attacker. DNSSEC proves that data is authentic but does not hide it. Encrypted DNS hides queries on one link but does not prove the data came from the real zone owner. The next chapters show how these tools combine.
Common mistakes
- Assuming HTTPS makes DNS safe. HTTPS protects the connection after the lookup. A forged answer can still send the client to an attacker's server, though a valid certificate check will normally fail there. The failure then depends on the user not clicking through a warning.
- Treating a short TTL as a defense. A short TTL limits how long a poisoned entry lasts, but the attack only needs to succeed once, and an attacker can repeat it.
- Thinking only the authoritative side matters. Many attacks target the recursive resolver or the client's local network, where the zone owner has no control.
Exercise
An attacker on the same coffee-shop Wi-Fi as you can read all your network traffic. Source port randomization and a random transaction ID are both enabled on your resolver. Does this stop the attacker from forging a DNS reply to your laptop? Explain, and name one kind of defense that would.
Show answer
No. Randomization only helps against an off-path attacker who has to guess the port and transaction ID. An on-path attacker on the same Wi-Fi sees the query, so it can copy both values into a forged reply and send it before the real one arrives. A defense that does not rely on secrecy of those values would stop it: DNSSEC validation, which checks a cryptographic signature on the data, or an encrypted and authenticated channel to the resolver (DoT or DoH), which prevents the attacker from reading or inserting packets.
Exercise
A resolver caches an NS record that points example.com to an attacker's server, with a TTL of 86400 seconds. Roughly how long can the poisoning last without any further action by the attacker, and why does a poisoned delegation matter more than one poisoned A record?
Show answer
Up to 86400 seconds, which is 24 hours, unless the entry is flushed from the cache sooner. A poisoned delegation matters more because the resolver will ask the attacker's server for every name under example.com, such as www, mail and any others. A poisoned A record affects only that one name.