Data Manipulation using Netcat

Devindi Navodya Karandawala
6 min readSep 25, 2022

--

Netcat also known as ‘nc’ is first served in 1995 by Hobbit and it is one of the most popular network security tools which is used for reading or writing from TCP or UDP sockets using any platform. Netcat is a terminal application that is similar to Telnet program but has a lot more features. Also, we can say that netcat is an upgraded version of Telnet program. Apart from that, netcat is the most popular tool for transferring files via TCP sockets and listening for incoming connections. We know netcat as a Swiss army knife because it is packed with lots of features in order to do various tasks in the terminal and network security. In order to be used directly or to be easily controlled by other programs and scripts, NetCat is made to be a dependable “back-end” device.

Netcat can act as a socket server or client and interact with other programs at the same time sending and receiving data through the network. In order to understand what are the usages and advantages of this tool, definitely you have to use it. Some of the main usages are port scanning, banner grabbing, and transferring files can be defined. By these usages, Netcat is known as the Swiss army knife. Banner grabbing is an essential technique that is used to gain information about a computer system like the operating system used in this system, what is the version of the operating system and what are the services running on etc., and its services running on open ports. In order to find the vulnerabilities of a system, we can do port scanning by using this tool. Other than these things, Penetration testers use this tool in order to grab the reverse shells and do various exploitations. As the main advantage, we can find that this tool supports various platforms such as Windows, Linux as well as macOS. Netcat-Traditional, Netcat-OpenBSD, and Ncat are the most popular versions of Ncat-used by Nmap that can be used on these platforms.

In here, I have done some practicals using Netcat tool with the help of the Kali Linux machine.

Command Line to check whether Netcat is already installed: -

Type netcat and hit enter in the terminal.

There are some terms we should know before going on to practical using netcat.

1. Listener: — System on which netcat is listening for commands. (Can be a sever as well.)

2. Client : — System which tries to connect to another system using netcat or give commands.

§ How to use netcat?

· General form of usage is

nc [switches] [hostname] [port]

In order to find options that can be used in netcat simply type,

· nc -h

As I mentioned before, Netcat can do various tasks with lots of features. So, let’s see what can netcat do using Kali Linux machine.

1. To make a Chat server.

Step 01: Make a listener who can listen to client connections. Here I used the same kali machine as the listener and client.

Command: nc -lvnp <listener port number>

Step 02: Make a client. Before making the client, we have to identify the listener’s Ip address and port.

Command: ifconfig

Step 03: type command.

nc < Listener Ip address> <Port>

After entering the above command on the listener’s end you can find that the client connected through the listener’s port.

Step 04: Test that both listener and client can chat at the same time.

1. Create a Web server.

Step 01: In here, we have to make the listener as a web server. I have created a basic HTML login page and hosted it as a web server.

Command: nc -lp 80 -q1 <File name>

Step 02: Type the listener’s IP address in the search bar in the web browser then after the request message will be displayed in the terminal as below.

Step 03: If the client terminates the connection, the listener is also terminating its connection. In order to avoid this, we have to use the command below to keep the server up and running.

You can see this kind of output after running the above commands.

1. File transfer using netcat

Step 01: Create a normal text file and save it in any directory as you wish. In my case, it is in /desktop/netcat/file1.txt

Step 02: After that make listener listens to any client connections. Also, make sure to open a location in order to capture the transferred file by the client end.

Command: nc -lvp 1337 > output

Step 03: On the client side, transfer the relevant file to the server end by typing this command.

Step 04: In order to check the relevant file transferred to the server side, we need to list down all files in the listener’s directory. (Place where the output file has been stored) by looking at this we can see that the output file has a file size of 14KB. Therefore, we can assume that the transferred file’s content has been stored in the output file.

Step 05: As the final step read the content in the output file.

There are some other interesting things that can be done by using Netcat. I have included some popular and simple activities that can perform by using a sever-client connection with netcat with the help of the Kali Linux machine.

Written by Devindi Karandawala — 2nd Year 2nd Semester — Cyber Security Student-SLIIT

--

--