{"id":659,"date":"2022-06-28T20:54:10","date_gmt":"2022-06-28T19:54:10","guid":{"rendered":"http:\/\/vroamam.com\/wordpress\/?p=659"},"modified":"2024-04-07T14:43:52","modified_gmt":"2024-04-07T13:43:52","slug":"nmap-part-3","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/nmap-part-3\/","title":{"rendered":"Nmap &#8211; Host Discovery"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Host Discovery<\/h3>\n\n\n\n<p>You will recall I hope this statement from Part 1<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>In its simplest form it is an advanced IP Scanner, much like the Windows utility of the same name and others you may know such as Angry IP Scanner.<\/p><\/blockquote>\n\n\n\n<p>If you read that you&#8217;d be forgiven for thinking this is the place to start .<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmap &lt;ip address&gt;<\/code><\/pre>\n\n\n\n<p>But if you do this you&#8217;ll send at least one SYN packet to the default port selection on the host you&#8217;ve scanned and as you can see in this image from Wireshark, you could be sending more than one.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3.us-west-2.amazonaws.com\/secure.notion-static.com\/2a9b27d2-62f6-4b28-94b3-6ea35a87b8ed\/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20201220%2Fus-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T181254Z&amp;X-Amz-Expires=86400&amp;X-Amz-Signature=6d3c82ce8d635be3729fbdd239ac8bc222b947c4e9f7689f015f0d45e0ea9cf3&amp;X-Amz-SignedHeaders=host&amp;response-content-disposition=filename%20%3D%22Untitled.png%22\" alt=\"\"\/><figcaption>Wireshark capture showing SYN based port scan<\/figcaption><\/figure>\n\n\n\n<p>On my lab network at home it took 760 seconds to scan a single host, which isn&#8217;t very efficient if you just want to see whats live on your network.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>You need to be specific with Nmap. The Nmap online manual advises that the dafult port range consist of 100 ports [3]<\/p>\n\n\n\n<p>Tell it what <strong>YOU<\/strong> want it to do and what <strong>YOU<\/strong> want it to scan. To do a simple ping based IP scan to see if a host or hosts are up, you have to tell it to ignore the port scanning by explicitly asking it to only do host enumeration.<\/p>\n\n\n\n<p>In the help screen we have this switch<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-sn: Ping Scan - disable port scan<\/code><\/pre>\n\n\n\n<p>So the command we need to run a simple host discovery scan using ICMP ping would be:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmap -sn 192.168.1.1<\/code><\/pre>\n\n\n\n<script id=\"asciicast-65XxDZ4rh4QnnfBx6p1xj3NQP\" src=\"https:\/\/asciinema.org\/a\/65XxDZ4rh4QnnfBx6p1xj3NQP.js\" async=\"\"><\/script>\n\n\n\n<p>You can see the result of this scan in this Wireshark capture.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3.us-west-2.amazonaws.com\/secure.notion-static.com\/124a8a10-3240-49bb-a20d-c36dcfdbbcf2\/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20201220%2Fus-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T181455Z&amp;X-Amz-Expires=86400&amp;X-Amz-Signature=33b973d360622fc913ad0b8b04e278e2288ccea893337fa785fc618648a630af&amp;X-Amz-SignedHeaders=host&amp;response-content-disposition=filename%20%3D%22Untitled.png%22\" alt=\"\"\/><figcaption>Wireshark capture of the previously Nmap scan<\/figcaption><\/figure>\n\n\n\n<p>If you want to scan a number of endpoints you can do so by IP addresses or by hostnames. Using hostnames requires accessible and working DNS.<\/p>\n\n\n\n<p>To list a range of IP addresses you have some choices. You can use the slash CIDR notation, you can list individual addresses separated by spaces, you can list blocks of IP addresses using a hyphen, and separate multiple blocks by space, or you can import a list of targets.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmap -sn 192.168.1.1\/24\nnmap -sn 192.168.1.1 192.168.1.2 192.168.1.3 192.168.1.4\nnmap -sn 192.168.1-10 192.168.1.20-25\nnmap -sn -iL &lt;filename&gt;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">TCP Scans<\/h3>\n\n\n\n<p>Often ICMP ping scans are blocked by firewalls, even windows client firewall blocks ICMP by default now. We need to try something else to try and discover hosts that might be up. Nmap can attempt to connect to hosts using the TCP handshake we discussed in part 1 and I hope you&#8217;ll see why I did that primer post on TCP first.<\/p>\n\n\n\n<p>So to get Nmap to do a TCP connection to our host and tell us if it is accepted and completed we have this switch listed in the help<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SCAN TECHNIQUES:\n  -sS\/sT\/sA\/sW\/sM: TCP SYN\/Connect()\/ACK\/Window\/Maimon scans<\/code><\/pre>\n\n\n\n<p>The obvious choice from this is something along these lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmap -sT 192.168.1.1<\/code><\/pre>\n\n\n\n<p>Remember I said earlier that you have to tell Nmap EXACTLY what you want it to do, well here we told it to go and try to connect to the host at 192.168.1.1 using a full TCP handshake. That is what it will try to do, but it will try to do it using its default setting and on its default ports. We already established that there are 1000 ports by default, so we maybe need to reduce this to a smaller number.<\/p>\n\n\n\n<p>There are as number of options to reduce the number of ports we try to connect to. Lets refer back to the help screen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PORT SPECIFICATION AND SCAN ORDER:\n  -p &lt;port ranges&gt;: Only scan specified ports\n    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9\n  --exclude-ports &lt;port ranges&gt;: Exclude the specified ports from scanning\n  -F: Fast mode - Scan fewer ports than the default scan\n  -r: Scan ports consecutively - don't randomize\n  --top-ports &lt;number&gt;: Scan &lt;number&gt; most common ports\n  --port-ratio &lt;ratio&gt;: Scan ports more common than &lt;ratio&gt;<\/code><\/pre>\n\n\n\n<p>We can choose our own port range using<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> -p &lt;port ranges&gt;: Only scan specified ports<\/code><\/pre>\n\n\n\n<p>We can select &#8220;Fast&#8221; mode which reduce the default number from 1000 to 100<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> -F: Fast mode - Scan fewer ports than the default scan<\/code><\/pre>\n\n\n\n<p>Let&#8217;s have a look at how they look in the terminal.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3.us-west-2.amazonaws.com\/secure.notion-static.com\/405c220a-08b0-4049-8e74-6679dd19cbc2\/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20201220%2Fus-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T181623Z&amp;X-Amz-Expires=86400&amp;X-Amz-Signature=de22aed7e24645dfc04f04f4e8978118a07bef4f8c62f1657473d86264acea85&amp;X-Amz-SignedHeaders=host&amp;response-content-disposition=filename%20%3D%22Untitled.png%22\" alt=\"\"\/><figcaption>Image showing comparison Nmap scans using -F switch<\/figcaption><\/figure>\n\n\n\n<p>In a  simple test here we can see that a fast scan using -F against a single target, with no firewall between the scanning machine and the target machine is almost twice as fast using the smaller number of ports (0.27 seconds vs 1.67 seconds). This is fine if all you are doing is host discovery i.e. you are just looking for hosts that are up and there are no firewalls in between.<\/p>\n\n\n\n<p>If we are looking for machines we could choose to manually select some common ports to connect to, maybe things like Telnet (21), SSH (22), HTTP (80), SMB (139,445), RPC (135) and even RDP (3389)&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3.us-west-2.amazonaws.com\/secure.notion-static.com\/a5303fd1-9ba3-4cdd-b911-7e54ec7544c2\/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20201220%2Fus-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T181924Z&amp;X-Amz-Expires=86400&amp;X-Amz-Signature=19c4ae54de581039c499ca2fda006b133a059653ab4eba8d19cd36b9d0e2cd27&amp;X-Amz-SignedHeaders=host&amp;response-content-disposition=filename%20%3D%22Untitled.png%22\" alt=\"\"\/><figcaption>Image showing Nmap scan command line with selected ports plus the output of the command.<\/figcaption><\/figure>\n\n\n\n<p>The fact that the target responds shows us it is up and answering requests. So we can do the same now on a range to see what answers.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3.us-west-2.amazonaws.com\/secure.notion-static.com\/e9e4c687-db0e-4b77-a45b-cbc8b84ef32d\/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20201220%2Fus-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T182258Z&amp;X-Amz-Expires=86400&amp;X-Amz-Signature=5a96d07174d7edc8b8ab9a9844f66d053e8bc1b4c4c5f6e69337da84de71272e&amp;X-Amz-SignedHeaders=host&amp;response-content-disposition=filename%20%3D%22Untitled.png%22\" alt=\"\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>So we have established that we can discover hosts using ICMP or TCP and that we can reduce the number of ports we scan or attempt to connect to by using the -F switch or by scanning known and common ports explicitly<\/p>\n\n\n\n<p>One final thing before we leave host discovery, we don&#8217;t actually need to make a full TCP connection to establish if a port or ports are open\/available to us. Remember that the handshake is just to make sure we have someone listening and that we aren&#8217;t sending data blindly. Once you have asked if they are listening and they&#8217;ve answered you, you know they are there.<\/p>\n\n\n\n<p>Just as we started the conversation in part 1 we can ask if they are available to talk to us and then change our minds. Do you remember how we did that in the TCP handshake?<\/p>\n\n\n\n<p>We did it by sending a SYN packet, so we can just send a SYN packet, if they answer we can assume they are listening, we then reset the request with an RST packet. Based on the port that the request is on we can make a good guess at the protocol that is in use (there is more we can get but we&#8217;ll do that in another section)<\/p>\n\n\n\n<p>So how do we start a scan using just a SYN packet?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SCAN TECHNIQUES:\n  -**sS**\/sT\/sA\/sW\/sM: TCP **SYN\/**Connect()\/ACK\/Window\/Maimon scans<\/code><\/pre>\n\n\n\n<p>we just simply tell it to by replacing the T with an S<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>nmap -sS -F 192.168.33.10<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/s3.us-west-2.amazonaws.com\/secure.notion-static.com\/b3fbca91-8605-4642-9ed3-e5723e2f43d0\/Untitled.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&amp;X-Amz-Credential=AKIAT73L2G45O3KS52Y5%2F20201220%2Fus-west-2%2Fs3%2Faws4_request&amp;X-Amz-Date=20201220T182418Z&amp;X-Amz-Expires=86400&amp;X-Amz-Signature=c640ccf5c3b666913c429957057e94768d708fa9ed177bae0abdef3da5247dc6&amp;X-Amz-SignedHeaders=host&amp;response-content-disposition=filename%20%3D%22Untitled.png%22\" alt=\"\"\/><figcaption>Image showing the Nmap command line syntax for a SYN only scan plus the result<\/figcaption><\/figure>\n\n\n\n<p>Some people call the SYN scan a Stealth scan. This is what the Nmap online manaual has to say about that:<\/p>\n\n\n\n<p>SYN scan has long been called the stealth scan&nbsp;because it is subtler than TCP connect scan (discussed next), which was the most common scan type before Nmap was released. Despite that moniker, don&#8217;t count on a default SYN scan slipping undetected through sensitive networks. Widely deployed intrusion detection systems and even personal firewalls are quite capable of detecting default SYN scans.<\/p>\n\n\n\n<p>Logs often only contain completed connections, but IPS, IDS and more modern Firewalls will all now see the SYN scan as potentially malicious and so ti is a lot less stealthy<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>So that is simple host discovery using Nmap and both ICMP and TCP<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2>Bibliography<\/h2>\n\n\n\n<p>[3] <a href=\"https:\/\/nmap.org\/book\/man-port-specification.html#:~:text=By%20default%2C%20Nmap%20scans%20the,1%2C000%20ports%20for%20each%20protocol.&amp;text=This%20option%20specifies%20which%20ports,(e.g.%201%2D1023%20\">Nmap Online Manual (Port Specification and Scan Order)<\/a><\/p>\n\n\n\n<p>[4] <a href=\"https:\/\/nmap.org\/book\/synscan.html\">Nmap Online Manual SYN (Stealth) Scan<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Host Discovery<\/p>\n<p>Let&#8217;s look at how we can identify live hosts, our options for the three types of scans we can use and how to limit the ports that are scanned.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[87,2,32,120,108,3],"tags":[65,7,110,100,107],"class_list":["post-659","post","type-post","status-publish","format-standard","hentry","category-ctf","category-cybersec","category-networking","category-nmap-training","category-nmap","category-training","tag-cyber","tag-cyber-security","tag-host-discovery","tag-nmap","tag-scanning","entry"],"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/comments?post=659"}],"version-history":[{"count":9,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/659\/revisions"}],"predecessor-version":[{"id":885,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/659\/revisions\/885"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}