Installing and using Netcat

Netchat is a utility that allows you to establish a TCP/UDP connection and perform data transfer.

Installation command in Ubuntu / Debian:

sudo aptitude install netcat

Installation command on CentOS:

sudo yum install netcat

On MacOS, Netcat is installed by default.

An example of connecting to some server (like telnet):

nc 80

Running Netcat as a server:

nc -l -p 777

Netcat can be used to transfer a file, for this on the first computer we type:

cat file | nc -l -p 777

And on the second:

nc 777 > file

Or copy the whole disk from one computer:

cat /dev/hdb | nc -l -p 777

On the second:

nc 777 > /dev/hdb

Port scan example:

nc -v -n -z -w 1 1-1000

An example of starting a process as a server:

nc -l -p 777 -e /bin/bash

The key combination Ctrl+C can be used to cancel the execution of a command.

I will describe some startup keys:
-l (binds Netcat to a specific port and listens on it, used in conjunction with specifying the port with keys -p (tcp), -u (udp))
-v (more detailed information output)
-w (connection timeout in seconds)

Leave a comment

Leave a Reply