Join our Newsletter — 33% off our NHI Course
Home› Guides› DNS Tunnelling Detection: Spotting C2 and Exfiltration Hidden…
Guide SOC & Detection Engineering

DNS Tunnelling Detection: Spotting C2 and Exfiltration Hidden in DNS

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 13 min read
On this page

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:

  1. The attacker registers a domain and runs (or points delegation to) an authoritative name server they control.
  2. Malware on the victim host encodes data, commonly in base32 or hex, into subdomain labels and asks its normal resolver for that name.
  3. The enterprise resolver cannot answer from cache, so it recurses to the attacker's authoritative server, which receives the encoded data.
  4. 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.

UseATT&CK v20 techniqueWhat it looks like in DNS
Command and control over DNST1071.004 Application Layer Protocol: DNSLow, regular beacons to one domain, commands returned in TXT or A records
Tunnelling another protocol inside DNST1572 Protocol TunnelingSustained high volume of unique queries carrying an interactive session
Data theft over DNST1048 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 C2T1568.002 Dynamic Resolution: Domain Generation AlgorithmsMany 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.

SourceKey fieldsStrengthsGaps
Windows DNS Server Analytical logEvents 257 RESPONSE_SUCCESS and 258 RESPONSE_FAILURE with client, query name, type, response codeCovers every client of the DC or DNS serverOff 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 logZone and record changesOn by default, low costNo query data at all
Sysmon Event ID 22 (DNSEvent)Process image, query name, results, statusNames the process that asked, logged whether the answer came from cache or notEndpoint coverage only; Windows 8.1 and later
Zeek dns.logid.orig_h, query, qtype_name, rcode_name, answers, TTLs, uidFull query and answer at a network choke point; pivot to conn.log by uidBlind to DNS over HTTPS and DNS over TLS
Cloud resolver query logsSource resource, query, type, response codeCovers workloads in virtual networksCaching can hide repeats; count unique names
Protective DNS service logsClient, query, policy actionBlocking and logging in one placeOnly 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.

SignalHow to computeStarting pointCommon false positives
Unique subdomains per parent domainDistinct full names under one registered domain, per client, per hourHundreds per hour from one clientAnti-spam and reputation lookups, telemetry from security agents
Label and query lengthLongest label and total name lengthLabels over about 50 characters, names near the 255 octet limitCDN and cloud service hostnames with long hashes
Character entropyShannon entropy of the subdomain part, plus digit ratio and consonant runsConsistently high across many queries from one clientHash-based hostnames, DKIM selectors
Record type mixShare of TXT, NULL, CNAME or other uncommon types per clientWorkstation making many TXT or NULL queries to one domainMail servers (TXT for SPF), some security agents
Volume and regularityQueries per client per domain over time; inter-query interval and jitterSteady stream for hours, or regular beacons from a serverSoftware update checks, monitoring agents
Response code patternNXDOMAIN or NOERROR with no answer, per domainHigh NXDOMAIN share to one domain, or many empty answersMisconfigured search suffixes, DGA activity (a different problem)
Bytes per domainTotal request and response bytes per client per domainKilobytes to megabytes per day to a low-popularity domainLarge TXT records for legitimate verification
Domain popularity and ageHow many internal clients query the domain; first-seen dateOne client, never seen beforeNew 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. Preserve evidence. Keep DNS logs, a memory image and the binary before reimaging, and record the timeline.
  7. 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

FrameworkReferenceHow it applies
MITRE ATT&CK v20T1071.004, T1572, T1048, T1048.003, T1041C2, tunnelling and exfiltration behaviours detected in DNS
NIST SP 800-53 Rev. 5SI-4 System Monitoring, AU-2 Event Logging, AU-6 Audit Record ReviewCollecting and analysing DNS telemetry
NIST SP 800-53 Rev. 5SC-7 Boundary Protection, SC-21 and SC-22 name resolution controlsEgress control and designated resolvers
NIST CSF 2.0DE.CM-01, DE.AE-02Monitoring network services and analysing adverse events
CIS Controls v8.1Safeguard 8.6 Collect DNS Query Audit Logs, Safeguard 9.2 Use DNS Filtering ServicesQuery logging and filtering
NIST SP 800-81 Rev. 3Secure 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

Related NHI Mgmt Group resources: DNS Logging and Detection Guide · Protective DNS Guide · Beaconing and C2 Detection Guide · Data Exfiltration Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.