DNS
DNS turns names into addresses. Almost every connection starts with it, which makes it a rich detection source and a favorite channel for attackers.
Overview
The Domain Name System (DNS) translates names that people use, such as portal.example.com, into the IP addresses that networks use. It also answers other questions: which servers receive mail for a domain, which domain controllers serve an Active Directory domain, and which text records prove who owns a domain.
DNS is a distributed, hierarchical database. No single server knows every name. Root servers know where the top-level domains such as .com are served, those servers know which servers are authoritative for example.com, and those servers hold the actual records. A recursive resolver walks this chain on behalf of clients and caches the results.
Classic DNS runs on port 53 over UDP, with TCP for large answers and zone transfers. Newer forms encrypt the traffic: DNS over TLS on port 853 and DNS over HTTPS on port 443.
Defenders care for two opposite reasons. DNS is one of the best detection sources there is: almost every connection a machine makes starts with a lookup, so DNS logs show which hosts talk to which destinations, often before any other traffic. And DNS is one of the most abused protocols: attackers use it for command and control, for data theft, to hide infrastructure that changes by the hour, to redirect whole domains, and to flood victims with traffic. Inside Windows networks, DNS is also how clients find domain controllers, so attacks on internal DNS feed directly into attacks on Kerberos and NTLM.
History and evolution
| Year | Milestone | Why it matters for security |
|---|---|---|
| 1970s to 1983 | ARPANET hosts are listed in one HOSTS.TXT file maintained centrally | The model DNS replaced. The hosts file still exists on every machine and still overrides DNS |
| 1983 | Paul Mockapetris publishes the first DNS specifications (RFC 882 and RFC 883) | DNS is designed for a small, trusted network, without authentication |
| 1987 | RFC 1034 and RFC 1035 | The core specifications still in use today |
| 1999 | EDNS0 (RFC 2671, now RFC 6891) | Allows larger UDP responses and option fields. Larger responses later make amplification attacks more powerful |
| 2005 | DNSSEC (RFC 4033 to 4035) | Signed records that resolvers can verify |
| 2008 | Dan Kaminsky's cache poisoning attack (CVE-2008-1447) | Forced resolvers worldwide to randomize source ports |
| 2010 | The DNS root zone is signed with DNSSEC | A chain of trust from the root becomes possible |
| 2016 | DNS over TLS (RFC 7858) | Encrypts traffic between client and resolver |
| 2018 | DNS over HTTPS (RFC 8484) | Hides DNS inside ordinary HTTPS. Browsers adopt it, which bypasses enterprise resolvers unless managed |
| 2022 | DNS over QUIC (RFC 9250) | Encrypted DNS over UDP port 853 |
Where DNS is used in enterprise networks
- Every client lookup goes to internal resolvers, which in Windows networks are usually the domain controllers running Active Directory-integrated DNS.
- Internal resolvers forward unknown names to an upstream service: the internet provider, a public resolver, or a protective DNS service that blocks known-bad domains.
- Active Directory depends on DNS to work at all. Clients find domain controllers through SRV records, and computers register their own names through secure dynamic updates.
- Public DNS for the company's own domains is hosted by a registrar, a DNS provider, or a CDN. It holds the website, mail (MX), and email authentication records (SPF, DKIM, DMARC).
- Cloud services, certificate issuance (CAA records and DNS-based validation), and content delivery networks all rely on DNS answers.
A single workstation makes thousands of DNS lookups a day. That volume is noisy, but it is also stable for each machine, which is what makes anomalies stand out.
Architecture and components
| Component | What it is | What it holds |
|---|---|---|
| Stub resolver | The DNS client in the operating system | A small local cache and the address of the configured resolver |
hosts file | Local name list checked before DNS | Static mappings. Malware sometimes edits it to redirect or block sites |
| Recursive resolver | The server that answers clients by asking other servers | A cache of answers, each kept for its time to live (TTL) |
| Forwarder | A resolver that passes queries to another resolver instead of resolving them itself | Common in enterprises: internal servers forward to an upstream service |
| Root servers | The top of the hierarchy. There are 13 named root server identities, each served from many locations | Referrals to top-level domain servers |
| TLD servers | Servers for top-level domains such as .com, .ae, or .org | Referrals to each domain's authoritative servers |
| Authoritative server | The server that holds a domain's records | The zone: the definitive records for that domain |
| Zone | A portion of the namespace managed as one unit | Records, a start of authority (SOA) record, and name server (NS) records |
| Primary and secondary servers | Copies of a zone. Secondaries copy from the primary with zone transfers | The same zone data |
| Active Directory-integrated zone | A Windows zone stored in the directory and replicated with it | Records, plus permissions on each record |
| DNSSEC keys | A key-signing key (KSK) and a zone-signing key (ZSK) per signed zone | Signatures (RRSIG) on records, and a delegation signer (DS) record in the parent zone |
How DNS resolution works step by step
- An application asks the operating system for
portal.example.com. The stub resolver checks thehostsfile and its own cache. - On a miss, the stub sends a query to its configured resolver with the Recursion Desired (RD) flag set.
- The resolver checks its cache. On a miss, it asks a root server, which replies with a referral to the
.comservers. - The resolver asks a
.comserver, which replies with a referral to the authoritative servers forexample.com. - The resolver asks an
example.comauthoritative server, which returns the answer with the Authoritative Answer (AA) flag set. - The resolver caches the answer for its TTL and returns it to the client, which then connects to the address.
In practice the resolver almost never starts at the root: the .com referral and popular answers are already in its cache.
sequenceDiagram participant C as Client stub resolver participant R as Recursive resolver participant Root as Root server participant TLD as .com server participant A as example.com authoritative C->>R: Query portal.example.com A, recursion desired R->>Root: Query portal.example.com A Root->>R: Referral to .com servers R->>TLD: Query portal.example.com A TLD->>R: Referral to example.com servers R->>A: Query portal.example.com A A->>R: Authoritative answer with TTL R->>C: Answer, cached for the TTL
DNS in Active Directory
Active Directory cannot work without DNS, and several well-known attack paths start here.
How clients find domain controllers: a domain-joined machine queries SRV records such as _ldap._tcp.dc._msdcs.corp.local and _kerberos._tcp.corp.local. It receives a list of domain controllers, then sends a short LDAP query over UDP 389 to pick one in its own site. Domain controllers register these records themselves through the Netlogon service.
How records are stored: Active Directory-integrated zones live in the directory, in the DomainDnsZones and ForestDnsZones partitions, and replicate with it. Each record is a directory object with its own permissions. Secure dynamic updates mean only the computer that registered a name can change it.
Where it goes wrong:
- Record creation by any user. By default, Authenticated Users hold the "Create all child objects" permission on Active Directory-integrated zones, so any domain account can create a record name that does not exist yet, and becomes its owner. An attacker can add a wildcard record, or a name that clients look up but that does not exist, and point it at their own machine. Clients that resolve it then send authentication to the attacker, which feeds directly into NTLM relay.
- WPAD. Browsers and Windows look up
wpadto find a proxy configuration. The Windows DNS server blockswpadandisatapby default with its global query block list, but that protection is often removed during troubleshooting. - DnsAdmins. Members of the DnsAdmins group can configure the DNS server service to load a DLL, and the service runs as SYSTEM on domain controllers. DnsAdmins membership is effectively control of the domain and should be treated as such.
Packet-level anatomy
Transport and ports
| Port | Protocol | Use |
|---|---|---|
| 53/UDP | Classic DNS | Most queries and responses |
| 53/TCP | Classic DNS | Truncated responses, zone transfers, and any query (RFC 7766 requires TCP support) |
| 853/TCP | DNS over TLS (DoT) | Encrypted client to resolver |
| 443/TCP | DNS over HTTPS (DoH) | Encrypted DNS inside ordinary HTTPS |
| 853/UDP | DNS over QUIC (DoQ) | Encrypted DNS over QUIC |
| 5353/UDP | Multicast DNS (mDNS) | Local network name discovery |
| 5355/UDP | LLMNR | Windows local name resolution fallback, a common poisoning target |
When a UDP response does not fit, the server sets the Truncated (TC) flag and the client retries over TCP. EDNS0 lets the client advertise a larger UDP buffer. 1232 bytes is the widely recommended size, because it avoids IP fragmentation, which some poisoning attacks exploit.
Header
Every DNS message starts with a 12-byte header.
| Field | Size | Purpose | Security note |
|---|---|---|---|
| ID | 16 bits | Matches responses to queries | Must be random. With source port randomization it is the main defense against spoofed answers |
| QR | 1 bit | 0 for a query, 1 for a response | None |
| Opcode | 4 bits | 0 standard query, 4 NOTIFY, 5 UPDATE | UPDATE messages from unexpected sources mean someone is trying to change records |
| AA | 1 bit | Authoritative Answer | Set by the server that owns the zone |
| TC | 1 bit | Truncated | Triggers a retry over TCP |
| RD | 1 bit | Recursion Desired | Set by clients |
| RA | 1 bit | Recursion Available | An authoritative server that answers with RA set to external clients is an open resolver |
| Z | 1 bit | Reserved, must be zero | Non-zero values point to unusual tools |
| AD | 1 bit | Authentic Data: the resolver validated the answer with DNSSEC | Only meaningful if the path to the resolver is trusted |
| CD | 1 bit | Checking Disabled: the client asks the resolver not to validate | None |
| RCODE | 4 bits | Response code | See the table below |
| QDCOUNT, ANCOUNT, NSCOUNT, ARCOUNT | 16 bits each | Number of questions, answers, authority records, and additional records | Responses with very large counts can indicate amplification or tunneling |
Question and resource records
The question holds a name (QNAME), a type (QTYPE), and a class (QCLASS, almost always 1 for Internet).
Names are encoded as labels, each prefixed with its length: portal.example.com becomes 06 portal 07 example 03 com 00. Each label can be at most 63 bytes, and a full name at most 255 bytes. Tunneling tools fill these limits with encoded data.
Every answer, authority, and additional record has the same format:
| Field | Size | Purpose |
|---|---|---|
| NAME | Variable | The owner name. Often a 2-byte compression pointer: the top two bits set (0xC0) plus a 14-bit offset to a name earlier in the message |
| TYPE | 16 bits | Record type |
| CLASS | 16 bits | 1 for Internet |
| TTL | 32 bits | Seconds the record may be cached |
| RDLENGTH | 16 bits | Length of the data |
| RDATA | Variable | The record data |
Record types
| Type | Value | Holds | Security note |
|---|---|---|---|
| A | 1 | IPv4 address | The most common query |
| NS | 2 | Name server for a zone | Changes to NS records at the registrar are how domains get hijacked |
| CNAME | 5 | Alias to another name | A CNAME pointing to a deleted cloud resource enables subdomain takeover |
| SOA | 6 | Zone authority and timers | None |
| NULL | 10 | Arbitrary data | Rare in normal traffic. Used by tunneling tools |
| PTR | 12 | Reverse lookup, address to name | Reverse sweeps reveal internal naming |
| MX | 15 | Mail server | Changes redirect a company's email |
| TXT | 16 | Free text | SPF, DKIM, DMARC, and domain verification. Also the favorite carrier for tunneling and command and control |
| AAAA | 28 | IPv6 address | None |
| SRV | 33 | Service location | Active Directory domain controller discovery |
| OPT | 41 | EDNS0 pseudo-record | Carries buffer size and options |
| DS, RRSIG, NSEC, DNSKEY, NSEC3 | 43, 46, 47, 48, 50 | DNSSEC data | Large responses, so useful for amplification |
| SVCB, HTTPS | 64, 65 | Service binding, including encrypted ClientHello configuration | None |
| IXFR, AXFR | 251, 252 | Incremental and full zone transfers | A full zone transfer to an unknown host hands over a map of the network |
| ANY | 255 | All records for a name | Historically abused for amplification. Many servers now return a minimal answer (RFC 8482) |
| CAA | 257 | Which certificate authorities may issue certificates for the domain | Limits certificate misissuance |
Response codes
| RCODE | Name | Meaning | Detection value |
|---|---|---|---|
| 0 | NOERROR | Success | Normal |
| 1 | FORMERR | The server could not parse the query | Bursts can point to malformed tunneling traffic or fuzzing |
| 2 | SERVFAIL | The server failed to answer | Spikes can mean DNSSEC validation failures, upstream outages, or attacks on the resolver |
| 3 | NXDOMAIN | The name does not exist | A host producing many NXDOMAIN answers is a classic sign of malware cycling through generated domains |
| 4 | NOTIMP | Not implemented | Rare |
| 5 | REFUSED | The server will not answer | External REFUSED answers show someone testing your servers for open recursion |
EDNS0 options
The OPT record carries the client's UDP buffer size, the DNSSEC OK (DO) bit, and options such as EDNS Client Subnet (option 8, which passes part of the client's address to authoritative servers), DNS Cookies (option 10, which helps resist spoofing), and Padding (option 12, which hides message sizes in encrypted DNS).
Example decoded response
An illustrative response as Wireshark shows it:
Domain Name System (response)
Transaction ID: 0x5c3a
Flags: 0x8180 Standard query response, No error
1... .... .... .... = Response: Message is a response
.000 0... .... .... = Opcode: Standard query (0)
.... .0.. .... .... = Authoritative: Server is not an authority for domain
.... ..0. .... .... = Truncated: Message is not truncated
.... ...1 .... .... = Recursion desired: Do query recursively
.... .... 1... .... = Recursion available: Server can do recursive queries
.... .... ..0. .... = Answer authenticated: Answer was not authenticated by the server
.... .... .... 0000 = Reply code: No error (0)
Questions: 1
Answer RRs: 1
Authority RRs: 0
Additional RRs: 1
Queries
portal.example.com: type A, class IN
Answers
portal.example.com: type A, class IN, addr 203.0.113.25
Time to live: 300
Additional records
<Root>: type OPT
UDP payload size: 1232
Zeek writes every query and response pair to dns.log, with fields including query, qtype_name, rcode_name, AA, TC, RD, RA, answers, and TTLs. An illustrative line for the same lookup:
query=portal.example.com qtype_name=A rcode_name=NOERROR AA=F TC=F RD=T RA=T answers=203.0.113.25 TTLs=300.0
Configuration in practice
Resolvers and internal DNS servers
| Setting | Default | Recommended | Why |
|---|---|---|---|
| Who may query the resolver | Varies by product | Internal networks only | An open resolver gets used for amplification attacks against others |
| Recursion on authoritative-only servers | Often on | Off | Public authoritative servers should only answer for their own zones |
| Source port randomization (Windows: socket pool) | On. Windows uses a pool of 2,500 ports by default | On, with a larger pool on busy resolvers | Makes spoofed answers much harder to land |
| DNSSEC validation | Varies by product | On, after testing | Rejects forged answers for signed domains |
| Global query block list (Windows) | Blocks wpad and isatap | Keep it | Stops WPAD and ISATAP spoofing through DNS |
| Query logging (Windows: DNS Server Analytical log) | Off | On, sent to your SIEM | Without it, there is no record of what each host looked up |
| Protective DNS or response policy zones | Not configured | Block known-bad and newly registered domains | Stops many malware and phishing lookups at the first step |
Zones and records
| Setting | Default | Recommended | Why |
|---|---|---|---|
| Zone transfers | Varies by zone type | Only to named secondary servers | Prevents anyone from downloading the full zone |
| Dynamic updates on Active Directory-integrated zones | Secure only | Secure only | Only authenticated computers can register names |
| Record creation by Authenticated Users in Active Directory-integrated zones | Allowed | Removed, or pre-create a harmless wildcard record | Stops attackers from adding records that capture authentication |
| DnsAdmins group membership | Usually small, rarely reviewed | Empty or Tier 0 administrators only | Membership leads to code execution on domain controllers |
| Response rate limiting on public authoritative servers | Off | On | Limits your servers' usefulness in reflection attacks |
The perimeter and the registrar
| Setting | Recommended | Why |
|---|---|---|
| Outbound 53/UDP, 53/TCP, and 853 | Allowed only from internal resolvers | Forces all DNS through servers you log and control |
| DNS over HTTPS in browsers and Windows | Managed by policy: off, or pointed at your own resolver | Unmanaged DoH bypasses your logs and blocking |
| Registrar and DNS provider accounts | Multi-factor authentication, registry lock where offered | Domain hijacking usually starts with a stolen registrar password |
| CAA records | Present, listing only the certificate authorities you use | Limits who can issue certificates for your domain |
| SPF, DKIM, and DMARC | Published, with DMARC set to reject | Stops others from sending email as your domain |
Security model and common misconfigurations
Classic DNS has no authentication and no encryption. A resolver accepts the first answer that matches its question, its transaction ID, and its source port. Everyone on the path can read every lookup.
The newer layers each fix part of this:
- DNSSEC proves that records came from the zone owner and were not changed. It does not hide anything, and it only protects zones that are signed.
- DNS over TLS, HTTPS, and QUIC encrypt the path between the client and its resolver. The resolver still sees every query, and the resolver's own upstream lookups may still be plain DNS.
- No layer protects against a compromised registrar account, because the attacker then publishes legitimate-looking records for your domain.
The misconfigurations behind most DNS incidents:
- Clients allowed to send DNS straight to the internet, bypassing internal resolvers
- Browsers using public DoH services, so internal logs and blocking see nothing
- No DNS query logging, or logs kept only a few days
- Open recursion on internet-facing servers
- Zone transfers allowed to any host
- Default record-creation permissions in Active Directory-integrated zones
- Stale DnsAdmins membership
- Registrar accounts without multi-factor authentication
- CNAME records left pointing to cloud resources that no longer exist
Attacks against DNS
Cache poisoning and spoofed answers
How it works: the attacker tries to get a resolver to accept a forged answer before the real one arrives, so the resolver caches a wrong address and hands it to every client. Dan Kaminsky showed in 2008 that by asking for many random names under the target domain, an attacker gets unlimited tries and can inject a forged referral for the whole domain (CVE-2008-1447). Later research, such as the SAD DNS attack in 2020, used side channels to guess the source port.
Prerequisites: the ability to send spoofed packets to the resolver, and a resolver with weak randomization or no DNSSEC validation for the target zone.
ATT&CK: T1557 (Adversary-in-the-Middle).
On the wire and in logs: bursts of queries for random names under one domain, many responses arriving for the same query, and answers for a well-known domain suddenly changing to an unfamiliar address.
Domain and DNS hijacking
How it works: instead of fooling resolvers, the attacker changes the real records. They steal the credentials for a registrar or DNS provider account and change the NS or A records, often just long enough to obtain valid TLS certificates and capture email or VPN logins. In 2019, CISA issued Emergency Directive 19-01 after a campaign that hijacked government domains this way. Home and small office routers with changed DNS settings are a smaller-scale version of the same idea.
ATT&CK: T1584.002 (Compromise Infrastructure: DNS Server).
On the wire and in logs: changes in your own public records that nobody requested. Certificates issued for your domains that you did not request, visible in certificate transparency logs. Registrar login alerts from unfamiliar locations.
Tunneling and command and control
How it works: malware encodes data into query names and receives commands in TXT, NULL, or CNAME answers from a domain the attacker controls. Because almost every network lets DNS through, the channel survives where other traffic is blocked. See the full DNS Tunneling entry.
ATT&CK: T1071.004 (Application Layer Protocol: DNS), T1572 (Protocol Tunneling), and T1048 (Exfiltration Over Alternative Protocol).
On the wire and in logs: many unique, long, random-looking subdomains under one registered domain from one host, unusual record types such as TXT and NULL from workstations, and regular timing.
Domain generation algorithms
How it works: malware computes a list of domain names from a seed, often the date, and tries them until one resolves. The attacker only needs to register one name from each day's list, which makes blocklists slow to keep up. The Conficker worm used this method at large scale in 2008 and 2009.
ATT&CK: T1568.002 (Dynamic Resolution: Domain Generation Algorithms).
On the wire and in logs: one host producing bursts of NXDOMAIN answers for random-looking names across many top-level domains, followed by one name that resolves.
Fast flux
How it works: the attacker's domain returns a rapidly changing set of IP addresses with very short TTLs, usually compromised machines acting as proxies. Taking down any single address does not take down the service.
ATT&CK: T1568.001 (Dynamic Resolution: Fast Flux DNS).
On the wire and in logs: a domain whose answers change on almost every lookup, TTLs of seconds to a few minutes, and addresses spread across many unrelated networks and countries.
Reflection and amplification attacks
How it works: the attacker sends small queries with the victim's address forged as the source to open resolvers or authoritative servers that return large answers. The servers flood the victim. DNS can multiply the attacker's traffic many times over, especially with large TXT, ANY, or DNSSEC responses.
ATT&CK: T1498.002 (Network Denial of Service: Reflection Amplification).
On the wire and in logs: your servers sending large volumes of responses to an address that sent you no real queries, and many requests for the same large record.
Reconnaissance
How it works: attackers map a network through DNS before attacking it: full zone transfers (AXFR) from misconfigured servers, reverse lookups across address ranges, brute force of common subdomain names, and certificate transparency logs that list every name a certificate was issued for.
ATT&CK: T1590.002 (Gather Victim Network Information: DNS).
On the wire and in logs: AXFR or IXFR queries from hosts that are not secondary servers, and one source sweeping PTR queries across a range.
Subdomain takeover
How it works: a record such as shop.example.com still points with a CNAME to a cloud service that the company deleted. The attacker registers the same resource name with the cloud provider and now serves content on the company's subdomain, which is useful for phishing and for stealing cookies scoped to the parent domain.
ATT&CK: T1584.001 (Compromise Infrastructure: Domains).
On the wire and in logs: this happens outside your network. Find it by regularly checking every CNAME in your public zones against the cloud resources you actually own.
Attacks on DNS servers themselves
DNS server software is a high-value target because it is reachable by design. SIGRed (CVE-2020-1350) was a wormable remote code execution flaw in the Windows DNS server, triggered by a malicious response to a query the server made. Because Windows DNS usually runs on domain controllers, exploitation meant domain compromise. KeyTrap (CVE-2023-50387) showed that crafted DNSSEC records could tie up validating resolvers with expensive calculations. Patch DNS servers on the same priority as internet-facing systems.
Abuse of Active Directory DNS
How it works: an attacker with any domain account adds a record to an Active Directory-integrated zone (for example, a name that a server keeps trying to resolve, or a wildcard), points it to their own machine, and captures or relays the NTLM authentication that follows.
ATT&CK: T1557.001 (Adversary-in-the-Middle: Name Resolution Poisoning and SMB Relay).
On the wire and in logs: with "Audit Directory Service Changes" turned on, domain controllers log Event 5137 (a directory object was created) for each new dnsNode object. A wildcard record appears as an object named * (DC=*), and any record created by an ordinary user account deserves a look. On the network, lookups that suddenly resolve to a workstation address.
Detection engineering
Log sources
| Source | What it records | What to look for |
|---|---|---|
| Resolver query logs (Windows DNS Server Analytical log, BIND query log, protective DNS logs) | Which client asked for which name and type, and the answer | Tunneling patterns, DGA bursts, lookups of known-bad domains |
Zeek dns.log | Every query and response seen on the wire, with flags, answers, and TTLs | The same patterns, plus DNS that never reached your resolvers |
Zeek conn.log or firewall logs | Connections to 53, 853, and known DoH endpoints on 443 | DNS that bypasses internal resolvers |
| Passive DNS history | How each domain resolved over time | Newly observed domains, fast flux, infrastructure reuse |
DNS Server audit log and directory change events (Event 5137 for new dnsNode objects) | Record and zone changes | Records created by unexpected accounts, wildcard records, zone setting changes |
| Registrar and DNS provider audit logs | Account logins and record changes for your public domains | Changes nobody requested |
| Certificate transparency monitoring | Certificates issued for your domains | Certificates you did not request |
Example detections
Tunneling by unique subdomains, as pseudo-SQL over Zeek data. registered_domain() stands for whatever function your platform uses to reduce a name to the part a person can register, based on the Public Suffix List.
SELECT orig_h,
registered_domain(query) AS domain,
COUNT(DISTINCT query) AS unique_names,
AVG(LENGTH(query)) AS avg_length
FROM dns_log
WHERE ts > now() - INTERVAL '1 hour'
GROUP BY orig_h, registered_domain(query)
HAVING COUNT(DISTINCT query) > 500 AND AVG(LENGTH(query)) > 40;
Expected false positives: some security products, content delivery networks, and anti-spam lookups use long generated names. Baseline for a week and add them to an allow list.
Domain generation algorithm activity, by NXDOMAIN rate per host:
SELECT orig_h,
COUNT(*) AS lookups,
SUM(CASE WHEN rcode_name = 'NXDOMAIN' THEN 1 ELSE 0 END) AS nxdomain
FROM dns_log
WHERE ts > now() - INTERVAL '15 minutes'
GROUP BY orig_h
HAVING SUM(CASE WHEN rcode_name = 'NXDOMAIN' THEN 1 ELSE 0 END) > 100
AND SUM(CASE WHEN rcode_name = 'NXDOMAIN' THEN 1 ELSE 0 END) > 0.5 * COUNT(*);
Expected false positives: misconfigured applications retrying a dead name, and browsers probing for intranet names. Those repeat the same few names; DGA traffic does not.
DNS that bypasses your resolvers:
SELECT orig_h, resp_h, resp_p, COUNT(*) AS connections
FROM conn_log
WHERE resp_p IN (53, 853)
AND orig_h NOT IN (SELECT ip FROM approved_resolvers)
AND NOT is_private(resp_h)
AND ts > now() - INTERVAL '1 day'
GROUP BY orig_h, resp_h, resp_p;
Add known DoH endpoints on port 443 to the same check using a maintained list of public DoH server addresses.
Zone transfer attempts, as Sigma-style YAML over Zeek DNS data:
title: DNS zone transfer request from an unapproved host
logsource:
product: zeek
service: dns
detection:
selection:
qtype_name:
- AXFR
- IXFR
filter_secondaries:
id.orig_h|cidr:
- 10.0.10.5/32
condition: selection and not filter_secondaries
falsepositives:
- Secondary servers not yet added to the filter
level: high
Prevention and hardening
In order of impact:
- Force all DNS through internal resolvers. Block outbound 53 and 853 from everything except those resolvers, and manage DNS over HTTPS through browser and Windows policy.
- Log every query, on the resolvers and on network sensors, and keep the logs for at least 90 days. DNS logs are often the only record of what an infected machine contacted.
- Add protective DNS or response policy zones that block known-malicious and newly registered domains.
- Protect your registrar and DNS provider accounts with multi-factor authentication, turn on registry lock for critical domains where your registrar offers it, and monitor certificate transparency logs for your domains.
- Restrict zone transfers to named secondaries, turn off recursion on authoritative servers, and turn on response rate limiting on public servers.
- Patch DNS servers quickly. SIGRed showed that a DNS flaw on a domain controller is a domain-wide incident.
- Lock down Active Directory-integrated zones: remove record creation for Authenticated Users or pre-create a harmless wildcard record, and keep the
wpadentry in the global query block list. - Treat DnsAdmins as a Tier 0 group, and review its membership.
- Turn off LLMNR and NetBIOS name resolution, which attackers use when DNS lookups fail.
- Turn on DNSSEC validation on your resolvers, and sign your public zones once you have a tested key rollover process.
- Remove dangling CNAME records, and publish CAA records for your domains.
- Publish SPF, DKIM, and DMARC with a reject policy for every domain, including ones that send no email.
Incident response and remediation
When DNS abuse is suspected:
- Scope from the logs. Find every host that queried the suspicious domain, when they started, and what they did next.
- Block or sinkhole the domain at your resolvers. Pointing it at an internal sinkhole also reveals any infected host you missed, because it keeps trying.
- Investigate the hosts behind the queries as compromised, not only the domain.
- After cache poisoning, flush resolver caches once the cause is fixed, and confirm answers for the affected names match the authoritative servers.
- After a hijack of your own domains: regain control of the registrar account, restore the correct records, rotate all registrar and DNS provider credentials, and revoke any TLS certificates issued while the attacker controlled the domain. Treat credentials entered on hijacked sites (VPN, webmail) as stolen.
- In Active Directory, look for records created by unexpected accounts, wildcard records, and changes to the global query block list. Check DnsAdmins membership and whether the DNS server is configured to load a plugin DLL.
- Preserve DNS logs and passive DNS data for the investigation before they roll over.
Real-world cases
- CVE-2008-1447: Dan Kaminsky's cache poisoning attack. A coordinated, multi-vendor patch release in July 2008 added source port randomization to resolvers worldwide.
- CVE-2020-1350, SIGRed: a remote code execution flaw in the Windows DNS server, rated 10.0. The flaw had existed in the code for about 17 years and could spread from server to server without user interaction.
- CVE-2023-50387, KeyTrap: crafted DNSSEC records could make validating resolvers spend excessive CPU, enough for a single packet to stall a resolver for a long time. Major resolver vendors patched it in early 2024.
- Mirai and Dyn, October 2016: a botnet of compromised internet-connected devices flooded Dyn, a major DNS provider, making many large websites unreachable for parts of a day. It showed how much of the internet depends on a few DNS providers.
Framework mappings
- T1071.004: Application Layer Protocol: DNS
- T1572: Protocol Tunneling
- T1048: Exfiltration Over Alternative Protocol
- T1568.002: Dynamic Resolution: Domain Generation Algorithms
- T1568.001: Dynamic Resolution: Fast Flux DNS
- T1498.002: Network Denial of Service: Reflection Amplification
- T1590.002: Gather Victim Network Information: DNS
- T1584.002: Compromise Infrastructure: DNS Server
- T1557: Adversary-in-the-Middle
- T1584.001: Compromise Infrastructure: Domains
DNS in the news
News stories tagged with DNS. This list updates on its own while the page is open.
No news stories are tagged with this topic yet.
Frequently asked questions
Does DNS over HTTPS make DNS monitoring impossible?
Not if you manage it. Block public DoH services and turn browser DoH off or point it at your own resolver through policy. Your resolvers then still see and log every query. Unmanaged DoH is what removes visibility.
Why does Active Directory need DNS?
Clients find domain controllers, Kerberos services, and global catalog servers through DNS SRV records, and computers register their own names in DNS. If DNS fails or is poisoned, logons, Group Policy, and replication fail or can be redirected.
Should we sign our public zones with DNSSEC?
It protects your records from forgery for every resolver that validates. The risk is operational: a mistake during key rollover makes your domain unreachable for validating resolvers. Sign once you have a tested rollover process, or use a DNS provider that automates it.
Which DNS logs should a SOC keep?
Client query logs from your resolvers, ideally with the answers, plus network sensor data such as Zeek dns.log to catch DNS that bypasses your resolvers. Keep at least 90 days. Add registrar audit logs and certificate transparency alerts for your own domains.
Is DNS over TCP suspicious?
Not by itself. Large answers, DNSSEC responses, and zone transfers use TCP, and it is a normal fallback. A workstation sending a steady stream of TCP DNS to one external domain is different and is worth checking for tunneling tools.
References and further reading
- RFC 1034: Domain Names, Concepts and Facilities
- RFC 1035: Domain Names, Implementation and Specification
- RFC 6891: Extension Mechanisms for DNS (EDNS(0))
- RFC 7766: DNS Transport over TCP
- RFC 4033: DNS Security Introduction and Requirements (DNSSEC)
- RFC 5452: Measures for Making DNS More Resilient against Forged Answers
- RFC 7858: DNS over Transport Layer Security (DoT)
- RFC 8484: DNS Queries over HTTPS (DoH)
- Zeek documentation: dns.log
- Microsoft Learn: DNS socket pool and Windows Server DNS security
- NetSPI: ADIDNS Revisited, WPAD, GQBL, and More (Kevin Robertson)
- MITRE ATT&CK Enterprise matrix
- MITRE CWE list
- NIST Computer Security Resource Center glossary
Found a technical error in this entry? Tell us and we will fix it.