Hacking With Netcat/Step By Step Tools Introduction

Netcat is a great network utility for reading and writing to network connections using the TCP and UPD protocol. Netcat is often referred to as the Swiss army knife in networking tools and we will be using it a lot throughout the different tutorials on Hacking Tutorials. Most common use for Netcat when it comes to hacking is setting up reverse and bind shells, piping and redirecting network traffic, port listening, debugging programs and scripts and banner grabbing. In this tutorial we will be learning how to use the basic features from Netcat such as:

  • Banner grabbing
  • Raw connections
  • Webserver interaction
  • File transfers

We will demonstrate these techniques using a couple virtual machines running Linux and through some visualization.

Banner Grabbing, raw connections and webserver interaction :

Service banners are often used by system administrators for inventory taking of systems and services on the network. The service banners identify the running service and often the version number too. Banner grabbing is a technique to retrieve this information about a particular service on an open port and can be used during a penetration test for performing a vulnerability assessment. When using Netcat for banner grabbing you actually make a raw connection to the specified host on the specified port. When a banner is available, it is printed to the console. Let’s see how this works in practice.

Netcat banner grabbing :

The following command is used the grab a service banner (make a raw connection to a service):

Command
nc [ip address][port]

Let’s try this on the FTP service on Metasploitable 2 which is running on port 21:

Command
nc 192.168.100.100 21 
Netcat

As we can see there is a vsFTPD service running on port 21. Have a look at the service enumeration tutorial if you want to learn more about this subject

Netcat raw connection :

To demonstrate how a raw connection works we will issue some FTP commands after we’re connected to the target host on the FTP service. Let’s see if anonymous access is allowed on this FTP server by issuing the USER and PASS command followed by anonymous.

Netcat raw connection

This example demonstrates how to grab a banner and how to setup and use a raw data connection. In this example we’ve used an FTP service but this also works on other services such as SMTP and HTTP services.

Web server interaction :

Netcat can also be used to interact with webservers by issuing HTTP requests. With the following command we can grab the banner of the web service running on Metasploitable 2:

Command
nc 192.168.100.108 80

And then run this HTTP request:

Command
HEAD / HTTP/1.0
Web server interaction

The webserver responds with the server banner: Apache/2.2.8 (Ubuntu) DAV/2 and the PHP version.

To retrieve the top level page on the webserver we can issue the following command:

Command
nc 192.168.100.108 80

And then run this HTTP request:

Command
GET / HTTP/1.0
Web server interaction

File transfers with Netcat :

In this example we will be using a Netcat connection to transfer a text file. Let’s assume we have remote command execution on the target host and we want to transfer a file from the attack box to the host. First we would need to set up a listener on the target host and connect to it from the attack box. We will be using port 8080 for this purpose and we safe the file to the desktop:

Command
nc -lvp 8080 > /root/Desktop/transfer.txt

On the attack box we connect to port 8080 and send a file name transfer.txt:

Command
nc 192.168.100.107 8080 < /root/Desktop/transfer.txt
File transfers with Netcat

Than we hit control + c and cat the contents of the file on both the attack box and target host.

Netcat Final attack

As we can see here the contents of the files are equal which means it has been transferred from the attack box to the target host.

Lessons learned :

In the first part of the Hacking with Netcat tutorials we have learned how to work with several basic features like raw connections, banner grabbing and file transfers. We have learned how to grab service banners which contain information about the service running on the specific port. We have also learned how to interact with services by using raw connections and Netcat. In the tutorial we have gained anonymous access to a FTP server using a raw data connection and issued some FTP commands. We have also learned how to use Netcat for interaction with a webserver. We are able to retrieve webpages and send HTTP requests. Last but not least, we have learned how to transfer files from one box to another with Netcat.

#bookofnetwork #book_of_network #network_book #hacking #hack #netcat #what_is_netcat #necat_tutorial #netcat_commands #netcat_in_kali_linux #Netcat_banner_grabbing #Netcat_raw_connection #Web_server_interaction #File_transfers_with_Netcat

(New page will open, for Comment)

Not yet commented...