Netcat Tool or call it NC

Sarath Pillai's picture

Wikipedia defines netcat as below.

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

if you are into system administration its necessary for you to understand what netcat is and what are the functionalities of netcat.

Netcat can be used as port scanner, a backdoor, a port redirector, a port listener and much more.

Netcat can even be used to port scan a machine!!!! yea thats true.

in the above shown picture i scanned my machine from 20 to 30 ports and it even returned me some information regarding the ports.cool isntit?the options i used are mentioned below:

-V: ofcourse verbose

-w: if the connection is idle for more that that no of seconds then the connection is silently closed.

-z: that nc should just scan for listening daemons, without sending any data to them.

so if nmap is not available you can use netcat to scan ports..(common dont make faces , i know that nmap is much wider and superb tool to do that thing)

Grabb banners with Netcat:

So we're interested in knowing what's running behind port 80 and 21. We can use Netcat to grab port banners in the following way:

after getting connected to port 80 i requested http by doing a get request...it returned me the apache version and hostname.

Chat using Netcat:

Imagine a situation where two friends are having a unix console machine with both having public ip's and both of them do not have any other tool other than netcat. what if they want to chat with each other?

one of them will do the following on the his machine.

[root@myvm1 ~]# nc -l 1230

the above command will open the port 1230 and start to listen on that port. the console is not retured untill crtrl + c because it is continuesly listening on that port for any data.

The other guy will do the below to connect to 1230 port and start chatting.

[root@myvm1 ~]# nc 70.82.34.131 1231

in the above example imagine the public ip of the first friend who opened the port 1230 is 70.82.34.131, you can now start chatting with each other.

Netcat can be used for sending files.

the sender will type the following:

[root@myvm1 ~]# cat file | nc localhost 1234

the file content is redirected through the pipe to the port opened by netcat

the reciever will do the following to get the file:

nc <IP> 12345 > file

 

integrate tar and netcat together, and use this to transmit a directory across a netcat socket:
On one side do the following.

  • tar zcfp - /path/to/directory | nc -w 3 127.0.0.1 1234
 

The tar statement before the pipe tar’s and compresses (using gzip) every file within that directory, before printing its output to
stdout (The screen). It is then caught by the pipe, and piped to nc which in this example, connects to 127.0.0.1 on port 1234
and sends it the data which would normally hit the screen. The –w 3 switch causes nc to allow for a 3 second timeout (In the
event of a temporary disconnection or similar).

On the other side:

 

  • nc -l -p 1234 | tar xvfpz –


This will listen on port 1234 for a connection, and will pass any data received to tar. Using the option ‘v’ we can print out filenames to screen:

Netcat can be used for sending files.

the sender will type the following:

Rate this article: 
Average: 3.2 (11 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.