Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 37 ยท Secure Protocols

DNS Security

Understand DNS attacks such as cache poisoning, spoofing and tunnelling, and defenses: DNSSEC, DoT and DoH, resolver hardening, RPZ filtering and spotting suspicious queries.

Almost every connection starts with a DNS question: "what is the address of this name?" DNS was designed in the 1980s for a small, friendly internet. By default its queries and answers are unauthenticated and unencrypted, and attackers have exploited that for decades. Defenders also use DNS as one of the best monitoring points, because nearly all malware needs to resolve a name before it can do anything.

This lesson covers the main DNS attacks, the protections (DNSSEC, encrypted DNS, resolver hardening, filtering) and a stand-in detector for DNS tunnelling. All domains are examples; none involve real targets.

How a lookup works

flowchart LR
    C["Client (stub resolver)"] --> R["Recursive resolver"]
    R --> Root["Root servers"]
    R --> TLD["TLD servers (.org)"]
    R --> A["Authoritative server (example.org)"]
    R -- "cached answer" --> C

The recursive resolver does the work and caches answers for the record's TTL.

The client asks its recursive resolver (your ISP, company or a public one). The resolver walks from the root to the TLD to the authoritative server, then caches the answer. Every step historically trusted the reply because it looked right.

Attacks

  • Spoofing and cache poisoning. An attacker tries to inject a forged answer into a resolver's cache so that bank.example points to an address they control. Classic UDP DNS has only a 16-bit transaction ID plus the port to authenticate a reply. Modern resolvers use source-port randomization and 0x20 encoding (random capitalization of the query name that the answer must echo) to make guessing hard, but without cryptographic proof the weakness remains.
  • Hijacking. Compromising the registrar account, the authoritative servers or the router's DNS settings changes where a name points. Strong account security (MFA, registry lock) matters here.
  • Amplification DDoS. A small spoofed query yields a huge response aimed at a victim. Defend by never running an open resolver and by rate limiting.
  • Tunnelling and exfiltration. Data is hidden inside DNS names (dGhpcw.attacker.example) so it passes firewalls that allow DNS. See the detector below.
  • Domain generation algorithms (DGA). Malware generates many pseudo-random domains to find its controller, making static block lists ineffective.
  • Typosquatting and look-alikes. examp1e.org for phishing.
  • Dangling records. An old CNAME pointing to a decommissioned cloud service can be claimed by someone else (subdomain takeover). Audit your zones.

DNSSEC: authenticity of answers

DNSSEC adds digital signatures to DNS data. The zone owner signs its records; resolvers that validate check the signatures against a chain of trust from the root down:

  • RRSIG is the signature over a set of records.
  • DNSKEY holds the public keys used to verify.
  • DS (in the parent zone) is a hash of the child's key, linking the chain.
  • NSEC/NSEC3 provide signed proof that a name does not exist.

If the signature does not validate, the validating resolver returns an error (SERVFAIL) instead of the forged data. DNSSEC protects integrity and authenticity, not privacy: queries are still readable. It also needs careful key management; an expired signature or botched key rollover makes your domain unreachable for validating resolvers.

Here is a read-only sketch of how you would check validation on a resolver you operate (output is illustrative):

TEXT
$ dig +dnssec example.org A
;; flags: qr rd ra ad;     <- "ad" = authenticated data: the resolver validated it
example.org.   3600 IN A     192.0.2.80
example.org.   3600 IN RRSIG A 13 2 3600 ... (signature)

Encrypted DNS: privacy

Plain DNS over UDP port 53 lets anyone on the path see every name you look up. Two protocols encrypt the client-to-resolver leg:

  • DoT (DNS over TLS), port 853. Easy for network teams to identify and manage.
  • DoH (DNS over HTTPS), port 443. Blends with web traffic, which protects users on hostile networks, but also lets applications bypass enterprise DNS filtering. Organizations should configure managed devices to use their DoH/DoT resolver and block unknown ones.

Neither proves the answer is authentic (DNSSEC does) and neither hides the destination IP address you then connect to.

Hardening your own resolvers and zones

  • Do not expose a recursive resolver to the internet; restrict it to your clients.
  • Keep resolver software patched; enable validation of DNSSEC.
  • Rate limit responses (response rate limiting) to blunt amplification.
  • Separate authoritative and recursive roles onto different servers.
  • Use split-horizon DNS so internal names are not published externally.
  • Secure the registrar: MFA, registry lock, restricted contacts, expiry monitoring.
  • Add CAA records to state which CAs may issue certificates for the domain (why this matters).
  • Review zones for dangling CNAMEs and stale records.

DNS filtering and RPZ

A resolver can refuse or redirect names on a deny list. Response Policy Zones (RPZ) let you apply threat-intelligence feeds directly in resolvers such as BIND or Unbound. A blocked lookup can return NXDOMAIN or point to a notice page. This stops many phishing and malware callbacks before any connection is made, and the logged blocks are excellent signals for your SIEM.

Detecting tunnelling and DGA domains

Two simple signals: long, high-entropy labels (encoded data looks random) and many unique names under one parent domain. The program measures both on made-up queries.

Python Entropy and length of DNS names

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The long random labels score high on entropy while ordinary words score lower; the attacker domain also has many unique subdomains. Production detectors add checks against legitimate high-entropy names (CDNs, security vendors) and baseline query volumes per client.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does DNSSEC provide?

    DNSSEC signs records so validating resolvers can detect forged data; it does not hide queries.
  2. 2. Which pair protects the privacy of the client-to-resolver leg?

    DNS over TLS and DNS over HTTPS encrypt queries between the client and its resolver.
  3. 3. Why is an open recursive resolver a risk?

    Attackers send spoofed queries so the resolver floods a victim with large responses.
  4. 4. What is a typical sign of DNS tunnelling?

    Encoded data creates long random-looking labels, and each message becomes a unique name.

Summary

  • DNS is unauthenticated and unencrypted by default; attacks include cache poisoning, hijacking, amplification, tunnelling, DGA and subdomain takeover.
  • DNSSEC adds signatures (authenticity); DoT/DoH add encryption (privacy). They solve different problems.
  • Harden resolvers and zones: no open recursion, patching, rate limiting, split-horizon, registrar security, CAA, zone audits.
  • RPZ and DNS filtering block known-bad names; DNS logs are valuable detection data.
  • Entropy, label length and unique-name counts help detect tunnelling and DGA activity.

Next: Email Security: SPF, DKIM and DMARC