{"id":6890,"date":"2018-12-29T03:01:53","date_gmt":"2018-12-29T03:01:53","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=6890"},"modified":"2018-12-30T04:46:41","modified_gmt":"2018-12-30T04:46:41","slug":"how-to-do-a-port-scan-in-linux-linux-hint","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/29\/how-to-do-a-port-scan-in-linux-linux-hint\/","title":{"rendered":"How to do a Port Scan in Linux \u2013 Linux Hint"},"content":{"rendered":"<p>Port scanning is a process to check open ports of a PC or a Server. Port scanners are often used by gamers and hackers to check for available ports and to fingerprint services. There are two types of ports to scan for in TCP\/IP Internet Protocol, TCP(Transmission Control Protocol) and UDP(User Datagram Protocol). Both TCP and UDP have their own way of scanning. In this article, we\u2019ll look at how to do port scan in Linux environment but first we\u2019ll take a look at how port scanning works. Note that port scanning is illegal in often countries, make sure to check for permissions before scanning your target.<\/p>\n<h3>TCP Scanning<\/h3>\n<p>TCP is stateful protocol because it maintains the state of connections. TCP connection involves a three-way handshaking of Server socket and client-side socket. While a server-socket is listening, the client sends a SYN and then Server responds back with SYN-ACK. Client then, sends ACK to complete the handshake for the connection<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/1-43.png\" alt=\"\" width=\"220\" height=\"155\" \/><\/p>\n<p>To scan for a TCP open port, a scanner sends a SYN packet to the server. If SYN-ACK is sent back, then the port is open. And if server doesn\u2019t complete the handshake and responds with an RST then the port is closed.<\/p>\n<h3>UDP Scanning<\/h3>\n<p>UDP on the other hand, is a stateless protocol and doesn\u2019t maintain the state of connection. It also doesn\u2019t involve three-way handshake.<\/p>\n<p>To scan for a UDP port, a UDP scanner sends a UDP packet to the port. If that port is closed, an ICMP packet is generated and sent back to the origin. If this doesn\u2019t happen, that means port is open.<\/p>\n<p>UDP port scanning is often unreliable because ICMP packets are dropped by firewalls, generating false positives for port scanners.<\/p>\n<h3>Port Scanners<\/h3>\n<p>Now that we\u2019ve looked at how port scanning works, we can move forward to different port scanners and their functionality.<\/p>\n<h3>Nmap<\/h3>\n<p>Nmap is the most versatile and comprehensive port scanner available till now. It can do everything from port scanning to fingerprinting Operating systems and vulnerability scanning. Nmap has both CLI and GUI interfaces, the GUI is called Zenmap. It has a lot of varying options to do quick and effective scans. Here\u2019s how to install Nmap in Linux.<\/p>\n<p>sudo apt-get update<br \/>\nsudo apt-get upgrade -y<br \/>\nsudo apt-get install nmap -y<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/2-39.png\" alt=\"\" width=\"1140\" height=\"641\" \/><\/p>\n<p>Now we\u2019ll use Nmap to scan a server (hackme.org) for open ports and to list services available on those ports, its really easy. Just type nmap and the server address.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/3-38.png\" alt=\"\" width=\"1140\" height=\"641\" \/><\/p>\n<p>To scan for UDP ports, include -sU option with sudo because it requires root privileges.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/4-37.png\" alt=\"\" width=\"1140\" height=\"641\" \/><\/p>\n<p>There are a lot of other options available in Nmap such as:<\/p>\n<p>-p- : Scan for all 65535 ports<br \/>\n-sT : TCP connect scan<br \/>\n-O : Scans for operating system running<br \/>\n-v : Verbose scan<br \/>\n-A : Aggressive scan, scans for everything<br \/>\n-T[1-5] : To set the scanning speed<br \/>\n-Pn : In case the server blocks ping<\/p>\n<h3>Zenmap<\/h3>\n<p>Zenmap is a GUI interface of Nmap for click-kiddies so that you won\u2019t have to remember its commands. To install it, type<\/p>\n<p>sudo apt-get install -y zenmap<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/5-39.png\" alt=\"\" width=\"1140\" height=\"641\" \/><\/p>\n<p>To scan a server, just type its address and select from available scan options.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/6-35.png\" alt=\"\" width=\"1140\" height=\"641\" \/><\/p>\n<h3>Netcat<\/h3>\n<p>Netcat is a raw TCP and UDP port writer which can also be used as a port scanner. It uses connect scan that\u2019s why it is not so fast like Network Mapper. To install it, type<\/p>\n<p>ubuntu@ubuntu:~$ sudo apt install netcat-traditional -y<\/p>\n<p>To check for an open port, write<\/p>\n<p>ubuntu@ubuntu:~$ nc -z -v hackme.org 80<br \/>\n&#8230;snip&#8230;<br \/>\nhackme.org [217.78.1.155] 80 (http) open<\/p>\n<p>To scan for a range of ports, type<\/p>\n<p>ubuntu@ubuntu:~$ nc -z -nv 127.0.0.1 20-80<br \/>\n(UNKNOWN) [127.0.0.1] 80 (http) open<br \/>\n(UNKNOWN) [127.0.0.1] 22 (ssh) open<\/p>\n<h3>Unicornscan<\/h3>\n<p>Unicornscan is a comprehensive and fast port scanner, built for vulnerability researchers. Unlike Network Mapper, it uses its own User-land Distributed TCP\/IP stack. It has a lot of features that Nmap doesn\u2019t, some of them are given,<\/p>\n<ul>\n<li>Asynchronous stateless TCP scanning with all variations of TCP Flags.<\/li>\n<li>Asynchronous stateless TCP banner grabbing<\/li>\n<li>Asynchronous protocol specific UDP Scanning (sending enough of a signature to elicit a response).<\/li>\n<li>Active and Passive remote OS, application, and component identification by analyzing responses.<\/li>\n<li>PCAP file logging and filtering<\/li>\n<li>Relational database output<\/li>\n<li>Custom module support<\/li>\n<li>Customized data-set views<\/li>\n<\/ul>\n<p>To install Unicornscan, type<\/p>\n<p>ubuntu@ubuntu:~$ sudo apt-get install unicornscan -y<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/linuxhint.com\/wp-content\/uploads\/2018\/12\/7-36.png\" alt=\"\" width=\"1140\" height=\"641\" \/><\/p>\n<p>To run a scan, write<\/p>\n<p>ubuntu@ubuntu:~$ sudo us 127.0.0.1<br \/>\nTCP open ftp[ 21] from 127.0.0.1 ttl 128<br \/>\nTCP open smtp[ 25] from 127.0.0.1 ttl 128<br \/>\nTCP open http[ 80] from 127.0.0.1 ttl 128<br \/>\n&#8230;snip&#8230;<\/p>\n<h4>Conclusion<\/h4>\n<p>Ports scanners come in handy whether you are a DevOp, Gamer or a Hacker. There is no real comparison between these scanners, none of them is perfect, each of them has its benefits and drawbacks. It completely depends upon your requirements and how you use them.<\/p>\n<p><a href=\"https:\/\/linuxhint.com\/port_scan_linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Port scanning is a process to check open ports of a PC or a Server. Port scanners are often used by gamers and hackers to check for available ports and to fingerprint services. There are two types of ports to scan for in TCP\/IP Internet Protocol, TCP(Transmission Control Protocol) and UDP(User Datagram Protocol). Both TCP &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/12\/29\/how-to-do-a-port-scan-in-linux-linux-hint\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to do a Port Scan in Linux \u2013 Linux Hint&#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-6890","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\/6890","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=6890"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6890\/revisions"}],"predecessor-version":[{"id":6941,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/6890\/revisions\/6941"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=6890"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=6890"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=6890"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}