Pivoting
Technique
Pivoting is a technique used to access otherwise unreachable networks by routing traffic through a compromised host. This method allows attackers to move laterally through segmented networks, access resources on internal subnets, and evade network security controls like firewalls.
The pivoting host (sometimes called a "jump box") acts as a bridge between the attacker and target networks, allowing traffic to flow between networks that wouldn't normally be able to communicate directly.
Prerequisites
Access Level: - Command execution on the pivot host - Ability to transfer and run tools on the pivot host - Network connectivity between the attacker, pivot host, and target network
System State: - Pivot host must have access to both the attacker's network and the target network - Appropriate tools must be available or transferable to the pivot host
Pivoting with Ligolo-NG
Ligolo-NG is a powerful, cross-platform tunneling tool designed for secure pivoting during penetration tests.
Single Pivot Setup
On Attack Host:
-
Set up TUN interface:
-
Start the proxy server:
-
Add route to the target subnet:
On Target (Pivot) Host:
- Run the agent to connect back to the attack host:
Back on Attack Host:
-
Select the session:
-
Add port forwards to access services:
-
Start the tunnel:
Double Pivot Setup
For accessing networks beyond the first pivot host:
On Attack Host:
-
Set up TUN interfaces for both pivots:
-
Start the proxy server:
-
Add routes to both target subnets:
First Pivot Host:
- Connect back to attack host:
On Attack Host:
-
Select the session:
-
Add listener for second pivot:
-
Add standard port forwards:
-
Start first tunnel:
Second Pivot Host:
- Connect to first pivot host:
Back on Attack Host:
- Switch to second pivot session
-
Add port forwards for second pivot:
-
Start second tunnel with specific TUN device:
Verify access to both networks:
SSH-Based Pivoting
Proxychains with SSH Dynamic Port Forwarding
-
Create a SOCKS proxy using SSH:
-
Verify proxychains configuration in
/etc/proxychains.confor/etc/proxychains4.conf: -
Use proxychains to route tools through the tunnel:
Note: Proxychains can only perform full TCP connect scans (
-sT) as it doesn't handle partial packets correctly.
SSHuttle (Transparent Proxy)
SSHuttle is a transparent proxy that routes traffic through an SSH connection without requiring proxychains:
This creates iptables rules to transparently redirect all traffic to the specified subnet through the SSH tunnel, allowing direct use of tools:
Other Pivoting Techniques
Metasploit's Routing and Port Forwarding
After getting a Meterpreter session:
# Add route through compromised host
meterpreter > run autoroute -s 192.168.1.0/24
# Or from msfconsole
msf > route add 192.168.1.0/24 <session_id>
# Create a SOCKS proxy
msf > use auxiliary/server/socks_proxy
msf > set SRVPORT 9050
msf > set VERSION 4a
msf > run
Chisel (Cross-Platform TCP/UDP Tunnel)
-
On attack host:
-
On pivot host:
Detection & Mitigation
Detection
- Monitor for unusual outbound connections, especially over non-standard ports
- Look for unexpected listening ports on internal systems
- Detect SSH connections with dynamic port forwarding (-D option)
- Watch for network traffic patterns inconsistent with normal business functions
- Monitor for the presence of tunneling tools (Ligolo, Chisel, etc.)
Mitigation
- Implement proper network segmentation with restrictive ACLs
- Use application-layer inspection to identify tunneled traffic
- Deploy an internal proxy for outbound web traffic
- Monitor and restrict outbound connections to the internet
- Implement jump servers with detailed logging for administrative access
- Use host-based firewalls to restrict unnecessary connections
- Deploy network traffic analysis tools to identify anomalous traffic patterns