Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Unix (http://www.go4expert.com/articles/unix/)
-   -   What is Netcat and How to use it (http://www.go4expert.com/articles/netcat-t26082/)

lionaneesh 17Jun2011 13:12

What is Netcat and How to use it
 
Netcat (also known as ‘nc’ or ‘Swiss Army knife’) is a networking utility used for reading or writing from TCP and UDP sockets using an easy interface. NetCat is designed as a Dependable ‘back-end’ device that can be used directly or easily driven by other programs and scripts. Netcat is a treat to network administrators, programmers, and pen-testers as it’s a feature rich network debugging and investigation tool.

In 2000, Netcat was voted the second most functional network security tool. Also, in 2003 and 2006 it gained fourth place in the same category.

That’s much of theory there; now let’s move on how to use netcat

Using Netcat



There are many features of Netcat and can be used in many ways, but for this tutorial I'll only focus on some fundamental use.

Opening Netcat:-


To open netcat simply go to your Shell and enter 'nc'

Code:

  lionaneesh@lionaneesh:~$ nc
Output:-

Code:

 

  This is nc from the netcat-openbsd package. An alternative nc is available
  in the netcat-traditional package.
  usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
                [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
                [-x proxy_address[:port]] [hostname] [port[s]]

Now let’s use netcat to make a simple Client-Server Chat system.

To make a similar chat client in C we need to write 60-70 lines of code at least. But with netcat we can do it in just 2 simple commands.

To make a Chat server :-

Code:

  nc -l 12345
What we just are instructed netcat to listen for connections on port '12345' , Now the machine is listening on the specified port for connections.

Connecting to this server:-

Code:

  nc localhost 12345
We instructed netcat to connect to a port '12345' on localhost.

Testing :-

Now that we are ready with the Client and the Server set let’s check how it works.

Client Side :-
Code:

 
  lionaneesh@lionaneesh:~$ nc localhost 12345
  Hello i am the client

Server Side :-

Code:

 
  lionaneesh@lionaneesh:~$ nc -l 12345
  Hello i am the client

Voila ! See what happend our message which we wrote at the client side travelled to the server and was printed o the screen , Isn’t that great!

Using Netcat to transfer files

Netcat can also be used to transfer files , Let’s see how.

Server Side (The receiver) :-

Code:

  lionaneesh@lionaneesh:~$ nc -l 12345 > file
What we did is instructed netcat to listen on port 12345 and redirect all the incoming data to 'file'.

Client Side (The Sender) :-

Code:

  lionaneesh@lionaneesh:~$ cat article | nc localhost 12345
In the above command we used pipes to redirect the output of 'cat article' (which would print the contents of the file named article) to port '12345' of local host.

Testing :-

Now let’s check whether the transfer of files was successful completed.

Server Side :-

Code:

  cat file
Output :-
Code:

  It’s a test
Client Side :-

Code:

  cat Article

Output:-

Code:

It’s a test
Voila! We just transferred a file from our client to out server.

Using Netcat as a port-scanner

This can easily be done using the '-z' flag which instructs netcat not to initiate a connection but just check if the port is open.

Code:

  lionaneesh@lionaneesh:~$ nc -z localhost  80-100
In the above command we instruct netcat to check which ports are open between 80 and 100 on 'localhost' .

Output :-

Code:

  Connection to 127.0.0.1 80 port [tcp/http] succeeded!
The output suggests that port 80 is open on '127.0.0.1'.

That’s all for this tutorial ,
Stay tuned for more.

lionaneesh 18Jun2011 12:19

Re: What is Netcat and How to use it
 
Thanks for accepting my tutorial , hope the users like it!

Kingson 13Jul2011 12:05

Re: What is Netcat and How to use it
 
Net-cat is a utility that is able to write and read data across TCP and UDP network
connections. If you are responsible for network or system security it essential that you
understand the capabilities of Net-cat. Net-cat can be used as port scanner, a backdoor,
a port re-director, a port listener and lots of other cool things too. It's not always the
best tool for the job, but if I was stranded on an island, I'd take Net-cat with me ☺
During this tutorial I'll demonstrate a complete hack, using Net-cat only, just to point
out how versatile it is.

The simplest example of its usage is to create a server-client chat system. Although this is a very primitive way to chat, it shows how net-cat works.

.............................................

Scripting 26Jul2011 14:04

Re: What is Netcat and How to use it
 
You can also use NC with some RAT, you will send the RAT to someone and then he will be listening and you can connect to him through the NC, this is the way i use it for :)

lionaneesh 26Jul2011 17:51

Re: What is Netcat and How to use it
 
Quote:

Originally Posted by Scripting (Post 85425)
You can also use NC with some RAT, you will send the RAT to someone and then he will be listening and you can connect to him through the NC, this is the way i use it for :)

That is a malicious use of Net Cat , Which is not the aim of this tutorial

seosurendra 26Jul2011 18:02

Re: What is Netcat and How to use it
 
Netcat is a networking service for reading from and writing using TCP or UDP.

Creativepromotion 28Jul2011 15:58

Re: What is Netcat and How to use it
 
thanks for sharing such nice information

lionaneesh 2Aug2011 20:57

Re: What is Netcat and How to use it
 
Quote:

Originally Posted by Creativepromotion (Post 85513)
thanks for sharing such nice information

My Pleasure

poornaMoksha 25Sep2011 20:06

Re: What is Netcat and How to use it
 
Good article

lionaneesh 25Sep2011 20:31

Re: What is Netcat and How to use it
 
Quote:

Originally Posted by poornaMoksha (Post 87307)
Good article

Means a Lot COming from YoU! :) Thanks

k3y 12Mar2012 02:27

Re: What is Netcat and How to use it
 
Is NetCat similar to telnet, in the way you can connect through an IP adress/Open Port and do basic file operations? I would greatly appreciate a response. I am trying to find some tools to help monitor networking stoof.


All times are GMT +5.5. The time now is 19:29.