Setting up the netcat server
Step 1: Let’s make Netcat listen on an ephemeral port, say port:8000. This can be done by entering the following command in the terminal.
nc -l -p 8000
- -l: The ‘-l’ option stands for listening mode.
- -p: The ‘-p‘ option is meant for specifying the port number to listen to.
Now the server is listening for connection requests on port 8000.
Step 2: Since we have not provided ways to handle HTTP requests, we can only make a TCP connection to this server. We can set this by opening another terminal and entering the below command.
nc -nv 127.0.0.1 8000
- -n: The ‘-n‘ option tells Netcat not to use a DNS server to perform a DNS resolution.
- -v: The ‘-v‘ option stands for verbose. It is used to print
- 127.0.0.1: The first parameter of the command denotes the IPv4 address of the host in which the netcat server is running, which is 127.0.0.1 (localhost), in our case.
- 8000: The second parameter is the port number in which we are going to connect to the server.
You will get a similar output if the connection is successful.
Minimal Web Server Using Netcat
Netcat is a networking utility that can be used to complete various tasks over TCP and UDP. It can be used to send TCP and UDP packets, also it can listen on the ports, specified for UDP and TCP. This utility is well-known for its versatility, as its application ranges from setting up simple chat servers to building your reverse shell. The interesting part about this utility is that it can be used as a web server as HTTP also relies on TCP.
In this article, we will learn how to harness the power of Netcat to spin up a minimal web server in no time.
Contact Us