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.

In Windows see %systemdrive%\Windows\System32\OpenSSH (where ssh)

Allows a local client port to be mapped to another port on a certain target reachable by the server.

ssh -N -L [<C_IP>:]<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.

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.

NO proxychains, but root on the SSH client and Python3 on the SSH server.

On Windows before OpenSSH, PuTTYarrow-up-right and its command-line-only counterpart Plinkarrow-up-right were used. Plink has much of the functionality offered by ssh.

Tunneling

Proxy on Attacker machine. Agent on Victim machine.

Connect the victim to the server

chevron-rightLigolo-ng < v0.6hashtag

Create a tun interface on the Proxy Server (C2)

Connect the victim to the server and select the session

Setup routing

chevron-rightLigolo-ng >= v0.6hashtag

Create a tun interface on the Proxy Server (C2)

Connect the victim to the server and select the session

Start the tunneling

Setup routing

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

On Target

<REMOTE>:

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)

On Target (Client)

Download compiled from HEREarrow-up-right

Or with Windows PowerShell Scriptarrow-up-right

Once connected, from Attacker

Communication channel encapsulated in ICMP packets. Requires administrator privileges.

Installation

On Target (Server)

On Attacker (Client)

Allows tunnelling and pivoting between Windows systems via RDP. Requires administrator privileges.

On Attacker (Client), with System PowerShell

Download Proxifierarrow-up-right, portable version (like proxychains but for windows).

Set new proxy server socks5 to 127.0.0.1:1080

On Target1, with System PowerShell

On Attacker

Warning

  • With proxychains only full TCP connect scan (nmap -sT)

  • Windows Defender blocks ICMP, traditional ping (nmap -Pn)

Last updated