RTFM_ security field notes

Pivoting

Forward ports or route traffic through a pivot with SOCAT, SSH, sshuttle, Chisel, Ligolo-ng and proxychains.

SOCAT

SOCAT is a network Swiss army knife that can perform port forwarding, among other things. For example, the command below creates a socket listening on port 2345 of the compromised machine and redirects the stream to port 22 (SSH) of machine 10.4.184.215.

socat -ddd TCP-LISTEN:2345,fork TCP:10.4.184.215:22

SSH

SSH forwarding requires a working SSH client, a reachable server and an account whose server policy permits forwarding.

Local port forwarding

The following command opens local port 4455 and forwards it to 172.16.184.217:4242 as reached from the SSH server 10.4.184.215.

ssh -N -L 127.0.0.1:4455:172.16.184.217:4242 database_admin@10.4.184.215

Local dynamic port forwarding

Dynamic port forwarding redirects traffic to several ports through a pivot. It works through a SOCKS proxy and the proxychains command.

The following command creates a local SOCKS proxy on port 9999. Only applications configured to use it send their TCP connections through 10.4.50.215.

ssh -N -D 127.0.0.1:9999 database_admin@10.4.50.215

Remote port forwarding

Remote forwarding listens on the SSH server and carries connections back through the SSH client. It forwards a port; it does not itself provide a shell.

ssh -N -R 127.0.0.1:2345:10.4.184.215:5432 user@192.168.45.229

The previous command forwards port 2345 of the attacker machine to port 5432 of IP 10.4.184.215 through the SSH tunnel of the compromised machine.

Remote dynamic port forwarding

As with local port forwarding, dynamic port forwarding is also possible remotely, using the following command:

ssh -N -R 9998 user@192.168.45.229

In the case above, the compromised machine connects to the attacker over SSH and opens a SOCKS proxy on port 9998 of the latter.

Sshuttle

Tools such as sshuttle simplify SSH tunnelling. For example, routes to the 10.5.184.0/24 and 172.16.184.0/24 networks can be created with the following command:

sshuttle -r database_admin@192.168.184.63:2222 10.5.184.0/24 172.16.184.0/24

Chisel

On the attacker side:

chisel server -p 8080 --reverse

On the victim side:

chisel client $ATTACKER_IP:8080 R:socks

Ligolo-ng

Ligolo-ng routes traffic through a TUN interface on the operator’s machine. The agent runs on the pivot and makes connections into its reachable networks; tools use the route directly, without SOCKS or Proxychains. The agent does not normally need administrator rights, but creating the local TUN interface and routes requires elevated privileges.

The example below uses a Linux operator machine, an agent that can reach the proxy on TCP 11601, and an example destination network 192.0.2.0/24. Use matching proxy/agent releases from the upstream releases.

Prepare the proxy

In the operator’s terminal, create an interface owned by the current user, then start the proxy:

sudo ip tuntap add user "$(id -un)" mode tun ligolo
sudo ip link set ligolo up
./proxy -selfcert

In the Ligolo-ng console, display the certificate fingerprint:

certificate_fingerprint

Copy that fingerprint through a trusted channel and use it on the pivot:

./agent -connect <PROXY_ADDRESS>:11601 -accept-fingerprint <SHA256_FINGERPRINT>

This pins the self-signed certificate instead of disabling verification with -ignore-cert. The proxy address must remain reachable outside the tunnel.

Select the agent and route traffic

In the proxy console, select the agent, inspect its interfaces, and start the tunnel on the interface created above:

session
ifconfig
tunnel_start --tun ligolo

In a separate operator terminal, add only the intended destination route:

sudo ip route add 192.0.2.0/24 dev ligolo
ip route get 192.0.2.10
nmap --unprivileged -sT -Pn -n -p 22,80,443 192.0.2.10

Check for overlapping local/VPN routes before adding one. A connected agent does not establish reachability to every network shown by ifconfig. The scan uses TCP connections, skips host discovery and avoids DNS lookups. It needs no proxychains prefix.

Protocol limits and cleanup

