Pivoting/Lateral Movement
SSH Tunneling 101
# SSH local port forward to reach an_internal_server_ip:port via server_ip
ssh tunneler@server_ip -p 2222 -L 1234:an_internal_server_ip:80
# Now curl localhost:1234 will fetch an_internal_server_ip:80 which is reachable from server_ip only
# dynamic port forward to create a SOCKS proxy to visit any_internal_server_ip
ssh tunneler@server_ip -p 2222 -D 1080
# next config proxychains socks4a localhost 1080; proxychains curl http://any_internal_server_ip/; which is reachable from server_ip only
# ProxyJump ssh to an_internal_host via ssh server_ip
ssh -J tunneler@server_ip:2222 whistler@an_internal_host # which is only accessible from server_ip
# SSH remote port forward to send traffic back to our local port from a port of server_ip
ssh whistler@server_ip -p 2222 -L 58671:localhost:1234 #
# this will listen on port 58671 of server_ip and tunnel the traffic back to us on loclahost:1234; nc -nlvp 1234 to receive for example
# Chain ProxyJump + dynamic port forward to create a proxy of 2nd_box which is only accessible via 1st_box
ssh -j firstuser@1st_box:2222 seconduser@2nd_box -D 1080
# next config proxychains socks4a localhost 1080; proxychains curl http://any_internal_server_ip/; which is reachable from 2nd_box only
# bypass first time prompt when have non-interactive shell
ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no"SSH reverse tunneling
If you already have an SSH session
If you didn't have an SSH session
Port Forwarding (Single port to one port)
Using Socat
Using Chisel
Remote tunnels "access IP:PORT you couldn't access before":
Local tunnels "listen on the target for something, and send it to us":
Using Metasploit
Using Plink.exe
Dynamic Port Forwarding (Single port to any remote port)
Using Chisel
Using Metasploit
Forward ports using built-in firewall
Using iptables
Port Forwarding with netcat
Last updated