Sub topic 14
Threats to DNS: spoofing, cache poisoning and eavesdropping
This chapter assumes you know how a recursive resolver walks from the root to an authoritative server, and that you know what a TTL is. Classic DNS was designed without authentication or encryption. A query and its answer travel as plain UDP packets, and a resolver trusts the first answer that looks right. That design gives attackers three main openings.
Spoofing: forging an answer
A resolver sends a query and waits for a reply. It accepts a reply if the details match the query it sent. An off-path attacker (someone who cannot see the traffic) can try to send a forged reply first.
To be accepted, the forged reply must match:
- The source IP address and port of the server that was queried.
- The destination port, which is the random UDP source port the resolver used.
- The 16-bit transaction ID in the DNS header.
- The question section (the name and type that were asked).
The transaction ID alone gives only 65,536 possibilities. That is few enough to guess by flooding. Modern resolvers also randomize the source port, which multiplies the search space by tens of thousands. A resolver that uses a fixed source port is much easier to attack.
An on-path attacker, such as a malicious Wi-Fi hotspot or a compromised router, can see the query. That attacker does not need to guess anything. It can simply answer first.
Cache poisoning: making the lie last
Spoofing one reply to one client is bad. Spoofing a reply to a shared recursive resolver is worse, because the resolver caches what it accepts. Every client of that resolver then receives the forged data until the TTL expires.
An attacker also wants the forged data to stick. Two things help:
- A high TTL on the forged record keeps it cached for longer.
- Extra records in the reply can carry forged glue, such as a fake address for a name server. A resolver that accepts unrelated extra records can be poisoned more widely. Modern resolvers apply bailiwick checks. They only accept records that belong to the zone the server is responsible for.
The 2008 Kaminsky attack showed that an attacker could trigger many guesses by asking for random nonexistent names like r1.example.com. Each query created a new race. Source port randomization was the emergency fix.
Eavesdropping: reading the questions
Even if every answer is genuine, plain DNS exposes your queries. Anyone on the path can see which names you look up. That includes your ISP, a network operator and a Wi-Fi owner. The names reveal which sites and services you use, even when the later traffic is encrypted.
Plain DNS also allows tampering by on-path devices. Some networks rewrite answers to redirect users or to block names.
Related weaknesses
- Open resolvers answer queries from anyone. Attackers use them for amplification attacks, in which a small spoofed query produces a large reply sent to a victim.
- Hijacked registrar accounts or name server settings let an attacker change the real records. No protocol feature can detect this, because the data is then genuine from the DNS point of view.
What defends against what
| Threat | Mitigation | Covered in |
|---|---|---|
| Forged answers, cache poisoning | Random source port and transaction ID, bailiwick checks, DNSSEC | DNSSEC chapter |
| Eavesdropping on queries | DoT or DoH between client and resolver | Encrypted DNS chapter |
| Open resolver abuse | Restrict recursion to your own clients | Resolver configuration |
Exercise
A resolver always sends queries from UDP port 53. Why does this make cache poisoning easier, and what does randomizing the port change?
Show answer
The attacker then only has to guess the 16-bit transaction ID, about 65,536 values. With a random source port, the attacker must also guess the port, which multiplies the number of guesses by tens of thousands and makes a successful forgery before the real reply far less likely.
Exercise
Why is a poisoned cache entry more damaging than a single spoofed reply to one client?
Show answer
The resolver stores the forged data and serves it to every client until the TTL expires, so one successful forgery affects all users of that resolver.