Reader small image

You're reading from  Network Scanning Cookbook

Product typeBook
Published inSep 2018
PublisherPackt
ISBN-139781789346480
Edition1st Edition
Right arrow
Author (1)
Sairam Jetty
Sairam Jetty
author image
Sairam Jetty

Sairam Jetty has more than 5 years of hands-on experience in many verticals of penetration testing, compliance, digital forensics, and malware research. He is currently working with Paladion Networks, Abu Dhabi, as a senior analyst and team lead. He has assisted and associated with various financial, telecom, and industrial institutions for testing and securing their applications and environments. Sairam has industry-standard certifications, such as OSCP, Digital Forensic Analyst, Digital Forensic Investigator, and Mobile Security Expert. He also specializes in source code review and mobile application security. He has acquired a great knowledge of SCADA/ICS and nuclear security from his corporate experience and self-learning.
Read more about Sairam Jetty

Right arrow

Port Scanning

In this chapter, we will cover the following recipes:

  • How to specify a target
  • How to perform host discovery
  • How to identify open ports
  • How to manage specification and scan order
  • How to perform script and version scan
  • How to detect operating system
  • How to detect and bypass network protection systems
  • How to use Zenmap

Introduction

In this chapter, we will be going through various recipes that explain how to make use of Nmap to perform various port scanning techniques. Each recipe will contain practical insights into performing Nmap scans on a test virtual machine, allowing you to understand the functionalities of the various switches supported by Nmap.

How to specify a target

The nmap command interprets any content appended without an associated switch as a target. The following is a basic syntax that specifies an IP address or a hostname to scan without any associated switches:

nmap 127.0.0.1 
nmap localhost

The hostname is resolved with the configured DNS server and the IP address is obtained to perform the scan. If multiple IP address are associated with one hostname, the first IP address will be scanned and the result will be displayed. The following syntax allows nmap to perform scans on all the IP addresses resolved with the hostname provided in the command:

nmap xyz.com*

Nmap also supports scanning the whole subnet, provided that you append the mask at the end of an IP address or hostname. Then, Nmap will consider all the resolved IP addresses in the range of the mask mentioned. For example, 10.0.0.1/24 would scan the...

How to perform host discovery

One of the basic techniques of identifying a running host is by sending an ICMP ping packet and analyzing the response to draw a conclusion. What if the host or the network is blocking ICMP packets at the network level or the host level? As per the ICMP technique, the host or the network will not pop up in the live host list. Host discovery is one of the core components of a network penetration test or vulnerability scan. A half-done host discovery can ignore hosts or networks from the scope and perform any further operation, thus leaving the network vulnerable.

Nmap provides various options and techniques to identify the live host by sending customized packets to satisfy specific network conditions. If no such options are provided, Nmap by default sends an ICMP echo to identify the live hosts. The provided probe options can be combined to increase...

How to identify open ports

The following are the six port states that are present in Nmap:

  • open: This means that the port is functioning and has a service running or accessing it. The service can thus accept any connections made as per the protocol and service in use on this port.
  • closed: A closed port is not being accessed by any service, there is no service running on it. Thus, no connections made externally will be successful on these ports.
  • filtered: This status is associated with ports from which no response was received due to the packet filtering mechanism present within the network. This might be caused by an intermediate network protection device.
  • unfiltered: This status is associated with the ports that Nmap was not able to determine whether they were open or closed. Mostly ACK scan labels ports to be in unfiltered state; moreover, scans such as SYN and FIN can help...

How to manage specification and scan order

Nmap provides various options to specify ports to be scanned in a random or sequential order. All the Nmap scans, without any ports specified or any specific NSE script provided as an argument, by default scan only the top 1,000 ports:

  • -p <port ranges>: This option can be used to configure the ports to be scanned in multiple formats. It can be a range or a list. General representation of the syntax would be –p1-65535 if you want to perform a full port scan or –p1, 2, 3, or 4 as a random list that can be non-serial in nature.
  • --exclude-ports <port ranges>: It is a tedious task to prepare a list of ports to be scanned when the requirement is a full port with a few exclusions. In such cases, you can use the exclude ports flag to exclude the ports that are not to be scanned.
  • -F (Fast (limited port) scan): The fast...

How to perform a script and version scan

While performing penetration tests, reconnaissance is really important for informing the next steps of testing. Even though Nmap provides the open ports and the version of the service running on the port, you will need to know the exact version or the name of the service that is running to prepare further exploits or to gain further knowledge of the system.

The Nmap-service-probes database contains specific packet construction techniques to probe specific services and analyze the responses received from them. Nmap provides information about the service protocol, the application name, the version number, the hostname, the device type, and the OS family. It also sometimes determines whether the service is open to connections or if any default logins are available for the service:

  • -sV (version detection): This flag enables Nmap to perform...

How to detect operating system

Nmap uses TCP/IP stack fingerprinting for OS detection.This is done by crafting custom TCP and UDP packets and analyzing their responses. After generating various such probes and comparing the results to the Nmap-os-db database of more than 2,600 known OS fingerprints and provides the OS version. The fingerprint provides details such as the vendor name, OS name, OS generation, device type, and also their Common Platform Enumeration (CPE) representation. Nmap also provides an option for the user to submit the fingerprint obtained if it is not present in the Nmap database of operating signatures:

  • -O (Enable OS detection): This enables OS detection for an Nmap scan. This flag further has options that can be used in conjunction with it.
  • --osscan-limit: This option will reduce the scan time when a list of hosts is being scanned by skipping the hosts...

How to detect and bypass network protection systems

The basic function of Nmap is to generate custom packets and analyze their response once they are sent to the remote hosts. This sometimes is not allowed by network protection systems such as firewalls and intrusion prevention and detection systems. In this recipe, we will discuss some of the methods that can be used to bypass these protections:

  • -f (Fragment packets): Most firewalls perform stateful and stateless packet inspection for which they examine the content of the packets and decide whether to allow the packet or drop it based on its contents. In order to bypass this, Nmap provides an option to fragment the packets so that the network device will not be able to construct the packet to read the correct contents, thereby bypassing the protection.
  • --mtu (Maximum transmission unit specification): This works similar to the...

How to use Zenmap

Zenmap is the graphical interface of Nmap. It is open source and comes in the same installation package as Nmap:

Sometimes, working with command-line tools can be tedious for administrators, thus Zenmap acts as an alternate GUI option.

How do it...

Here are the steps:

  1. Open Zenmap from the list of programs.
  2. Enter the target to be scanned in the text field provided, as shown here:
  1. Select Quick scan from the Profile drop-down list, as shown here:
  1. This will perform a fast scan with the –F option, thereby giving results for the top 100 ports along with a detailed analysis in different tabs, as shown in the following screenshot:

The Ports/Hosts tab shows the various open ports along with the services...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Network Scanning Cookbook
Published in: Sep 2018Publisher: PacktISBN-13: 9781789346480
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Sairam Jetty

Sairam Jetty has more than 5 years of hands-on experience in many verticals of penetration testing, compliance, digital forensics, and malware research. He is currently working with Paladion Networks, Abu Dhabi, as a senior analyst and team lead. He has assisted and associated with various financial, telecom, and industrial institutions for testing and securing their applications and environments. Sairam has industry-standard certifications, such as OSCP, Digital Forensic Analyst, Digital Forensic Investigator, and Mobile Security Expert. He also specializes in source code review and mobile application security. He has acquired a great knowledge of SCADA/ICS and nuclear security from his corporate experience and self-learning.
Read more about Sairam Jetty