DNS is allowed out of almost every network, so attackers use it to carry commands and stolen data in plain sight, one small query at a time. DNS tunnelling encodes data in the names a compromised host looks up and in the records the attacker's authoritative server sends back. It rarely moves data fast, but it works where web traffic is filtered, and many SOCs never look at it. This guide is for SOC analysts and network defenders: how tunnelling shows up, the telemetry you need, the detection signals that separate it from normal traffic, how resolver controls shrink the problem, how to triage an alert, and the false positives that waste analyst time. It goes deeper on tunnelling than the general DNS Logging and Detection Guide and stays defensive: there are no tool walkthroughs here.
Key takeaways
- Tunnelling has a shape, not a signature. Long, high-entropy labels, hundreds of unique subdomains under one parent domain, unusual record types and steady query volume from one client are the signals. No single one is enough.
- Measure per client and per parent domain. Aggregate by registered domain and source host over time windows. Looking at single queries finds nothing; looking at unique subdomains per domain per hour finds most tunnels.
- Force every client through your resolvers. Block outbound port 53 and 853 from everything except designated resolvers and turn off browser DNS over HTTPS to external providers, or the tunnel simply goes around your logs.
- Expect noisy legitimate look-alikes. Security products, content delivery networks and anti-spam lookups also generate long, random-looking names. A maintained allowlist is part of the detection, not an afterthought.
- Treat a confirmed tunnel as a compromised host. Block the domain at the resolver, isolate the host, and scope what data could have left: a tunnel is evidence of code running, not just odd traffic.
How DNS tunnelling works
MITRE ATT&CK describes adversaries communicating over DNS to blend in with existing traffic, embedding commands and results in the protocol, and notes that DNS is often allowed even before network authentication completes. The defensive model is simple:
- The attacker registers a domain and runs (or points delegation to) an authoritative name server they control.
- Malware on the victim host encodes data, commonly in base32 or hex, into subdomain labels and asks its normal resolver for that name.
- The enterprise resolver cannot answer from cache, so it recurses to the attacker's authoritative server, which receives the encoded data.
- The authoritative server replies with instructions encoded in the answer, often in TXT, NULL, CNAME or A records.
Two consequences shape detection. First, the infected host never needs a direct connection to the internet: the enterprise resolver carries the traffic, so resolver logs alone show the resolver, not the true source, unless you also log the client. Second, every query must be unique (or the resolver answers from cache), so tunnels produce a long tail of never-repeated names under one domain. DNS limits also apply: a label holds at most 63 octets and a full name at most 255 octets, so data moves in small chunks and a busy tunnel needs many queries.
| Use | ATT&CK v20 technique | What it looks like in DNS |
|---|---|---|
| Command and control over DNS | T1071.004 Application Layer Protocol: DNS | Low, regular beacons to one domain, commands returned in TXT or A records |
| Tunnelling another protocol inside DNS | T1572 Protocol Tunneling | Sustained high volume of unique queries carrying an interactive session |
| Data theft over DNS | T1048 Exfiltration Over Alternative Protocol (and T1048.003 for unencrypted non-C2 protocols) | Bursts of long outbound labels, often outside working hours, few or empty answers |
| Domain generation for C2 | T1568.002 Dynamic Resolution: Domain Generation Algorithms | Many different random registered domains, mostly NXDOMAIN; related but distinct from tunnelling |
For the wider C2 picture see the Command and Control (C2) Guide and the T1572 Protocol Tunnelling Defensive Guide.
Telemetry you need
Detection fails most often because the right fields are not collected at the right point. Combine at least one resolver source with one endpoint source.
| Source | Key fields | Strengths | Gaps |
|---|---|---|---|
| Windows DNS Server Analytical log | Events 257 RESPONSE_SUCCESS and 258 RESPONSE_FAILURE with client, query name, type, response code | Covers every client of the DC or DNS server | Off by default; Microsoft cites about 5 per cent degradation at 100,000 queries per second and no apparent impact at 50,000 or lower |
| Windows DNS Server Audit log | Zone and record changes | On by default, low cost | No query data at all |
| Sysmon Event ID 22 (DNSEvent) | Process image, query name, results, status | Names the process that asked, logged whether the answer came from cache or not | Endpoint coverage only; Windows 8.1 and later |
| Zeek dns.log | id.orig_h, query, qtype_name, rcode_name, answers, TTLs, uid | Full query and answer at a network choke point; pivot to conn.log by uid | Blind to DNS over HTTPS and DNS over TLS |
| Cloud resolver query logs | Source resource, query, type, response code | Covers workloads in virtual networks | Caching can hide repeats; count unique names |
| Protective DNS service logs | Client, query, policy action | Blocking and logging in one place | Only for clients that use it |
Keep at least the query name, record type, response code, answer size or data, client address and timestamp. Without response codes and answer sizes you lose two of the strongest signals. Retain enough history (90 days is a sensible floor) to know when a domain first appeared in your environment. For Zeek field use see the Zeek Logs Cheat Sheet.
Detection signals
Score several signals together per client and registered domain, and alert on the combination. Thresholds below are starting points to tune against your own baseline, not universal values.
| Signal | How to compute | Starting point | Common false positives |
|---|---|---|---|
| Unique subdomains per parent domain | Distinct full names under one registered domain, per client, per hour | Hundreds per hour from one client | Anti-spam and reputation lookups, telemetry from security agents |
| Label and query length | Longest label and total name length | Labels over about 50 characters, names near the 255 octet limit | CDN and cloud service hostnames with long hashes |
| Character entropy | Shannon entropy of the subdomain part, plus digit ratio and consonant runs | Consistently high across many queries from one client | Hash-based hostnames, DKIM selectors |
| Record type mix | Share of TXT, NULL, CNAME or other uncommon types per client | Workstation making many TXT or NULL queries to one domain | Mail servers (TXT for SPF), some security agents |
| Volume and regularity | Queries per client per domain over time; inter-query interval and jitter | Steady stream for hours, or regular beacons from a server | Software update checks, monitoring agents |
| Response code pattern | NXDOMAIN or NOERROR with no answer, per domain | High NXDOMAIN share to one domain, or many empty answers | Misconfigured search suffixes, DGA activity (a different problem) |
| Bytes per domain | Total request and response bytes per client per domain | Kilobytes to megabytes per day to a low-popularity domain | Large TXT records for legitimate verification |
| Domain popularity and age | How many internal clients query the domain; first-seen date | One client, never seen before | New SaaS rollouts |
Combine, then rank. A practical first rule: one internal client, one registered domain, more than a few hundred unique subdomains in an hour, median label length above about 30 characters, and the domain queried by fewer than three clients in the environment. Then rank by bytes per domain. This catches both fast tunnels and slow exfiltration while ignoring most CDN traffic, which is queried by many clients.
Slow tunnels. ATT&CK notes that DNS beacons may be hard to spot because they communicate infrequently. Extend windows to 24 hours and seven days for low-volume rules, and look for regular intervals from servers, which have narrow and predictable DNS behaviour.
Encrypted DNS bypass. Alert on any internal host other than a resolver sending traffic to port 53 or 853 on the internet, and on connections to known public DNS over HTTPS endpoints. A host that suddenly prefers DoH to an outside provider is itself a lead.
Where identity fits. Servers and workloads run as non-human identities with a short list of expected destinations. A per-workload allowlist of domains, built from DNS logs, makes tunnelling from a workload stand out quickly. See the Cloud Workload Identity Guide.
Prevention with resolver controls
Detection is easier when the network gives tunnels fewer places to hide. Roll out in this order:
- Designate resolvers. List every resolver, forwarder and DC acting as DNS server, and which clients use each. Only these may talk DNS to the internet.
- Close direct paths. Block outbound UDP and TCP 53 and TCP 853 from all other hosts at the firewall. Test in log-only mode for a week to find appliances with hard-coded public resolvers.
- Manage encrypted DNS. Offer DoH or DoT on your own resolvers if you need privacy on the wire. Set browser policy: in Microsoft Edge the DnsOverHttpsMode policy accepts off, automatic or secure (Group Policy "Control the mode of DNS-over-HTTPS"); Chrome has an equivalent enterprise policy. Firefox disables default-on DoH when the network's resolver gives a negative answer for the canary domain use-application-dns.net, but Mozilla notes this applies only where DoH was the default, not where a user turned it on, so use enterprise policy as well.
- Use protective DNS. A protective DNS resolver checks queries against threat intelligence and blocks known malicious domains. CISA's Protective DNS service for US federal civilian agencies, for example, provides blocking, log data and DoH and DoT support. See the Protective DNS Guide and, for local policy, DNS Response Policy Zones.
- Restrict servers further. Servers that need no internet names (database tiers, OT gateways) should use resolvers that only answer internal zones and an allowlist of external domains.
- Roll back safely. If a block breaks a business system, add a scoped exception for that host and resolver rather than reopening port 53 for the segment, and record the exception with an owner and expiry.
Small versus large organisations. A small organisation can get most of the value from a protective DNS service with query logging, egress rules for 53 and 853, browser policy and EDR DNS telemetry. A large one needs logs at every resolver tier, sensors at egress points, a data pipeline that summarises to per-client, per-domain counts, and a detection engineer to keep thresholds and allowlists current. The Encrypted DNS Enterprise Guide covers the DoH design choices in more depth.
Triage and response
- Confirm the pattern. Pull every query from the client to the domain over the window: count, unique names, label lengths, record types, answer sizes. Decode a sample of labels; readable fragments or consistent base32 or hex structure raise confidence.
- Check the domain. Registration age, authoritative name servers, how many clients query it, threat intelligence matches. A domain only one host has ever asked for is a strong indicator.
- Find the process. Use Sysmon Event ID 22 or EDR telemetry to name the process and user behind the queries. A resolver log alone cannot do this when queries pass through a forwarder.
- Contain. Sinkhole or block the domain at the resolver and protective DNS, and isolate the host with EDR. Blocking only the domain warns the operator, who may switch domains, so isolate at the same time when confidence is high.
- Scope. Search all DNS logs for the domain, its name servers and similar label patterns from other hosts. Estimate how much data could have left from total query bytes over time. See the Data Exfiltration Scoping Guide.
- Preserve evidence. Keep DNS logs, a memory image and the binary before reimaging, and record the timeline.
- Close and tune. Add confirmed false positives to the allowlist with a reason and an owner, and feed confirmed domains to your blocklists.
Metrics that show it is working
- Percentage of client networks whose DNS reaches a logged resolver (target 100 per cent, cloud included).
- Internal non-resolver hosts with direct external DNS or DoT traffic per week (target zero).
- Percentage of servers with process-attributed DNS telemetry.
- True positive rate of tunnelling rules, reviewed monthly, and size of the allowlist with owners.
- Median time from first tunnelling query to host isolation in confirmed cases and exercises.
Common failure patterns
- Logging only the forwarder. Every query appears to come from the domain controllers, so the infected client cannot be identified. Log at the client-facing tier and add endpoint telemetry.
- Single-query rules. Alerting on any long name floods the queue with CDN and security agent traffic; aggregate by client and domain instead.
- No allowlist ownership. Analysts suppress noisy security vendor domains ad hoc, the list grows without review, and an attacker domain that resembles a vendor pattern is hidden.
- DoH left open. Browsers and malware use public DNS over HTTPS, the resolver logs look clean and the detection program measures only part of reality.
- Raw volume thresholds on cached logs. Cloud and caching resolvers may log only first lookups, so counts underestimate activity; use unique names.
- Blocking without isolating. The domain is sinkholed but the host stays online, and the operator moves to a new domain or channel within hours.
Framework mapping
| Framework | Reference | How it applies |
|---|---|---|
| MITRE ATT&CK v20 | T1071.004, T1572, T1048, T1048.003, T1041 | C2, tunnelling and exfiltration behaviours detected in DNS |
| NIST SP 800-53 Rev. 5 | SI-4 System Monitoring, AU-2 Event Logging, AU-6 Audit Record Review | Collecting and analysing DNS telemetry |
| NIST SP 800-53 Rev. 5 | SC-7 Boundary Protection, SC-21 and SC-22 name resolution controls | Egress control and designated resolvers |
| NIST CSF 2.0 | DE.CM-01, DE.AE-02 | Monitoring network services and analysing adverse events |
| CIS Controls v8.1 | Safeguard 8.6 Collect DNS Query Audit Logs, Safeguard 9.2 Use DNS Filtering Services | Query logging and filtering |
| NIST SP 800-81 Rev. 3 | Secure DNS Deployment Guide (March 2026) | Secure resolver design, protective and encrypted DNS, DNS logging |
Practitioner checklist
- Map every resolver and forwarder and the clients each serves.
- Log query name, type, response code, answer and client at client-facing resolvers; enable the Windows DNS Analytical log after a performance pilot.
- Collect Sysmon Event ID 22 or EDR DNS telemetry from servers and key workstations.
- Build aggregate rules on unique subdomains, label length, entropy, record type and bytes per client and domain.
- Maintain an owned, reviewed allowlist for CDN, anti-spam and security vendor domains.
- Block outbound 53 and 853 from non-resolvers and set browser DoH policy.
- Route clients through protective DNS or RPZ with logging.
- Write a triage runbook that ends in host isolation and exfiltration scoping.
- Keep 90 days or more of searchable DNS logs and review rule precision monthly.
Standards and references
- MITRE ATT&CK: Application Layer Protocol: DNS
- NIST: SP 800-81 Rev. 3 Secure Domain Name System (DNS) Deployment Guide
- CISA: Protective Domain Name System Resolver
- Microsoft Learn: DNS logging and diagnostics
- Microsoft Learn: Sysmon
- Zeek documentation: dns.log
- Microsoft Learn: Edge DnsOverHttpsMode policy
- Mozilla: Canary domain use-application-dns.net
Related NHI Mgmt Group resources: DNS Logging and Detection Guide · Protective DNS Guide · Beaconing and C2 Detection Guide · Data Exfiltration Guide