Module 18: Port Redirection and SSH Tunneling
Why Port Redirection and Tunneling?
Most networks aren't flat, or at least shouldn't be. Port Redirection and Tunneling are important because we will likely run into network with segmentation via subnets, firewalls, etc.
Port Forwarding with Linux Tools
A Simple Port Forwarding Scenario
Context for following sections' follow-along labs. Nothing to note.
Setting Up the Lab Environment
More context, at this point we've gained access to a Confluence server and identified an internal subnet with plaintext credentials to a postgres database.
Port Forwarding with Socat
We'll be setting up a listening port on the Confluence server to listen on port 2345 on the WAN interface, forwarding all traffic to port 5432 of the postgres server using socat.
Starting a verbose Socat process (-ddd), listening on TCP port 2345 (TCP-LISTEN:2345), forking into a new subprocess when it receives a connection instead of dying after a single connection (,fork), then forwarding all traffic it receives to TCP port 5432 on the postgres server (TCP:10.4.50.215:5432).
confluence@confluence01:/opt/atlassian/confluence/bin$ socat -ddd TCP-LISTEN:2345,fork TCP:10.4.50.215:5432Connecting through the Confluence server to the postgres server with the credentials found earlier:
kali@kali:~$ psql -h 192.168.50.63 -p 2345 -U postgres
# Now that we're connected, list the databases
postgres=# \l
# Connect to the database
postgres=# \c confluence
# Grab everything from the cwd_user table which contains the username and password hashes for all Confluence users
postgres=# select * from cwd_user;The hashcat mode number for Atlassian (PBKDF2-HMAC-SHA1) hashes is 12001.
SSH Tunneling
SSH Local Port Forwarding
Connected to the internal server, time for a quick scan to see if SMB is listening via lolbins:
Now that we've found a device with SMB open, time to setup local SSH port forwarding to allow us to interact directly with it from our Kali box rather than moving data one device at a time. This will listen on all interfaces via port 4455, forwarding to 172.16.50.217 port 445.
SSH Dynamic Port Forwarding
Setting up a dynamic port forward:
With that listening, we need to be able to communicate via our SOCKS proxy. In this case we'll use Proxychains. Proxychains uses a configuration file for almost everything, stored by default at /etc/proxychains4.conf. Proxies are typically found at the end of the file and can be replaced with a single line defining the proxy type, IP address, and port of the SOCKS proxy we have running on the Confluence server.
With that configured, let's use proxychains to communicate through our SOCKS proxy port:
Additional examples of using proxychains to now port scan that internal network:
SSH Remote Port Forwarding
SSH Remote Dynamic Port Forwarding
Using sshuttle
sshuttle allows us to treat SSH like a VPN by setting up local routes that force traffic through the SSH tunnel. It requires root privileges on the SSH client and Pyton3 on the SSH server.
Port Forwarding with Windows Tools
ssh.exe
If SSH is on Windows and is above version 7.6 we can setup the port forward.
Looking for SSH
Plink
Plink is the command-line-only counterpart to PuTTY. Plink does not have the ability to setup remote dynamic port forwarding.
If we have Plink, we can setup a remote port forward.
Netsh
Using netsh, we can setup a port forward with the portproxy subcontext with the interface context. Netsh requires administrative privileges to created a port forward on Windows.
Last updated