SSH Tunneled Exfiltration
When direct HTTP, HTTPS, or DNS egress is blocked but outbound SSH is permitted, an SSH tunnel carries other protocols out of the network. The SSH connection acts as an encrypted wrapper. Your attacker machine receives the tunnelled traffic and forwards it normally. From the target's perspective, the only outbound connection is a standard SSH session.
Direct SCP, SFTP, and rsync transfers are covered in Data Exfiltration over SSH and SCP. This page covers routing non-SSH exfiltration through SSH when that is the only available egress path.
Confirm SSH Egress Is Open
Before setting up a tunnel, verify outbound SSH reaches your attacker machine:
If port 22 is blocked but 443 is open, run sshd on your attacker machine on port 443:
Then connect from the target on that port:
Route HTTP Exfiltration Through a SOCKS Proxy
Set up a dynamic forward from the target to your attacker machine:
Use curl with the SOCKS proxy to push staged data to a receiving server:
Start a receiver on your attacker machine before triggering the transfer:
import http.server
class H(http.server.BaseHTTPRequestHandler):
def do_POST(self):
l = int(self.headers['Content-Length'])
open('received.tar.gz','wb').write(self.rfile.read(l))
self.send_response(200); self.end_headers()
def log_message(self, *a): pass
http.server.HTTPServer(('0.0.0.0', 8080), H).serve_forever()
The data travels encrypted inside SSH to your attacker machine, then the SOCKS proxy forwards the HTTP POST to the receiver. The target's firewall sees only outbound SSH.
Route Exfiltration Through a Local Port Forward
Forward a specific port on the target directly to a listener on your attacker machine:
Transfer directly to the forwarded port:
This is simpler than SOCKS when you have a single known receiving endpoint.
Stage Before Tunnelling
Compress data before sending through the tunnel to reduce transfer time and volume:
Check the size before committing to a tunnel transfer:
See Staging and Compressing Data for Exfiltration for full staging guidance.
Verify Transfer Integrity
Check that the file arrived intact:
Matching hashes confirm no corruption during the tunnelled transfer.
Clean Up
Remove the staging directory and kill the background SSH tunnel after the transfer completes:
References
-
ssh(1) OpenBSD manual pageman.openbsd.org/ssh.1 (opens in new tab)
Full reference for -D dynamic forwarding and -L local port forwarding used to tunnel traffic
Was this helpful?
Your feedback helps improve this page.