Always ensure you have explicit permission to access any computer system before using any of the techniques contained in these documents. You accept full responsibility for your actions by applying any knowledge gained here.
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
aptinstallproxychains4# Or from source for latest versiongitclonehttps://github.com/rofl0r/proxychains-ng.gitcdproxychains-ng./configure--prefix=/usr--exec-prefix=/usr--libdir=/usr/lib/x86_64-linux-gnumakesudomakeinstall
Verify installation
whichproxychainsproxychains--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:
# Strict - each proxy must be reachable
# Random - proxies are used randomly
# Dynamic - proxies can be down dynamically
strict_chain
#random_chain
#dynamic_chain
# timeout in ms
tcp_read_time_out 4000
tcp_connect_time_out 5000
# Reduce these for faster connections through slow networks
# tcp_read_time_out 800
# tcp_connect_time_out 800
# ProxyList format
# type ip port [user [pass]]
[ProxyList]
socks5 127.0.0.1 1080
# For SOCKS4 (older, less reliable)
# socks4 127.0.0.1 1080
# Any command prefixed with proxychains will tunnel through the proxy
proxychains nmap -p 80,443 10.10.20.0/24
proxychains ssh -u admin 10.10.20.50
proxychains curl http://10.10.20.30
# TCP-based host discovery with nmap (slow but reliable)
proxychains nmap -sT -Pn -p 22,80,443,445 --open -n 10.10.20.0/24
# Full port scan (extremely slow, not recommended)
proxychains nmap -sT -Pn -p- 10.10.20.50
# Top ports only (faster)
proxychains nmap -sT -Pn --top-ports 100 --open 10.10.20.50
# Specific ports (recommended)
proxychains nmap -sT -Pn -p 22,80,443,445,3306,5432 10.10.20.50
# Start msfconsole and set proxies
msfconsole
msf> setg Proxies SOCKS5:127.0.0.1:1080
# Or use command line
proxychains -q msfconsole -x "setg Proxies SOCKS5:127.0.0.1:1080; use exploit/..."
# Write to writable shares
proxychains smbclient //10.10.20.50/share -N
# smb > put exploit.exe
# smb > quit
# Then execute via lateral movement (PsExec, etc)
# First pivot: Establish SOCKS through first compromised system
ssh -fN -D 1080 user@10.10.10.100
# Second pivot: Establish SOCKS through target accessed via first proxy
proxychains ssh -fN -D 1081 user@10.10.20.50
# Configure /etc/proxychains.conf for second proxy
# [ProxyList]
# socks5 127.0.0.1 1081
# Now enumerate third network
proxychains nmap -sT -Pn --top-ports 20 10.10.30.0/24
#!/bin/bash
# multi_pivot.sh - Manage multiple SSH tunnels and proxychains
declare -A pivots=(
[network1]="user@10.10.10.100:1080"
[network2]="user@10.10.20.50:1081"
)
for net in "${!pivots[@]}"; do
IFS=':' read -r host port <<< "${pivots[$net]}"
echo "[*] Establishing pivot to $net on port $port"
ssh -fN -D $port $host
done
echo "[+] All pivots established. Configure proxychains and use:"
echo " proxychains <command>"
# Single proxy
PROXYCHAINS_SOCKS5=127.0.0.1:1080 proxychains nmap -sT -Pn 10.10.20.50
# Switch proxies without editing config
ssh -fN -D 2000 user@10.10.10.100
PROXYCHAINS_SOCKS5=127.0.0.1:2000 proxychains curl http://10.10.20.30
# In new shell with proxy set
export PROXYCHAINS_SOCKS5=127.0.0.1:1080
proxychains zsh # All commands in this shell use the proxy
# Single proxy
PROXYCHAINS_SOCKS5=127.0.0.1:1080 proxychains nmap -sT -Pn 10.10.20.50
# Switch proxies without editing config
ssh -fN -D 2000 user@10.10.10.100
PROXYCHAINS_SOCKS5=127.0.0.1:2000 proxychains curl http://10.10.20.30
# In new shell with proxy set
export PROXYCHAINS_SOCKS5=127.0.0.1:1080
proxychains zsh # All commands in this shell use the proxy
# Correct
proxychains nmap -sT -Pn 10.10.20.50
# Won't work through SOCKS
proxychains nmap -sS 10.10.20.50 # TCP SYN scan won't work
# DNS may leak or not resolve correctly through SOCKS
# Use IP addresses instead of hostnames when possible
proxychains nmap 10.10.20.50 # Good
proxychains nmap internal.local # May fail
# Force DNS through proxy
# Edit proxychains.conf:
# proxy_dns
# Or use Tor
# Reduce timeouts further if connections keep timing out
tcp_read_time_out 500
tcp_connect_time_out 500
# Or disable timeouts entirely (not recommended)
# Comment out tcp_* lines
# Verify tunnel is open
netstat -tulpn | grep 1080
# Reconnect if needed
ssh -fN -D 1080 user@10.10.10.100 -v # Verbose for debugging
# Check firewall rules on pivot host
proxychains iptables -L -n
# Use minimal nmap options
proxychains nmap -sT -Pn --open 10.10.20.50
# Or use nc for raw port scanning
for port in 80 443 445 22; do
proxychains nc -zv 10.10.20.50 $port
done