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

First, SSH to your Kali from target machine

On Kali:

Port Forwarding (Single port to one port)

Using Socat

For linux

Forward your 8083 to 10.39.0.2:443

Using Chisel

Most platforms

Remote static tunnels "port to port":

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

Get meterpreter session, then:

Using Plink.exe

Just like SSH, but Windows only. Part of the Putty toolset.

Dynamic Port Forwarding (Single port to any remote port)

  • setup proxychains with socks5 on 127.0.0.1:1080

    • Or set up socks5 proxy on firefox

    For nmap use -Pn -sT or use tcp scanner in msf

Using Chisel

Using Metasploit

  • Get meterpreter session

  • Auto route (multi/manage/autoroute)

  • Start socks proxy (auxiliary/server/socks4a)

Forward ports using built-in firewall

Using iptables

To set up a port forwarder using iptables run the below commands as root (or with sudo).

Port Forwarding with netcat

Forward traffic using netcat and a named pipe.

Last updated