Exploitationrelaynetworkingsocketstcpudpsslproxyport-forwarding

socat

Socat is a multipurpose relay for bidirectional data transfer between two byte streams. It supports files, pipes, devices, and sockets including Unix, IPv4, IPv6, raw, UDP, TCP, and SSL.

Description

Socat (SOcket CAT) establishes two bidirectional byte streams and transfers data between them. Data channels may be files, pipes, devices like terminals or modems, or sockets. It provides forking, logging, tracing, different modes for interprocess communication, and many more options.

It can be used as a TCP relay (one-shot or daemon), external socksifier, shell interface to Unix sockets, IPv6 relay, netcat and rinetd replacement, to redirect TCP-oriented programs to a serial line, or to establish a relatively secure environment (su and chroot) for running client or server shell scripts inside network connections. Socat supports SCTP as of version 1.7.0.

The package includes helper tools like filan for analyzing file descriptors, procan for system parameters, and scripts such as socat-broker.sh, socat-chain.sh, and socat-mux.sh for specific relay scenarios.

How It Works

Socat creates two bidirectional byte streams defined by bi-addresses and transfers data between them. It handles various protocols including TCP, UDP, SSL, Unix sockets, IPv4, IPv6, raw sockets, and SCTP. Features like forking, logging, tracing, and options for interprocess communication enable versatile data channeling between files, pipes, devices, and network sockets.

Installation

bash
sudo apt install socat

Flags

-Vprint version and feature information to stdout, and exit
-h|-?print a help text describing command line options and addresses
-hhlike -h, plus a list of all common address option names
-hhhlike -hh, plus a list of all available address option names
-d[ddd]increase verbosity (use up to 4 times; 2 are recommended)
-d0|1|2|3|4set verbosity level (0: Errors; 4 all including Debug)
-Danalyze file descriptors before loop

Examples

Print help text describing command line options and addresses
socat -h
Start a broker on port 1234 where data sent by any client is forwarded to all other clients
/usr/bin/socat-broker.sh TCP4-L:1234
Forward clients connecting to port 1234 to <server>:<port> using SOCKS over TLS
/usr/bin/socat-chain.sh TCP4-L:1234,reuseaddr,fork SOCKS::<server>:<port> OPENSSL:10.2.3.4:12345,cafile=...
Mux connections from port 1234 to 10.2.3.4:12345, forwarding data from target to all clients
/usr/bin/socat-mux.sh TCP4-L:1234,reuseaddr,fork TCP:10.2.3.4:12345
Show help for filan, which analyzes file descriptors of the process
filan -h
Show help for procan, which analyzes system parameters of process
procan -h
General usage to relay between two bidirectional addresses
socat [options] <bi-address> <bi-address>
Updated 2026-04-16kali.org ↗