SSH tunnelling for fun and profit: local vs remote

cytopia/pwncat

Local Port Forwarding

Opens a local port that forwards all traffice headed to that port to the destination

# Alice:8080 -> Bob:22 -> Bob:80
# On Alice
ssh root@bob -f -N -L 8080:localhost:80 # perspective of server, localhost is the SSH server itself, Bob
# Alice:8080 -> Bob:22 -> Charlie:3389
# On Alice
ssh root@bob -f -N -L 8080:charlie:3389 # perspective of server

Remote Port Forwarding

Opens a remote port that forwards all traffic headed to that port to the destination

# Alice:8080 -> Bob:22 -> Bob:80
# On Bob
ssh root@alice -f -N -R 8080:localhost:80 # perspective of initiator, Bob
# Alice:8080 -> Bob:22 -> Charlie:3389
# On Bob
ssh root@alice -f -N -R 8080:charlie:3389 # perspective of initiator, Bob

Using Meterpreter

Use auxiliary/server/socks4a module to set up a proxy which can be used for nmap and other tools. Modify proxychains.conf with the srv-host ip entered into the socks4a module

run autoroute -s <target_network>

Alternatively:

use post/multi/manage/autoroute

Once routes are established, Metasploit modules can access the IP range specified in the routes. Scans and exploits can be directed at machines that would otherwise be unreachable from the outside, via the sessions established. For other applications to access the routes, a little bit more setup is necessary. This involves setting up the Socks4a Metasploit module and using Proxychains in conjunction with the other applications.

msf > use auxiliary/server/socks4a
msf auxiliary(socks4a) > set SRVHOST 127.0.0.1
msf auxiliary(socks4a) > set LPORT 1080
msf auxiliary(socks4a) > exploit -j
echo '[ProxyList]' > proxychains.conf
echo 'socks4 127.0.0.1 1080' >> proxychains.conf
proxychains nmap -T4 -n ...

Want to add the route as a default route? Meaning without proxychains, traffic headed towards the remote network will be routed automatically.