Penetration testing

Netcat Command for Beginners: Connect, Listen, Transfer

Netcat, usually typed as nc, reads and writes data across network connections. It is tiny, it is on most systems, and it teaches how TCP connections work better than most tools. Use it only on your own lab or systems you have written permission to test.

A Chat Between Two Lab Machines

  • On machine A, listen: nc -lvnp 4444
  • On machine B, connect: nc 192.168.56.20 4444 (use A's address)
  • Type on either side; the text appears on the other.

-l listens, -v is verbose, -n skips DNS and -p sets the port. Variants of netcat differ slightly, so check man nc on your system.

Check Ports and Grab Banners

  • nc -zv 192.168.56.20 20-100 checks a range of ports without sending data.
  • nc -v 192.168.56.20 80, then type HEAD / HTTP/1.0 and press Enter twice, shows the web server's response headers.

For serious scanning use Nmap; see Nmap for beginners.

Move a File

  • Receiver: nc -lvnp 4444 > received.txt
  • Sender: nc 192.168.56.20 4444 < file.txt

There is no encryption or authentication here, which is exactly why real work uses SSH or HTTPS.

Command Cheat Sheet

  • nc -lvnp 4444 listens on a port.
  • nc HOST 4444 connects to it.
  • nc -zv HOST 20-100 checks a port range.
  • nc -u -lvnp 5353 listens for UDP.
  • nc HOST 4444 < file.txt sends a file.
  • nc -lvnp 4444 > received.txt receives one.

We ran the listen, connect, port-check and file-transfer commands between two local processes before publishing. This was the OpenBSD variant of netcat; others differ slightly.

Why Testers and Defenders Both Care

Attackers use the same idea to open a shell: a listener on one side and a connection from the compromised machine. Defenders see it as an unexpected outbound connection or listening port. Watch it in a capture with tcpdump or Wireshark, and see what blocks it in firewalls, IDS and IPS explained.

Sources and Further Reading

Want to see attack and detection side by side in a lab? Book free trial classes. Contact us or call +91 86868 92922.

Start Your Cyber Security Career

Talk to a counselor, choose the right course for your goals, and get the fee, syllabus and next batch dates in writing.

Book Free Trial Classes

By submitting, you agree that Hacking Trainer Academy may contact you about courses by phone, WhatsApp or email. See our privacy notice and refund policy.

WhatsApp