Outils pour utilisateurs

Outils du site


issue144:tutoriel3

Ceci est une ancienne révision du document !


Web: http://netcat.sourceforge.net/ Version: 0.7.1 (2004) Netcat is a utility that uses TCP/IP to read and write data across network connections. It is mainly used for testing TCP and UDP connections, but it is so much more. Some people refer to it as the Swiss army knife of network tools. Netcat is all about network connections, monitoring, testing, and sending data with this admin tool. If - for some reason, you don't have it, install it with: sudo apt install netcat Any system administrator or hacker – we don't judge which way you lean – should have a solid understanding of netcat. Skilled system administrators can do almost all of their work using the built-in tools without having to install additional software, and, indeed, netcat is baked into most distributions.

Looking at the man page for netcat is bleh. Netcat is better understood with examples. Don't go rushing off installing bro pages, netcat is not listed in it yet. The basic syntax for netcat is: netcat [options] host port You can use netcat typed out in full, or simply shortened to nc. As stated before, netcat is a utility that does things via TCP/IP; should you require UDP, you have to specify the -u switch. If you are using ports 1-1024, you will require root privileges, anything else is fine as a normal user. You can add netcat to your scripts and it will work just fine. You can also use netcat to scan a range of ports (this is called port scanning), to test if your firewall setup was successful.

IMPORTANT - When scanning addresses on your internet connection, make sure that your ISP allows this, so that you do not get banned from the network. It is also very handy to check your router ports, consider the following: Here (shown below) I scanned my router, ports 50-60, and discovered that port 53 is open. The reason I knew it would be is because DNS uses port 53. (further reading here: https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers) If it was not - and I had no internet connectivity, this would be why. I used switches -vnz (clumped, I could also have used -v -n -z) as: v - verbose output n - no DNS lookup z - don't send data to the ports w - is just so that the listening times out and does not wait forever.

As you can see, crafting custom scans is very easy in netcat, which in turn, makes crafting your own tools very easy. By adding a u after -vnz = -vnzu, will do the scan via UDP, very handy for servers. Let's not kid about the power of netcat. Hackers can use netcat to make a backup of all your data and have your server send it to them! Hacker is seen in such a negative light, let's call it 'Rogue administrator doing an unauthorized backup'? Hello GDPR? For the sake of completion, let us explore this. On your laptop run the following command: nc -lp 8888 | sudo dd of=/home/backups/image.img.gz then, on your server, run: dd if=/dev/sdc | gzip -c | nc 192.168.8.103 8888

Now, in this example, my server was at 192.168.0.102, and my laptop at 192.168.0.103. (assuming port 8888 is open and because hosted VM's don't have root access and port 80 can't be used, hint-hint, nudge-nudge, wink-wink.) In my backups folder, I now have a 100% copy of my server drive, or your server drive, depending on my inclination. I would not use this to make a backup normally, but in a pinch, this will do. Now we can also do the opposite, a restore. nc -lp 8888 | gunzip -c | sudo dd of=/dev/sdc and cat /home/backups/image.img.gz | nc 192.168.8.102 8888

The -lp switch is very handy; it listens on a specific port. In the old days before Teamviewer and the likes, we used the screen command to mirror a screen and chat to one another. Another way of chatting, server to server, or workstation to workstation, would be via netcat. Just go typing everything before the pipe '|' in the example, on one side, and the address and port on the other, you can have a rudimentary IRC chat. Very handy for talking to an IT person in a large server room, when you are at the monitor. Just like we streamed a whole hard drive from one computer to another, we can stream any file as well. (and play it on VLC ~ hello own Netflix!) Here is a nice tutorial I found: https://linoxide.com/tools/simple-chat-netcat-linux/

So far we have used netcat with IP addresses, you can also use domain names, which make it handy for testing your websites. The syntax is: netcat domain.com port If you have an empty domain, and want to park something there, you can, with netcat. If you spun up your server at digital ocean, or wherever, netcat can display a static webpage for you. Let's make an index page: nano index.html while true; do sudo nc -lp 80 < index.html; done

This keeps serving the page by looping, as if you did not, it would otherwise stop after serving the index page once. There is lots more netcat can do, and many ways a sharp mind can form this versatile tool. Examples include TCP banner grabber, relays, backdoor shell, etc. Hopefully, you now have an idea of the range of netcat's usefulness.

issue144/tutoriel3.1557070876.txt.gz · Dernière modification : 2019/05/05 17:41 de d52fr