What it is#
DNS tunneling is a technique that encodes arbitrary data within DNS queries and responses, using the DNS protocol as a covert communication channel. DNS traffic is essential for normal network operation, so firewalls rarely block it and it often receives minimal inspection. This makes DNS an attractive vector for command-and-control (C2) communication and data exfiltration.
The fundamental insight is that a DNS query can carry data in the subdomain labels, and the response can carry data in the answer section. As long as the attacker controls the authoritative name server for a domain, they can exchange arbitrary information with a compromised host that can make DNS queries.
How it works#
A typical DNS tunnel operates as follows:
- The attacker registers a domain (e.g.,
tunnel.example.com) and runs a custom authoritative name server for it. - The compromised client encodes data into the subdomain labels of queries. For example, exfiltrated data might appear as
657866696c.tunnel.example.com, where the subdomain is a hex- or base32-encoded payload. (Base64 is unsuitable here because DNS labels are case-insensitive, and a resolver may fold the case.) - The local recursive resolver, seeing an uncached subdomain, forwards the query up the hierarchy until it reaches the authoritative server controlled by the attacker.
- The attacker's server decodes the query, processes it, and encodes the response in TXT, NULL, CNAME, or other record types in the reply.
- The response traverses back through the resolver to the client, which decodes it.
DNS label length limits (63 bytes per label, 253 bytes total for a name) constrain throughput. DNS tunnels achieve roughly 10 to 50 kbps, slow by modern standards but sufficient for exfiltrating credentials, executing commands, or downloading small payloads.
Domain protection
Detect adversary infrastructure while it is being staged.
Have I Been Squatted helps security teams detect lookalike domains, certificate and DNS changes, and staging infrastructure, investigate the evidence, and coordinate takedowns.
Legitimate and malicious uses#
Not all DNS tunneling is malicious. Some VPN services use DNS tunnels to provide connectivity on captive-portal networks. Some IoT devices use DNS-based communication as a fallback when other protocols are blocked.
Malicious uses are more concerning:
- C2 communication. Malware receives instructions and sends status updates over DNS, making it difficult for network defenders to distinguish from normal traffic
- Data exfiltration. Sensitive data is encoded and sent out query by query, bypassing DLP (Data Loss Prevention) controls that only inspect HTTP/HTTPS
- Bypassing network segmentation. If a compromised host can resolve DNS but has no direct internet access, tunneling provides a path out
Purpose-built tools like dnscat2 (designed for C2) reduce the protocol expertise needed to set up a tunnel. Dual-use tools like iodine (mentioned above as a legitimate VPN mechanism) can be repurposed for exfiltration.
Detection signals#
DNS tunneling produces distinctive patterns that defenders can identify:
- High query volume to a single domain or a small set of domains
- Long, high-entropy subdomain labels. Normal subdomains are short and human-readable. Tunneled data produces strings like
a3f7c2e9b1d4.tunnel.example.com - Unusual record types. Frequent TXT or NULL queries from a single client are uncommon in normal browsing
- Consistent query cadence. Periodic queries at fixed intervals suggest automated C2 polling
- Abnormal response sizes. Responses carrying encoded data are often larger than typical DNS answers
Tunneling detection depends on DNS logging at the recursive resolver. Without query-level visibility, these patterns are invisible. DNS filtering solutions that perform behavioral analysis can sometimes flag tunneling patterns automatically. They then block suspicious domains before much data is exfiltrated.