SSH (reverse tunnel)
Secure-SHell (SSH) can be used for pivoting around a network. Particularly, this is achieved with the reverse tunnel (-R
) option provided by SSH.
$ ssh -R <listen_port> <remote_host> [-p <port>]
Given the following setup:
Attacker machine
IP: 1.1.1.1/24
Pivot machine (compromised)
IP: 1.1.1.2/24 and 2.2.2.2.2/24
Target machine
Only accessible from the pivot machine
IP: 2.2.2.3/24
Suppose we want to access the target machine from the attacker machine. However, the target machine is only accessible from the pivot machine on the particular interface (2.2.2.0/24). To bypass this restriction, we can use the following SSH command to convert the pivot machine to a SOCKS5 proxy:
$ ssh -R 8888 1.1.1.2 -N
Now, we can access the target machine (2.2.2.3/24 network) on port 8888 from the attacker machine, as if they are on the same network. We can use proxychains to achieve this:
$ cat /etc/proxychains4.conf
...
socks5 127.0.0.1 8888
# eg. perform nmap scan through the pivot (acting as proxy)
$ proxychains4 -f /etc/proxychains4.conf nmap -sT 2.2.2.3
Note that certain commands or options may not work as expected over the SOCKS proxy, eg.
nmap -sS
. Moreover, additional configurations may be required for DNS resolution to be resolved over the proxy.
Last updated