Inside Nmap, the world’s most famous port scanner (2024)

This article is a deep dive into how Nmap works, to understand its internal structure, and master its functionality.

Network administrators and penetration testers use port scanning to discover open communication channels on computer systems. For an attacker, this is the first step to get info about the target’s network and identify a potential way in, since services running on an open port could be vulnerable to attacks.

Multiple tools can produce good results, but someport scannersare better for a particular task than others. Our focus is onNmap (Network Mapper), by far the most popular tool for network discovery and port scanning. Some of its features include Host Discovery, Port Scan, Service and OS fingerprinting, and Basic Vulnerability detection. There is also a graphical version known asZenmap, which offers easy access to scanning options and network mapping diagrams.

In this article, we will describe how Nmap can help you to:

  1. Discover live hosts on a network

  2. Scan for open ports

  3. Discover services

  4. Test for vulnerabilities

Port scanning alternatives

Nmap is not the only port scanner available, and other tools in this category are suitable for particular needs. Some of the more popular are:

  • Unicornscanis useful for collecting network and OS information, and it comes with features like asynchronousTCP and UDP scanning, port scanning, and service and OS fingerprinting.

  • Angry IP Scanneris a GUI-based tool for high-speed scanning, allowing users to run ping sweeps of the network. Based on the live IPs detected, it can scan for ports and services, reveal MAC addresses, as well as resolve hostnames.

  • Masscanis widely known as the fastest port scanner. It has both a command line and a graphical interface, and the default transmission rate is 100 packets per second.

  • Onetwopunchis a powerful script that combines the features of unicornscan and Nmap tools for faster and more accurate results. It uses unicornscan to scan all 65535 ports, and then feeds the results to Nmap for service fingerprinting. This way, the user gets a complete list of open ports and the services running on them.

1. Nmap host discovery

By default, Nmap uses requests to identify a live IP. In the older version of the tool, the option for ping sweep was -sP; in the newer version, it is -sn. To discover available hosts, the following packets are sent (as seen in the below screen capture below from Wireshark packet analyzer):

  • ICMP echo request

  • A TCP SYN packet to port 443

  • A TCP ACK packet to port 80

  • An ICMP timestamp request

Inside Nmap, the world’s most famous port scanner (1)

If the target is unknown and large, the recommendation is to identify hosts first. Scanning the ports at this stage would generate too much traffic, take time and resources, and is likely to trigger security alerts.

Below are some methods to identify live IPs:

ARP scanningcan be used to stealthily discover the hosts in the local LAN. Getting an ARP reply means that the hosts exist and since this ARP is needed for routing packets, a firewall won’t interfere in the exchange.

nmap -n -sn -PR --send-eth 192.168.100.1-20

Inside Nmap, the world’s most famous port scanner (2)

Inside Nmap, the world’s most famous port scanner (3)

Above, you can see an ARP request and reply captured by Wireshark.

ICMP scancan also identify live hosts by sending an ICMP Echo request. A live host will send back a reply, signalling its presence on the network.

nmap -sP -PE 192.168.100.1/24

Using the -PP option, Nmap will send ICMP timestamp requests (type 13), expecting ICMP timestamp replies (type 14) in return. If a type 14 ICMP packet is received, then Nmap assumes the host is alive.

nmap -sP -PP172.26.1.4

The -PM option sends ICMP address mask (netmask) requests (type 17), expecting an ICMP address mask reply (type 18) in return. Once again, if a type 18 packet is received, the host is alive.

nmap -sP -PM 172.26.1.4

Keep in mind that ICMP messages may be blocked by some firewalls, so this technique may not always work.

TCP scansrepresent another way to discover hosts, using commands to send out TCP SYN or TCP ACK ping messages:

With a TCP SYN scan, Nmap sends an SYN packet to a given port on the target. If the machine replies with an SYN/ACK or RST packet for the specified port, Nmap knows the host is up. Lack of a response for a certain period leads to marking the host as down.

nmap -sP -PS 21 IP

During aTCP ACKscan,Nmap sends an empty TCP packet with the ACK flag set to port 80. If the host is up, it will answer with an RST packet since the connection doesn’t exist. If the host is down, there will be no response. The port can be defined by the user.

nmap -sP -PA IP

If a list of live IP addresses already exists, host discovery is not necessary and you can move to the next step, finding open ports.

nmap -PnIP

2. Scan for open ports

Nmap identifies the status of ports based on the response it receives for an SYN request.

  • Open Port: Nmap receives “syn-ack” as the probe response

  • Closed Port: Nmap receives an “RST” as the probe response

  • Filtered: Nmap marks the port as open | filtered when it does not receive any response, which could be due to firewall filtering

