

DNS Tunneling: How Attackers Hide Data and How to Detect It

DNS tunneling is the encoding of data inside DNS queries and responses so that a compromised host can exchange commands or stolen data with an attacker-controlled authoritative nameserver. In the usual recursive form, the organization’s own resolvers act as the courier, so the host needs no direct connection to the attacker. The signals for plaintext tunnels are well documented, and for most teams the harder problem is visibility: seeing every DNS query, tying it to a host and process, and investigating it before the channel goes quiet.
The technique is old and the tools are open source, yet new malware still uses it, with Check Point documenting a DNS-tunneling backdoor as recently as 2025.
TL;DR:
- DNS is widely trusted, and recursive resolution can deliver tunnel traffic to the attacker’s server even when the host cannot reach that server directly.
- Tunnels leave payload fingerprints, such as long encoded labels and unusual record types, and traffic fingerprints, such as high volume and many unique subdomains under one domain.
- Controlling which resolvers hosts can use matters more than any single detection rule, especially once encrypted DNS enters the picture.
- A tunneling alert stays a hypothesis until someone ties the queries to a process, a data volume, and a timeline.
Why DNS Makes a Reliable Covert Channel
DNS works as a covert channel because most networks allow it outbound, many don’t inspect it, and recursion routes each query to whoever is authoritative for the domain. Attackers abuse it as an application-layer C2 protocol because DNS is administratively common, can be allowed before network authentication completes, and has many fields and headers in which to conceal data.
A host in a segmented network with no route to the internet can still ask the internal resolver about anything.attacker-domain.example, and if that resolver resolves external names, it forwards the question up the delegation chain to the attacker’s nameserver and returns the answer. Egress firewall rules that block the host’s direct connections never see a connection to block.
How DNS Tunneling Works
A tunnel runs in order through three parties: the compromised host that encodes data into queries, the recursive resolver that relays them, and the attacker’s authoritative nameserver that decodes queries and encodes replies.
Registering the Domain and Authoritative Server
The attacker registers a domain and delegates it, or a subdomain, to a server they control. In a typical setup, NS records delegate the domain to a nameserver hostname whose A record points to that server, which makes it authoritative. The server runs the tunnel software (iodined, the dnscat2 server, or a C2 framework listener) that parses incoming names and builds responses.
Encoding Data in Subdomain Labels
The client carries upstream data in the query name: it chunks data, encodes it with a DNS-safe alphabet, and prepends it as labels to the attacker’s domain. RFC 1035 limits each label to 63 octets and the full name to 255 octets, so each query carries well under 255 bytes of raw payload once the domain suffix, label separators, and encoding overhead are subtracted.
Alphabet choice depends on what the resolvers in the path tolerate. iodine sends upstream data gzipped and Base32-encoded, or uses Base64, Base64u, or Base128 when the relay supports those characters. dnscat2 hex-encodes the data it carries in names and TXT records. Because chunks can arrive out of order or be retried, tools embed sequence numbers or session identifiers in the labels.
Carrying Responses in TXT, NULL, and CNAME Records
Downstream data rides in the answer, and the record type sets the capacity. These are the record types tunnels rely on most:
- TXT returns strings and carries far more per response than an A record, which makes it a common tunnel carrier.
- NULL can hold arbitrary binary data, so iodine treats it and its private type as the highest-bandwidth options and sends data raw, although message overhead and resolver limits keep real responses small.
- CNAME returns a hostname that can carry encoded labels; tools such as dnscat2 end it in their own domain so intermediate resolvers pass it along.
- A records carry four bytes per response and AAAA records 16.
A Tunneling Query Next to a Normal Lookup
A single log line can show the suspicious features, although confirming a tunnel takes more context. Below, the first row is an ordinary lookup and the second is a Base32-encoded chunk (“hello world”) with a sequence label sent to a placeholder tunnel domain:
| Client | Query | Type | Response |
|---|---|---|---|
| 10.0.4.21 | www.example.com |
A | 192.0.2.10 |
| 10.0.4.37 | nbswy3dpeb3w64tmmq.0042.t1.example.net | TXT | “6f6b3a3030343200” |
The tunnel row has a Base32-encoded leftmost label, a counter, and a TXT record with an encoded reply.
What Attackers Use DNS Tunnels For
Exfiltration is the clearest use: ATT&CK T1048.003 describes attackers hiding stolen data in natively unencrypted protocols such as DNS, sometimes base64-encoded in headers and fields. In the campaign MITRE tracks as C0017, APT41 exfiltrated victim data by encoding it and prepending it as subdomains to an attacker-controlled domain, the kind of DNS egress that exfiltration prevention controls have to account for.
Tunnels also carry command and control, where low-rate beacons query the nameserver for tasking, and they let attackers bypass network policy, reaching out from segments that allow only internal DNS. Benign uses exist too, such as some antivirus reputation lookups.
DNS Tunneling Tools and Real Campaigns
Defenders see the same small set of public tools reused by custom malware, so knowing how each behaves tells you what the logs should contain.
Common Tunneling Tools
iodine tunnels IPv4 over DNS, auto-detects the best record type, and prefers NULL. dnscat2 builds an encrypted command channel over TXT, MX, CNAME, A, and AAAA records and rejects unencrypted sessions by default. Cobalt Strike’s DNS Beacon is a DNS-only payload that polls its team server over DNS and downloads tasks over A, AAAA, or TXT (the default); it skips the full check-in until a task is waiting, but keeps polling at every sleep interval.
Campaigns That Used DNS Tunneling
Infoblox disclosed Decoy Dog in April 2023. The toolkit is a modified version of the open-source Pupy RAT with rewritten communication modules and its own domain generation algorithm, and Infoblox later found its controllers run by at least three separate actors.
OilRig (APT34) has built DNS tunnels into its tooling: its Spearal backdoor sends TXT queries to its C2 server and encodes data in the query subdomains with a custom Base32 scheme.
More recent reporting shows the same reuse of DNS tunnels in custom tooling:
- Storm-2603, a ransomware-linked group, used the AK47DNS backdoor, which hex-encodes its traffic into subdomain labels and exchanges it through TXT lookups.
- CISA’s AA24-249A reports that Unit 29155 actors used dnscat2 and iodine to tunnel IPv4 traffic out of victim networks.
In 2020, CISA advisory AA20-352A flagged additional CNAME resolutions for avsvmcloud[.]com, the encoded-subdomain C2 domain of the SUNBURST backdoor, as a sign of follow-on activity.
DNS Tunneling vs Other Covert Channels
DNS offers less bandwidth than other covert channels but reaches further:
| Channel | Protocol | Relative bandwidth | Detection difficulty |
|---|---|---|---|
| DNS tunnel | DNS over UDP/TCP 53, or DoH on 443 | Low | Moderate with resolver logs; high over DoH |
| ICMP tunnel | ICMP echo | Low | Moderate |
| HTTP/HTTPS tunnel | TCP 80 or 443 | High | High over HTTPS, which blends with web traffic |
DNS cache poisoning is a different attack, catalogued as CAPEC-142, in which an adversary modifies a resolver’s cache so names resolve to attacker-chosen addresses. It corrupts resolution instead of carrying data through it.
How to Detect DNS Tunneling
Payload analysis inspects individual queries and responses and tends to catch specific utilities, and traffic analysis looks at behavior over time and generalizes better across tools, so most teams run both.
Payload Indicators
Because a label holds at most 63 characters and the encoding needs a restricted alphabet, tunneled data leaves marks in the query name: labels near 63 characters, high subdomain entropy, and character sets that match Base32 or hex. Queries to known malicious infrastructure are a further flag, and record-type mix matters too, because a workstation sending NULL queries is unusual. A host that suddenly sends a burst of TXT queries after weeks of none is worth a look.
Traffic Indicators
Tunnels generate a new subdomain for nearly every request, so aggregate queries per client and per registered domain over a short window and count the unique names. Elastic’s prebuilt rule for DNS tunneling works this way, grouping queries by client and registered domain in five-minute windows and flagging bursts of long distinct subdomains, NULL queries, or long TXT queries. A spike in NXDOMAIN responses from one client also merits investigation, though it can point to a DGA instead.
Domain and Resolver Signals
Domain age and prevalence are a cheap signal that payload rules miss: a registered domain that few hosts in your environment have ever queried, now receiving thousands of unique subdomains from one host, is a high-value lead. Resolver bypass is the other cheap signal: any host sending DNS directly to an external IP on port 53, port 853, or a known DoH endpoint. If only approved resolvers should answer, every other DNS flow is either misconfiguration or evasion.
Sample Queries and False Positive Tuning
A Zeek dns.log in JSON already carries the fields you need (id.orig_h, query, qtype_name, rcode_name, answers). A minimal pull with jq:
jq -r '[."id.orig_h", .query, .qtype_name, .rcode_name] | @tsv' dns.log
Network logs name the host, while Sysmon Event ID 22 names the process, recording DNS queries a process makes through the Windows DNS client on Windows 8.1 and later. Escalate when a non-browser process (PowerShell, rundll32, an unsigned binary) on one host sends sustained, unique, long subdomains to a single rarely seen domain.
Published randomized-subdomain searches use cutoffs on average subdomain entropy and minimum length, and those cutoffs work best once tuned against your own baseline. Allowlist known benign sources before you tighten thresholds, because these commonly produce long, high-entropy names:
- Antivirus reputation lookups that send file hashes over DNS.
- CDNs that encode file identifiers in long names.
- Mail servers doing DNS-based anti-spam lookups and TXT queries for SPF and other mail-authentication records.
- Search, social, and streaming services that use disposable domains for signaling.
If those services dominate your baseline, hunt for the same patterns from processes and hosts that never run them.
Handling Tunnels Over DoH and DoT
Encrypting DNS hides query names and record types from network-based monitoring. Of the two encrypted protocols, DoT is easier to spot because it uses its own port, 853, while DoH shares port 443 with web traffic. Attackers already use the cover: Cobalt Strike 4.11 added a DoH Beacon that carries its DNS channel over HTTPS, and the BRICKSTORM backdoor uses DoH to resolve its C2 servers before talking to them over encrypted web traffic, which hides even the lookup.
Making the enterprise resolver the only DoH endpoint moves visibility back to resolver logs. Firefox’s DNSOverHTTPS policy, Chrome and Edge’s DnsOverHttpsMode policy, and the DNS Client Group Policy in recent Windows versions can all lock the DoH setting, and Firefox also turns off default DoH when the canary domain use-application-dns.net returns NXDOMAIN.
Malware that runs its own resolver or DoH client bypasses the Windows DNS client, so Event ID 22 misses it; endpoint network-connection telemetry to known DoH hosts closes part of that gap.
How to Respond to and Prevent DNS Tunneling
If a tunnel is confirmed, contain the host and block the domain at the resolver, then scope the activity. If it is only suspected, gather process and volume evidence before blocking. If no resolver query logs exist yet, enable them first: on Windows DNS Server, analytical and debug logging are off by default. Route 53 Resolver logs queries only after you create a query logging configuration, and even then it skips answers served from its cache.
Investigating a Suspected Tunnel
Scope a suspected tunnel by working through these questions in order:
- Which hosts queried the domain, and since when, using resolver and passive DNS history.
- Which process issued the queries, from Event ID 22
ImageandProcessGuidor EDR DNS events. - How much DNS traffic each source sent, using query and answer lengths as a first estimate before accounting for encoding, polling, and retries.
- What the process did before the tunnel started, such as file access, compression, or credential use.
- Whether other domains share the same nameserver or encoding pattern.
Searching other hosts for the same process hash shows whether the tunnel is isolated or part of a wider intrusion.
Prevention Controls
Prevention starts with forcing all DNS through approved resolvers. NSA and CISA’s Protective DNS sheet recommends blocking outbound ports 53 and 853 from everything except the approved resolvers and blocking traffic to unauthorized DoH servers, to keep hosts from routing around resolver controls. DNS filtering at those resolvers blocks known malicious and categorized domains and can log queries.
CISA’s Protective DNS Resolver blocks, redirects, or sinkholes matching queries and alerts the agency; it is required for federal civilian executive branch agencies, and critical infrastructure can join only through a limited pilot. Sinkholing can cut off communication with a known tunnel domain, but a freshly registered tunnel domain may not yet appear in a threat feed, which is why behavioral detection and log retention still matter.
DNS Tunneling Is a Visibility Problem Before It Is a Detection Problem
Detecting any of these patterns depends on knowing what your resolver logs, endpoint DNS events, and network sensors cover: which keep client identity, which skip cached answers, and where encrypted DNS or resolver bypass leaves gaps. Without that coverage, entropy rules have little to work on. Decoy Dog ran for about a year before a resolver operator watching DNS behavior caught it.
Tunnels that stay below alert thresholds call for hypothesis-driven hunts, and a threat hunting program is where those hypotheses belong. Daylight’s MDR investigates and responds to the alerts a team’s existing tools raise, and Threat Hunting, a separate service, has security experts develop hypotheses such as DNS-borne exfiltration that specialized agents run at scale. Start by checking whether, for any domain, you can tell which hosts and processes queried it and how much they sent.
Frequently Asked Questions About DNS Tunneling
How Fast Can Data Move Through a DNS Tunnel?
Throughput depends on the tool, record type, resolver path, and latency, but published tests put it in the tens to hundreds of kilobits per second. In iodine’s throughput tests, sustained rates through a carrier-grade DNS cache over Wi-Fi were about 50 kbit/s upstream and more than 200 kbit/s downstream, and several times that on a wired test LAN. Low-rate C2 beacons move far less by design.
Does Blocking TXT Records Stop DNS Tunneling?
Blocking TXT does not stop DNS tunneling, because the common tunnel tools can all carry data in other record types, such as A, AAAA, MX, or CNAME, at lower bandwidth. The block also breaks SPF and other mail-authentication lookups that ride on TXT, so it costs the defender more than it costs the attacker.
Does DNSSEC Prevent DNS Tunneling?
DNSSEC does not prevent DNS tunneling, because it authenticates the origin and integrity of DNS responses without inspecting what a query or answer carries. An attacker who controls the tunnel domain can sign that zone like any other, and validating resolvers will pass its encoded answers as legitimate.
Which DNS Logs Should Be Retained for Tunneling Investigations?
Retain resolver query and response logs with client IP, query name, record type, response code, and answers, and keep them long enough to reach back to the start of a slow tunnel found months later. Federal agencies have a baseline to work from: OMB M-26-14 requires retained logs to stay actively searchable for six months and retrievable for one year.
Is DNS Tunneling the Same as a Domain Generation Algorithm?
DNS tunneling and domain generation algorithms solve different problems. A DGA (ATT&CK T1568.002) generates many candidate domains so malware can find its C2 server even after defenders block known ones, which shows up as gibberish domains and high NXDOMAIN rates. A tunnel moves data inside the subdomains, which usually shows up as many unique, long names under one parent domain, though some tunnels rotate parents or pair with a DGA, as Decoy Dog did.
Subscribe to newsletter
Subscribe to receive the latest blog posts to your inbox every week.
.avif)




Related posts
.avif)

For expert judgment, scaled to your world, head for Daylight



