githubEdit

Proxychains

Pivoting using Proxychains

circle-check

Proxychains

Proxychains is a tool that forces TCP/UDP connections made by any program to go through one or more SOCKS proxies. It's essential for red team operations to pivot through compromised systems and access systems on internal networks.

Installation

Linux/Debian-based systems

apt install proxychains4

# Or from source for latest version
git clone https://github.com/rofl0r/proxychains-ng.git
cd proxychains-ng
./configure --prefix=/usr --exec-prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu
make
sudo make install

Verify installation

which proxychains
proxychains --version

Advantages

  • Transparent SOCKS proxying - Works with any TCP application without modification

  • Flexible configuration - Easy to chain multiple proxies

  • Minimal setup - Only requires SSH access to a compromised system

  • Stealthy - Appears as legitimate traffic from the pivot host's perspective

  • No agent required - Doesn't need installation of additional software on target

  • Dynamic SSH tunnels - Can establish tunnels on-the-fly without opening additional ports

  • Supports chaining - Can pivot through multiple systems sequentially

  • Environment variable control - Can specify proxy configuration via environment variables instead of editing files

Disadvantages

  • Slow performance - Proxying adds significant latency and reduces bandwidth

  • Timeout issues - Connections may timeout on slow networks; requires tuning

  • DNS resolution problems - May leak DNS queries or require specific handling

  • Application compatibility - Some applications work poorly through SOCKS proxies

  • Noise and detection - Extensive proxying can generate suspicious traffic patterns

  • UDP limitations - SOCKS5 UDP support varies; SOCKS4 doesn't support UDP at all

  • No encryption over SOCKS layer - Must use encrypted tunnel (SSH) for confidentiality

  • Error handling - Application errors through proxies can be difficult to debug

Basic Proxychains Setup and Usage

Step 1: Establish SSH Dynamic Port Forward

From your attacker machine, create a SOCKS proxy tunnel through an SSH connection:

Parameters:

  • -D: Allocate a SOCKS proxy port

  • -f: Go to background after authentication

  • -N: Don't execute remote command (just forward ports)

Step 2: Configure Proxychains

Edit /etc/proxychains.conf to specify the SOCKS proxy:

Step 3: Using Proxychains

Remote Network Enumeration through Proxychains

Host Discovery

Layer 2 traffic such as arp and ICMP will not traverse a SOCKS proxy, and therefor cannot be used through proxychains.

Port Scanning through Proxychains

Important: Port scanning through proxychains is VERY SLOW. Optimization is critical.

Basic port scan:

Optimized parallel scanning with xargs:

The key to speed is parallelization - scan multiple ports simultaneously:

Service Enumeration

Exploit Delivery through Proxychains

Method 1: Using Metasploit with Proxychains

Configure Metasploit to use SOCKS proxy:

Method 2: Direct Exploit Execution

Execute exploits directly through proxychains:

Method 3: File Upload and Command Execution

Advanced Proxychains Techniques

Multiple Proxy Chains (Double/Triple Pivot)

Chain multiple proxies to traverse multiple network segments:

Bash script for managing multiple proxies:

Dynamic SOCKS Configuration via Environment Variables

Instead of editing config files, specify proxy via environment variable:

Proxychains Configuration

ProxyChains looks for the configuration file in the following order:

  1. SOCKS5 proxy port in environment variable ${PROXYCHAINS_SOCKS5}

  2. File listed in environment variable ${PROXYCHAINS_CONF_FILE}

  3. The -f configfile_name argument provided to the proxychains command

  4. ./proxychains.conf

  5. $(HOME_DIRECTORY)/.proxychains/proxychains.conf

  6. /etc/proxychains.conf

Specify proxy on command line

Using environment variables eliminates the need to edit config files:

Optimization for Speed

Proxychains scanning is inherently slow. These techniques improve performance:

1. Reduce Timeouts

2. Use Quiet Mode

3. Parallel Execution with xargs

4. Limit Port Range

5. TCP Connect Scan (-sT)

Use only TCP connect scans through proxychains. Stealth scans don't work through SOCKS:

Common Issues and Troubleshooting

DNS Resolution Issues

Timeout Errors

Connection Refused

Slow Performance

Best Practices

  1. Use background SSH tunnels: ssh -fN -D port user@host

  2. Set appropriate timeouts: Balance between timeout errors and speed

  3. Scan critical ports only: Focus on likely vulnerabilities

  4. Use parallel execution: Leverage xargs for simultaneous scans

  5. Verify tunnel connectivity: Test tunnel before running scans

  6. Change settings per engagement: Tune timeouts based on network latency

  7. Document all pivots: Track which proxies you've established

  8. Clean up tunnels: Kill SSH processes when done pivoting

  9. Monitor for detection: Excessive proxychains traffic may trigger alerts

  10. Have backup pivots: Establish multiple tunnels for reliability

References

Last updated