In these various examples, we expose a Mysql server listening on port 3306 to an other machine’s port 12345
Local Forwarding
In local forwarding, the port receiving the tunnelled connection lives on the same machine as the client initiating the connection.
SSH
For a single machine, listening to 3306 locally, you can use
_local__ __remote________
| client | |server |
| |==tunnel===|>0.0.0.0:22 |
| :12345 | | 127.0.0.1:3306 |
|________| |________________|
ssh -L localhost:12345:localhost:3306 user@server
To access port 3306 of a db_server living in a private network through a bastion machine, use
_local__ __remote_priv_net
| client | |bastion |
| |==tunnel===|>0.0.0.0:22 |
| :12345 | | _____________ |
|________| | |db_server ||
| |>0.0.0.0:3306||
| |_____________||
|_________________|
ssh -L localhost:12345:db_server:3306 user@bastion
Remote forwarding
In remote forwarding, the port receiving the tunnelled connection lives on a different machine as the one initiating the connection.
SSH
To expose a local 3306 on a remote gateway through its port 12345, use
_____local_____ _remote_______
| 127.0.0.1:3306| |gateway |
| client|==tunnel==|>0.0.0.0:22 |
|_______________| |0.0.0.0:12345<|
|______________|
ssh -R 0.0.0.0:12345:localhost:3306 user@gateway
To expose the port 3306 of a db_server living in a private network on a remote gateway through its port 12345, use
__local_priv_net _remote_______
| | |gateway |
| client|==tunnel==|>0.0.0.0:22 |
| _____________ | |0.0.0.0:12345<|
||db_server | | |______________|
||>0.0.0.0:3306| |
||_____________| |
|_________________|
ssh -R 0.0.0.0:12345:db_server:3306 user@gateway
Chisel
_____local_____ _remote_______
| 10.10.10.10 | |target |
| 0.0.0.0:8888<|==tunnel==|client |
| :12345| |127.0.0.1:3306|
|_______________| |______________|
When SSH is not a option, try to sneak a chisel compiled binary on the remote machine to perform the following
on local
./chisel server --port 8888 --reverse
on remote
./chisel client 10.10.10.10:8888 R:12345:127.0.0.1:3306
NB: client and server version should match
Ligolo
To access an entire network once you own one machine, I would recommend ligolo, for routing is fairly easy to set up and, since this is a layer 3 VPN, TCP, UDP and ICMP packets are supported: you can nmap your way into the exposed network!
_____attacker____ _bastion_________ _remote_______
| 10.10.10.10 | |target |==TCP==>| |
| 0.0.0.0:11601<|==tunnel==|agent |==UDP==>| |
| | |192.168.100.1/24 | |192.168.100.2 |
|________________| |_________________|=ICPM==>|______________|
attacker first need to launch ligolo server with…
sudo ./ligolo/proxy -selfcert
…before pairing the compromised bastion machine with
agent.exe -connect 10.10.10.10:11601 -ignore-cert
Attacker’s side, the agent should now appear in ligolo’s interactive shell. You just need to select the agent with session before creating an interface and route with:
ligolo-ng >> ifcreate --name ligolo0
ligolo-ng >> tunnel_start --tun ligolo0
ligolo-ng >> add_route --name ligolo0 --route 192.168.100.1/24
Now, any remote machine from 192.168.100.0/24 should be accessible.