Skip to content

DNS Spoofing and Cache Poisoning

DNS spoofing makes a victim's resolver or device accept a forged DNS answer, so a real name such as your bank's domain leads to an attacker's server. The attacker can then show a look-alike site, read traffic, or block updates.

DraftLast reviewed Oct 11, 20262 scriptsEdit this page on GitHub

This page is a draft: its scripts were tested in a lab, but its references still need an independent review.

On this page

After this lesson you can

  • Explain what DNS Spoofing and Cache Poisoning is in your own words.
  • Describe how the attack or technique works.
  • Walk through a real-world example from start to finish.
  • Recognise it using the detection techniques in this lesson.
  • Apply the prevention methods described here.
  • Read and run the 2 Python scripts in a lab you control.
  • Relate the topic to T1557 in the standards.

Last reviewed: 2026-10-11 | Status: Draft (new topic; scripts tested against local lab targets, references not yet independently re-verified)

Standards mapping

FrameworkReference
OWASP Top 10:2025not applicable
MITRE ATT&CK (v19)Related: Credential Access / T1557 Adversary-in-the-Middle
CWEnot applicable
CAPECCAPEC-142 DNS Cache Poisoning
Example CVECVE-2008-1447 (Kaminsky DNS cache poisoning)

What it is

DNS spoofing makes a victim's resolver or device accept a forged DNS answer, so a real name such as your bank's domain leads to an attacker's server. The attacker can then show a look-alike site, read traffic, or block updates.

How it works

Plain DNS over UDP has no proof of who sent an answer. A forger must match the query's 16-bit transaction ID and source port and answer before the real server. If the forged reply arrives first, a caching resolver stores it and serves it to every client until the record's TTL expires. On a local network an attacker can instead sit in the path (see ARP spoofing) and answer queries directly.

Real-world example

In 2008 Dan Kaminsky showed that cache poisoning could be done quickly and reliably against resolvers that used predictable source ports (CVE-2008-1447). Vendors responded by randomising source ports. Source: CERT/CC VU#800113.

Detection

  • Two answers for one query with different addresses: CONFLICTING_ANSWERS (the forged-versus-genuine race)
  • An answer from a server the query was not sent to: WRONG_SOURCE
  • An answer with no matching query: UNSOLICITED_RESPONSE
  • A public name resolving to a private or loopback address: PRIVATE_ANSWER (spoofing or DNS rebinding)

Prevention

In order of strength. The first items fix the cause; the rest reduce risk.

  1. Enable DNSSEC validation on your resolver and sign your own zones (prevention/dnssec_check.py shows whether it is working)
  2. Use encrypted DNS (DNS-over-TLS or DNS-over-HTTPS) to a resolver you trust
  3. Keep resolver software patched; make sure it randomises source ports and transaction IDs
  4. Restrict recursion to your own clients; do not run an open resolver
  5. Defend the local network against ARP spoofing (dynamic ARP inspection, static entries for gateways)

Scripts in this topic

Common mistakes

  • Believing HTTPS makes DNS spoofing harmless: it limits damage only if users never click through certificate warnings
  • Checking only the first answer: forged replies race the real one
  • Running a validating resolver but never checking that it actually sets the AD flag

Test it safely

Only test systems you own or have written permission to test. Practice against a deliberately vulnerable app such as OWASP Juice Shop or DVWA, or a local test server you write yourself. The detector can be tested offline with a .pcap file: python detection/dns_spoof_detector.py -r capture.pcap.

Practical Python labs

Open a script to read its source and copy the run commands. Run security tools only on systems you own or have written permission to test.

Check what you have covered

These questions are generated from this lesson's category, standards mapping and scripts. They test where things live in the guide, not how well you understand the concepts. Nothing is saved or tracked.

1.Which category is "DNS Spoofing and Cache Poisoning" part of?
2.Which MITRE ATT&CK identifier is listed in the standards mapping for "DNS Spoofing and Cache Poisoning"?
3.Which of these scripts belongs to the "DNS Spoofing and Cache Poisoning" lesson?
4.Is dns_spoof_detector.py a detection script or a prevention script?

References