Ligolo-ng supports TCP, UDP and ICMP echo, but does not forward arbitrary raw packets. Even a SYN scan is translated into TCP connect() calls on the agent; do not interpret it as raw SYN behavior on the remote network. Upstream recommends Nmap’s --unprivileged or -PE to avoid misleading discovery results.

For this dedicated foreground setup, stop the agent and proxy with Ctrl-C, then remove the route and interface created for it:

sudo ip route del 192.0.2.0/24 dev ligolo
sudo ip link delete ligolo

Only remove these resources if they belong to this tunnel.

Sources reviewed 2026-11-24: Ligolo-ng quickstart and upstream README. Commands were checked against documentation, not executed as a tunnel.

Diagnose a pivot

A connected agent proves the control connection works, not that the intended service is reachable. Check one layer at a time:

  1. Session and tunnel: confirm the selected agent and TUN name; a session attached to another interface can send traffic through the wrong pivot.
  2. Local route: check the route chosen for the exact destination.
  3. Remote reachability: confirm that the pivot can reach that host/port; an interface address is not evidence of reachability to the whole subnet.
  4. Name resolution: compare a direct-IP check with an explicit DNS query.
  5. Application identity: preserve the HTTP hostname, TLS SNI or Kerberos service name even when overriding the destination IP.

On the Linux operator machine:

ip link show ligolo
ip route get 192.0.2.20
ip route show table all
ip rule show

ip route get performs a local lookup; it does not send a packet to the destination. Overlapping VPN networks and policy routing can select another interface. Keep the agent’s connection to the proxy outside routes directed back into its own tunnel.

DNS through a tunnel

Creating a TUN route does not automatically change the system resolver. If the internal DNS server is reachable through the pivot, query it explicitly:

dig -r @192.0.2.53 app.example.org. A +time=2 +tries=1
dig -r @192.0.2.53 app.example.org. A +tcp +time=2 +tries=1

These compare normal DNS transport and TCP. SSH dynamic forwarding supports TCP, so do not assume a SOCKS setup will carry ordinary UDP DNS. Ligolo-ng supports UDP, but the resolver address still needs the correct route. Use HTTP’s --resolve example to preserve a virtual host while testing a known address.

Access a service bound to the Ligolo agent's loopback

The operator’s 127.0.0.1 is not the pivot’s loopback. Ligolo-ng maps addresses in its special 240.0.0.0/4 range to the selected agent’s 127.0.0.1. Route one address rather than the entire range:

sudo ip route add 240.0.0.1/32 dev ligolo
nmap --unprivileged -sT -Pn -n -p 8080 240.0.0.1
# Remove the route when finished
sudo ip route del 240.0.0.1/32 dev ligolo

This is a Ligolo-specific mapping, not a real destination host or a general VPN feature. It refers to the agent selected for that tunnel.

If a connection works but transfers stall, investigate MTU, timeouts and proxy settings before changing them. Ping failure alone does not establish that TCP is unreachable. A connection refusal and a timeout are different observations; see Nmap state interpretation.

Version 4 source: Ligolo-ng agent-local ports, reviewed 2026-11-24. No routes were changed during documentation work.

Proxychains

Proxychains redirects supported applications’ TCP connections through proxies listed in its configuration. Match the SOCKS address and port to the tunnel:

proxychains -q $CMD

SSH can instead use an explicit ProxyCommand. This example assumes an existing SOCKS5 listener on 127.0.0.1:1080; adjust it to match your tunnel:

ssh -o ProxyCommand='ncat --proxy-type socks5 --proxy 127.0.0.1:1080 %h %p' database_admin@10.4.50.215

Warning: When running NMAP through proxychains, a few adjustments are needed:

  • ICMP does not pass through proxychains, so the -Pn option must be set.
  • SYN scans do not work, so forcing the -sT option (CONNECT scan) is worthwhile.
proxychains nmap -sT -Pn -v www.example.com
Provenance and confidence
Version
4
Sources reviewed
2026-11-23
Confidence
medium — V4 on 2026-11-24 adds route/DNS diagnostics and agent-loopback access using Ligolo-ng documentation. V3 setup retained; no tunnel test and legacy examples retain their earlier review limits.

Also searched as: pivot, pivotement, redirection de port, tunnel ssh, ligolo, ligolo-ng, interface tun, rebond