{"id":25276,"date":"2020-01-22T18:29:53","date_gmt":"2020-01-22T12:59:53","guid":{"rendered":"https:\/\/www.armourinfosec.com\/?p=25276"},"modified":"2020-01-23T14:07:15","modified_gmt":"2020-01-23T08:37:15","slug":"hacking-with-netcat-a-comprehensive-guide","status":"publish","type":"post","link":"https:\/\/www.armourinfosec.com\/hacking-with-netcat-a-comprehensive-guide\/","title":{"rendered":"Hacking with Netcat : A Comprehensive Guide"},"content":{"rendered":"
Netcat<\/strong> is a featured networking utility tool which reads and writes data across network connections, using the TCP\/IP protocol. Netcat can be used from any directory. Let’s start with the basic option which will show us the help page by the following command.<\/p>\n <\/p>\n One of the most common uses for netcat is as a Port Scanner. It can be used to know which ports are open and running services on a target machine. It can scan a single or multiple or a range of open ports. <\/p>\n <\/p>\n Netcat can be also used for grabbing service banner viz. Service Version, Status etc. To grab the target port banner from netcat, use the following command :<\/p>\n <\/p>\n Here, we will connect a FTP Server with the IP Address 192.168.1.200. To connect to the server at a specific port where a particular service running. In our case, the port is 21 i.e. FTP.<\/p>\n <\/p>\n Netcat can also be used to communication between two users. We need to establish a connection before chatting. For this we will need need two devices. One will play the role of initiator and other will be a listener to start the conversation. Once the connection is established, communication can be done from both ends.<\/p>\n User 1<\/strong> User 2<\/strong> On User<\/strong> 1, we will start a listener on port 4455<\/strong> using options -l<\/strong> for listen, -v<\/strong> verbose mode, -p<\/strong> for port<\/p>\n <\/p>\n On User 2<\/strong>, we will create an initiator by providing IP address of listener followed by the listener port.<\/p>\n <\/p>\n Netcat can also be used to transfer files, both text and binary, from one computer to On the Windows system<\/strong>, we will set up a netcat listener on port 4455<\/strong> and redirect any <\/p>\n On the Linux system<\/strong>, we will push the file to the Windows system through port 4455<\/strong>:<\/p>\n <\/p>\n The connection which will be received by netcat on the Windows system<\/strong> as shown below:<\/p>\n <\/p>\n If we can\u2019t decide our very own port to establish a Netcat connection. Then we can use a special -r<\/strong> parameter which gives us randomize local port.<\/p>\n <\/p>\n Netcat can be used as a simple web server. Actually, web servers are very simple if there are no special configuration requirements. Web servers only send HTML pages over HTTP protocol.<\/p>\n <\/p>\n One of the most useful features of netcat is its ability to do command redirection. Netcat can take an executable file and redirect the input, output, and error messages to a TCP\/UDP port rather than the default console. First, we will start a listener on Windows system<\/strong> for remote connection which will take place from Kali<\/strong>.<\/p>\n <\/p>\n On Kali<\/strong> when we will hit the listener port of Windows<\/strong>, we will get its Command Shell.<\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" Netcat is a featured networking utility tool which reads and writes data across network connections, using the TCP\/IP protocol. It…<\/p>\n","protected":false},"author":1,"featured_media":25343,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92,90],"tags":[],"yoast_head":"\n
\nIt is designed to be a reliable “back-end” tool that can be used directly or easily driven by other programs and scripts. At the same time, 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. It’s so simple, powerful, and useful that many people within the IT community refer to it as the “Swiss Army Knife of Hackers<\/strong>“.<\/p>\nFeatures :<\/strong><\/h5>\n
\n
General Syntax :<\/strong><\/h5>\n
nc [options] host port\r\n<\/pre>\n
Getting start with Netcat :
\n<\/strong><\/h5>\nnc -h\r\n<\/pre>\n
Port Scanning :<\/strong><\/h5>\n
\nWe will use -z<\/strong> option to perform only scan and -v<\/strong> option enables verbose mode options for a port scan like below.<\/p>\nnc -v -z 192.168.1.200 80<\/pre>\n
nc -v -z 192.168.1.200 21-25<\/pre>\n
Banner Grabbing :<\/strong><\/h5>\n
nc -v 192.168.1.200 22<\/pre>\n
Connecting to a Server :<\/strong><\/h5>\n
nc 192.168.1.200 21<\/pre>\n
Command Line Chat Server :
\n<\/strong><\/h5>\n
\nOS<\/strong>: Kali Linux
\nIP Address<\/strong>: 192.168.1.100
\nRole<\/strong>: Listener<\/p>\n
\nOS<\/strong>: CentOS
\nIP Address<\/strong>: 192.168.1.200
\nRole<\/strong>: Initiator<\/p>\nnc -lvp 4455<\/pre>\n
nc -v 192.168.1.100 4455<\/pre>\n
Transferring Files with Netcat :<\/strong><\/h5>\n
\nanother. Here we will create a scenario where we will transfer a file from a Kali system to Windows system.<\/p>\n
\nincoming input into a file called output.txt<\/strong>.<\/p>\nnc.exe -nlvp 4455 > output.txt<\/pre>\n
nc -v 192.168.1.200 4455\u00a0 < demo.txt<\/pre>\n
Randomize Port :<\/strong><\/h5>\n
nc -lv -r<\/pre>\n
Simple Web Server with Netcat :<\/strong><\/h5>\n
while : ; do ( echo -ne \"HTTP\/1.1 200 OK\\r\\n\" ; cat index.html; ) | nc -l -p 8080 ; done<\/pre>\n
Remote Administration with Netcat :<\/strong><\/h5>\n
\nTo further explain this, consider the cmd.exe executable. By redirecting the stdin, stdout, and stderr to the network, we can bind cmd.exe to a local port. Anyone connecting to this port will be presented with a command prompt belonging to this
\ncomputer. To further drive this home, consider the following scenario, involving Windwos<\/strong> and Kali<\/strong>.<\/p>\nnc.exe -nlvp 4455 -e cmd.exe<\/pre>\n
nc -v 192.168.1.200 4455<\/pre>\n