One Day One GNU/Linux Command (NETCAT)
nc -- TCP/IP Tool to read and write data across network connection
Summary:netcat(nc) is a simple utility which reads and writes data across network connections, using IP, TCP or UDP protocol. It is designed to be a reliable "back-end" tool that can be used directly or easily driven by other programs and scripts. It is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities. We can use netcat with-in local system. But just for better understanding, I use two systems A and B. IP of A is 192.168.1.1 and B is 192.168.1.2. Examples:
(A) $ nc B 21 -- Connect to port 21 on B (B) $ nc -l -p 5000 -- Listen on port 5000 in B. (A) $ nc B 5000 -- Connect to B on port 5000. Whatever typed in A will goto B and vice-versa. (A) $ nc -o dump.txt B 5000 -- Same as above. But all traffic will be dumped in the file in hex format. (B) cat fileB.txt | gzip -9 | nc -l 5000 -- Send the file through port 5000 and on-the-fly compress it. (A) nc B 5000 > fileA.gz -- Receive a file from B and save it in A. (A) $ echo "Hello" | nc -w 1 B 5000 -- Connect to B on port 5000 and pass "Hello" message to it. (B) nc -l -p 5000 -e /bin/bash -- Listen on port 5000. If anyone connected this, provide the bash shell. (Simple way to open a backdoor). (A) $ nc -zv B 10-100 -- Simple TCP port scan on B. Option -z makes the netcat not to wait for any response from B. (A) $ nc -zvu B 10-100 -- Simple UDP port scan on B.
Read: man nc or man netcat