Inside Nmap, the world’s most famous port scanner (4)

There are multiple techniques you can use for port scanning:

Stealth Scan, also known as SYN scan or half-open scan, is the default and most popular technique. Its stealth comes from not performing a 3-way handshake to complete the connection and the packet exchange is as follows:

  1. The scanner sends an SYN packet.

  2. If the port is open, the machine replies with SYN/ACK;

  3. If the port is closed the machine sends RST;

  4. If no response is received after several retries, the port is marked as filtered.

  5. Once the scanner receives SYN/ACK from the machine, it sends the RST packet and marks it as an open port.

nmap -sTIP

Inside Nmap, the world’s most famous port scanner (5)

The images below show the packet exchange during the scanning procedure, as captured by Wireshark:

  • Packet 526 sends an SYN packet from the source IP to 192.168.100.19 on TCP port 135

  • Packet 545 sends an SYN-ACK packet from IP 192.168.100.19 on TCP port 135

  • Packet 546 sends an RST packet from the source IP to 192.168.100.19 on TCP port 135 to close the connection. The same goes for port 445 and port 80

Inside Nmap, the world’s most famous port scanner (6)

TCP Connectscan completes the 3-way handshake with the target machine and makes for a good alternative to the stealth scan. The process is as follows:

  • The scanner sends an SYN packet.

  • If the port is open, the machine will send SYN/ACK;

  • If the port is closed, the machine will send RST;

  • If no response is received after several retries, the port is marked as filtered.

  • Once the scanner receives SYN/ACK, it sends the ACK packet to complete the connection.

nmap-sT IP

Inside Nmap, the world’s most famous port scanner (7)

For a peek behind the scenes, we have captured the traffic to better understand the packet exchange process. You can see that the connection starts with an SYN packet visible inline 121 and the handshake is complete when the ACK packet is delivered.

Inside Nmap, the world’s most famous port scanner (8)

Unlike the SYN scan, the results from TCP connections are slow and the completion of the connection may create a log entry that could reveal the intrusion attempt; it works when the source IP is whitelisted by firewalls, IDS or IPS security gear.

UDP Scansare slower than the TCP port scan and, because of this, are often ignored by security auditors.

Nmap runs the check by sending a UDP packet to the ports. For most of them, the packet is empty and for the common ports, the packet contains the protocol-related payload.

Getting an “ICMP port unreachable error (type 3, code 3)” message means that the port is closed, lack of response signifies that the port is open or filtered, which makes it slow and inaccurate; if the response contains any data, it means that the port is open.

nmap-sU IP

Inside Nmap, the world’s most famous port scanner (9)

In the traffic capture below, packets 78349 and 78350 contain the UDP response for the probe performed on port 2049. For many of the closed ports, the response is shown as “port unreachable.”

Inside Nmap, the world’s most famous port scanner (10)

3. Discover services

Nmap can identify services by listening to open communication ports for the welcome banner. Many common services (SSH, Telnet, FTP, SMTP) identify themselves this way.

If a banner is not advertised, Nmap sends a probe and waits for a reply. The data received using the service scan (-sV) command is compared to thousands of signatures Nmap keeps in its database file, specifically for service fingerprinting purposes.

nmap -sV IP

Inside Nmap, the world’s most famous port scanner (11)

4. Test for vulnerabilities

Nmap can find vulnerabilities in the network through the Nmap Script Engine (NSE) – a flexible feature activated with the -sC option that allows users to write scripts for task automation.

NSE comes with a rich collection of scripts that can help in the network discovery process, withvulnerability exploitation, and backdoor detection. The database is available at “/usr/share/nmap/scripts/” on Linux and “C:\Program Files (x86)\Nmap\scripts” on Windows.

Inside Nmap, the world’s most famous port scanner (12)

nmap-sC IP

Inside Nmap, the world’s most famous port scanner (13)

Testing for a specific vulnerability on a remote target is possible via the –script command:

nmap --script=<nse script> -p <port> IP

You can use this command to check for anonymous login permission on an FTP server:

nmap --script= ftp-anon.nse -p21 192.168.226.130

Inside Nmap, the world’s most famous port scanner (14)

The cache of NSE scripts offers the possibility to check for specific vulnerabilities that have already been reported. For instance, there is a script that checks for a backdoor in the VSFTPD server:

nmap --script= ftp-anon.nse-p 21 192.168.226.130

Inside Nmap, the world’s most famous port scanner (15)

Learn how to use Nmap to discover open communication channels

Nmap is a powerful tool for penetration testers and network administrators alike. Each new release extends its capabilities way beyond the simple port scanner the project started as. It is a mature tool that can also identify critical vulnerabilities and perform some web application-level testing.

