What is Netcat and How to use it

Discussion in 'Unix' started by lionaneesh, Jun 17, 2011.

  1. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    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.
     
  2. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Thanks for accepting my tutorial , hope the users like it!
     
  3. Kingson

    Kingson Banned

    Joined:
    Jul 12, 2011
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    0
    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.

    .............................................
     
  4. Scripting

    Scripting John Hoder

    Joined:
    Jun 29, 2010
    Messages:
    421
    Likes Received:
    57
    Trophy Points:
    0
    Occupation:
    School for life
    Location:
    /root
    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 :)
     
  5. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    That is a malicious use of Net Cat , Which is not the aim of this tutorial
     
    Scripting likes this.
  6. seosurendra

    seosurendra Banned

    Joined:
    Jul 14, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Netcat is a networking service for reading from and writing using TCP or UDP.
     
  7. Creativepromotion

    Creativepromotion New Member

    Joined:
    Dec 11, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    SEO
    Location:
    Mumbai
    Home Page:
    http://www.creativewebpromotion.com/
    thanks for sharing such nice information
     
  8. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    My Pleasure
     
  9. poornaMoksha

    poornaMoksha New Member

    Joined:
    Jan 29, 2011
    Messages:
    150
    Likes Received:
    33
    Trophy Points:
    0
    Occupation:
    Software developer
    Location:
    India
  10. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    Means a Lot COming from YoU! :) Thanks
     
  11. k3y

    k3y New Member

    Joined:
    Mar 9, 2012
    Messages:
    14
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Student
    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.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice