05. sshuttle
This tool is quite different from the others covered so far. It doesn't do a port forward, and the proxy it creates is nothing like the ones we've already seen. Instead it uses an SSH connection to build a tunnelled proxy that acts like a new interface. In short, it simulates a VPN, letting us route our traffic through the proxy without proxychains (or an equivalent). We can connect directly to devices in the target network as we would to any networked device. Because the tunnel runs through SSH, anything sent through it is also encrypted, which is a nice bonus. We use sshuttle entirely on our attacking machine, much like we'd SSH into a remote server.
As good as that sounds, it isn't without drawbacks. sshuttle only works on Linux targets. It also needs SSH access to the compromised server, and Python installed on it, although with SSH access it could in theory be possible to upload a static copy of Python and work with that. These restrictions limit its uses somewhat, but when it is an option it tends to be a superb bet.
First we need to install sshuttle. On Kali that's just the apt package manager:
sudo apt install sshuttle
The base command for connecting to a server with sshuttle is:
sshuttle -r username@address subnet
For our fictional 172.16.0.x network with a compromised server at 172.16.0.5, that might look like:
sshuttle -r user@172.16.0.5 172.16.0.0/24
We'd then be asked for the user's password, and the proxy would be established. The tool then sits passively in the background and forwards relevant traffic into the target network.
Rather than specifying subnets, we can use the -N option, which tries to work them out automatically from the compromised server's own routing table:
sshuttle -r username@address -N
Bear in mind this isn't always successful.
As with the previous tools, these commands can be backgrounded by appending the ampersand (&).
If it worked, you should see the line:
c : Connected to server.
So what if we don't have the user's password, or the server only accepts key-based authentication? Unfortunately sshuttle doesn't currently seem to have a shorthand for specifying a private key. We can get around that with the --ssh-cmd switch.
This switch sets the command sshuttle runs when authenticating to the compromised server. By default that's just ssh with no arguments. With --ssh-cmd we can pick a different command, say ssh -i keyfile.
So, with key-based authentication, the final command looks like:
sshuttle -r user@address --ssh-cmd "ssh -i KEYFILE" SUBNET
Using the example from before:
sshuttle -r user@172.16.0.5 --ssh-cmd "ssh -i private_key" 172.16.0.0/24
Please Note: With sshuttle you may hit an error like this:
client: Connected. client_loop: send disconnect: Broken pipe client: fatal: server died with error code 255
This can happen when the compromised machine you're connecting to is part of the subnet you're trying to reach. For instance, connecting to 172.16.0.5 while forwarding 172.16.0.0/24 includes the compromised server inside the newly forwarded subnet, disrupting the connection and killing the tool.
To get around it, tell sshuttle to exclude the compromised server from the subnet range with the -x switch. Using our earlier example:
sshuttle -r user@172.16.0.5 172.16.0.0/24 -x 172.16.0.5
This lets sshuttle create a connection without disrupting itself.