See the Nmap official website for detailed information on all the commands and features.

Inside Nmap, the world’s most famous port scanner (2024)

FAQs

Inside Nmap, the world’s most famous port scanner? ›

This article is a deep dive into how Nmap works, to understand its internal structure, and master its functionality. Network administrators and penetration testers use port scanning to discover open communication channels on computer systems.

What is the most common port scan in Nmap? ›

By default, Nmap scans the most common 1,000 ports for each protocol. This option specifies which ports you want to scan and overrides the default. Individual port numbers are OK, as are ranges separated by a hyphen (e.g. 1-1023 ).

What is the better port scanner than Nmap? ›

Masscan is the fastest network port scanner. It can scan the whole internet under 6 minutes with 25 millions per second data transmitting speed.

Is port scanning illegal? ›

Fundamentally, it is not a crime to conduct a port scan in the United States or the European Union. This means that it isn't criminalized at the state, federal, or local levels. However, the issue of consent can still cause legal problems for unauthorized port scans and vulnerability scans.

What is the fastest port scan? ›

Masscan is widely known as the fastest port scanner. It has both a command line and a graphical interface, and the default transmission rate is 100 packets per second.

What is the best port scanner for Linux? ›

Nmap (network mapper) is the world's leading network security scanning tool for Linux systems. It helps identify open ports and prevents potential network security threats. Nmap is an essential network scanning tool due to its accurate, simple-to-use, and flexible interface with many advanced features.

What is the most common scanner? ›

Flatbed scanners are the most common type of scanner. They are called "flatbed" because the document is placed on a flat surface for scanning. Flatbed scanners can scan documents of various sizes and are generally more versatile than sheetfed scanners.

What is a unicorn scan? ›

The unicornscan port scanner, an attempt at a User-land Distributed TCP/IP stack, is designed to provide users with a better interface for initiating stimuli in and then measuring responses from TCP/IP enabled networks or devices. Unicornscan is most often used by network and system administrators and programmers.

Do real hackers use Nmap? ›

Inexperienced hackers will often use the default settings of Nmap and end up getting their IP blocked by the target IDS or their packets dropped by the network firewall. An experienced hacker will be patient and probe the target using different MAC/IP addresses to gain information about the targets system.

What is the stealthiest Nmap scan? ›

SYN scan is the default and most popular scan option for good reason. It can be performed quickly, scanning thousands of ports per second on a fast network not hampered by intrusive firewalls. SYN scan is relatively unobtrusive and stealthy, since it never completes TCP connections.

What is the quickest Nmap scan? ›

If you need to perform a scan quickly, you can use the -F flag. The -F flag will list ports on the nmap-services files. Because the -F "Fast Scan" flag does not scan as many ports, it isn't as thorough. Note: Learn about other methods you can use to check for open ports in Linux.

Is Wireshark better than Nmap? ›

Choosing between Nmap vs Wireshark is like deploying a scout or a spy. Nmap is for scouting and knowing the landscape, while Wireshark is for stealthily collecting what could be interesting data and bringing them back to camp for analysis.

Which is the famous tool for port scanning? ›

Nmap is one of the most popular open-source port scanning tools available. Nmap provides a number of different port scanning techniques for different scenarios.

Is there anything better than Nmap? ›

Angry IP Scan

An angry IP scanner is the best alternative for Nmap for the port scan tool. It is mainly used for the fast scanning speed of port and IP address scanners, as it has a multi-thread process that separates each scan. Moreover, it is free and supports operating systems Linux, Windows, Mac, etc.

What is the default port scan type in Nmap? ›

By default, Nmap performs a SYN Scan, though it substitutes a connect scan if the user does not have proper privileges to send raw packets (requires root access on Unix).

Which of the following is a popular port scanner? ›

Port Scanning Techniques. Nmap is one of the most popular open-source port scanning tools available.

What is the basic of port scanning? ›

A port scan is a common technique hackers use to discover open doors or weak points in a network. A port scan attack helps cyber criminals find open ports and figure out whether they are receiving or sending data. It can also reveal whether active security devices like firewalls are being used by an organization.

Which computer ports are most often scanned by hackers? ›

Ports most targeted by attackers include ports 443 and 8080 (HTTP and HTTPS) No port is 100% secure and what determines the risk of a port is the way it is managed. To protect open ports, it is essential to use ports that encrypt traffic in order to make it difficult for hackers to access sensitive information.

Top Articles
How to Scrape Data From A Website (Is It Legal?) | Airbyte
How much are Chase Ultimate Rewards points worth? - The Points Guy
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Selly Medaline
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 6605

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.