Local Port Forwarding is where SSH can listen on our local host and forward a service on the remote host to our port:
Dynamic Port Forwarding is where we send packets to remote network via pivot host:
Sometimes we might want to forward local service to the remote port as well and we need Reverse Port Forwarding for this.
Setup
Attack Host(10.10.15.5) → Ubuntu Server(10.129.15.50,172.16.5.129) → Windows Server(172.16.5.19)
In this case, it would be impossible to get a reverse shell from Windows Server to Attack host since Windows server doesn’t know how to route traffic leaving it’s network.
We have make Ubuntu server the pivot host to spawn a reverse shell.
- Create msfvenom payload with receiver set as Ubuntu Server(172.16.5.129)
- Ubuntu port 8080 forwards all reverse packets to attacker’s port 8000.
Create Payload
We will create a payload using msfvenom with receiver set as the pivot host and listening port as 8080:
Transfer Payload to PivotHost
We will now transfer the payload to the pivot host(ubuntu server)
Transfer Payload to Target
Now let’s transfer payload from PivotHost to Target machine(windows).
Python web server on PivotHost:
We will download the payload to the target:
Forwarding
We now have our payload on the Windows host.
Let’s use SSH remote port forwarding to forward connections from the Ubuntu server’s port 8080 to our listener on port 8000.
-R
command asks the Ubuntu server to listen on port 8080 and forward all incoming connection to the attacker’s port 8000.
On metasploit, we now have the connection made once the payload runs:
Below is the summary:
- Create payload for PivotHost-Target
- Transfer the payload to target
- SSH forward traffic to attacker listener port
- Run the payload on the target
- Shell