How To Use Nmap To Scan For Open Ports | Blumira (2024)

Traditionally you can protect devices on your local network with a firewall. But how do you know if your firewall is working? Or if it’s even working in the way that you configured it?

Firewalls don’t protect against every attack, and some attackers target firewalls, poking holes to make their attacks easier. This is where scanning comes in.

Scanning with Nmap is an easy way to peek into your network and see exactly what services that server or desktop is making available.

In this article, we’ll walk you through using Nmap to find vulnerabilities in your network.

What Is Nmap?

Nmap is one of the most popular and versatile network scanners for both attackers and defenders. It originally started as just a tool for viewing open TCP and UDP ports, but has grown into the bread and butter network scanner for IT professionals and attackers.

Nmap was first released just on the unix operating system in 1997. In 2000, a version for Windows was added. From there, the open source project was continuously improved on and added to by the security community.

Nmap can now scan pretty much anything if it runs on a network, and even has a built-in scripting language. Nmap scripts, also known as NSE scripts, are like the evolved Pokemon version of Nmap. We won’t quite need them for basic scans, but as your scanning needs evolve, they are great for automating and finding complex or specific vulnerabilities in your environment.

Ports, Explained

Before we go any further, it’s important to discuss a very important component to network scanning: ports!

Ports are essentially the holes that route different kinds of data and web traffic on a network. If an IP address is like the physical address of your house, then ports are the various doors and windows that let things in and out.

Web traffic on the internet in your browser even runs on ports. For example, if you type https://blumira.com into your browser’s URL bar and hit enter, the browser is actually slapping the port right on the end of that URL. This is because HTTPS and many others generally run on what is called a standard port. In this example, your browser is actually requesting https://blumira.com:443. The :443 refers to the HTTPS front door, and tells the traffic where to go once it reaches your house. This is also true with IP Addresses; 8.8.8.8:53 refers to the DNS port on Google’s main DNS server.

The port’s status — open, closed, or filtered — refers to the traffic a port accepts, similar to having security at your front door. Either no one gets in and the port is closed, the port is open and everyone gets in, or it’s filtered and only certain people are let in. Filtering is generally the job of a network or software firewall, and can be done on the network or the device itself.

The services running on those ports are generally one of two types: UDP or TCP. For this article, we will just note the main difference: UDP typically refers to one-way communication (sending a letter) and TCP is two-way communication (using the phone). This matters when scanning because Nmap will generate very different results and options for TCP vs UDP.

Now that we know a bit more about ports, wouldn’t it be great to have a list of them and what they do? Nmap actually keeps a list and regularly updates it. However, port numbers are mostly arbitrary and not specifically tied to a certain service. So, for example, HTTPS may run on port 8443 instead of 443 or HTTP on port 8080. The port number is generally left up to the operating system and software listening on that port. Nmap does its best to try and discover the service as well as the port.

It’s important to understand the difference between a local network and publicly-facing networks. Some services have a very different security and risk context when exposed publicly vs locally.

Here are services and their default ports that would potentially dangerous if exposed to the internet:

  • SSH | Default Port: 22
  • RDP | Default Port: 3389; sometimes 80 and 443 to handle authentication
  • DNS | Default Port: 53
  • SMB | Default Port: 139 (Older version), 445 (Newer TCP-based version)
  • FTP | Default Port: 21
  • HTTP | Default Port: 80 or 8080
  • HTTPS | Default Port: 443 or 8443
  • Web Application Administration | Default Port: 8080, 8443

Here are port ranges to be aware of:

  • 1-1023 are the “well-known” ports we referred to earlier.
  • 1024-49152 are called registered ports. These ports have varying reliability when trying to figure out what service is running on them.
  • 49152–65535 are known as dynamic ports, so they are usually randomized within this range. Bittorrent is one example that uses this range.

You can also use Wikipedia’s list of common port numbers to service mappings as a starting point.

How To Install Nmap

You can install nmap on many different device types, including a laptop, desktop, server or even a Raspberry Pi.

  1. First, go to https://nmap.org/download and follow the instructions to download the latest stable version for your operating system. If you’re wondering why the site looks so outdated, that’s because it is quite old but still going strong to this day. If you are looking for a desktop GUI version, that is called Zenmap and it is pre-selected as an option with the Windows installer.
  2. Confirm Nmap working by launching your preferred command line tool like CMD or Terminal and typing nmap -V to print out the version installed. Alternatively, you can launch Zenmap from your applications folder or program files folder.
  3. If you have issues, or if typing in nmap returns an error that the command is not found, make sure you did not install it in an alternative location. If so, just change directories in the command line to that location and try again.

If you’re running an EDR solution on the same device, it may generate some alerts once Nmap is installed or when you begin scanning. This is because attackers use Nmap as well. You can simply acknowledge the alerts or mark them as resolved. If you’re performing regular scanning from the device or automating the scans, you may want to create a false positive rule just for that device if possible.

Getting Started With Nmap

Now that Nmap is installed, let’s get scanning!

First, fire up your command line or GUI. Typing scanme.nmap.org will perform a default scan for open ports on the domain name scanme.nmap.org. Nmap provides this server to test out different scans.

How To Use Nmap To Scan For Open Ports | Blumira (2)

If you want to scan something else, type in the device’s DNS name or IP address. Later, you can type in a whole subnet that translates to “scan everything in this network range.” You can even scan the device Nmap is installed on from within. For that, type the hostname, localhost, or the IP 127.0.0.1 into Nmap’s command’s line.

Going Beyond Default Scanning

Default scanning is not an ideal way to detect an attacker poking around on your network. The goal is to find and remediate weak spots or vulnerabilities in your network before an attacker finds them. The biggest difference between a normal scan and how most attackers scan is all in the pings.

When we run basic Nmap with no options, Nmap first sends a ping to the device to determine if it’s online before performing time consuming and not-so-stealthy scans. However, most modern firewalls — even built-in desktop ones — have a feature that ignores random pings from other devices. That will shut down any results for a big portion of devices on your network.

Attackers can circumvent this with a technique called syn scanning. Syn scanning bypasses that ping, and just reaches out directly to each port and asks if it’s open. A threat actor sends a syn packet with a request to connect on whatever port they want.

Because of the way TCP protocols work, the device is supposed to respond with a syn/ack packet that tells the scanner whether they can connect. If the device was blocked, or if the port was closed, the targeted host sends an rst/ack packet that basically means ‘go away.’ Once Nmap receives that response, it sends another packet known as a rst, which essentially translates to “I changed my mind about connecting.”

An attacker using syn scanning is similar to a burglar going around a neighborhood and quietly checking every door and window to see who was home and if any of them are open. The ping approach, on the other hand, is like ringing every doorbell and causing a scene.

How To Perform Syn Scans In Nmap

To get the most out of Nmap from a security perspective, it’s crucial to use flags. Think of flags as settings or commands telling Nmap how to work. Flags usually begin with – or –. Nmap has two different flag categories, scan types and options. This is normally formatted like nmap [ -type ] [ -option ] [ target ].

Running certain scans will require administrator privileges, so in Windows it’s best to start by running as admin or in MacOS or Linux using sudo. To perform a basic syn scan, that would be nmap -sS scanme.nmap or sudo nmap -sS scanme.nmap

How To Use Nmap To Scan For Open Ports | Blumira (3)

You can even combine most flags, but scan type flags only allow mixing TCP and UDP types. That would be something like nmap -sS -SU scanme.nmap.org

Let’s say you want to just check if SSH (port 22) is open on your firewall. Add the -p (for port) and give it the port number to check: nmap -sS -p 22 scanme.nmap.org

How To Use Nmap To Scan For Open Ports | Blumira (4)The -Pn flag for scanning a single device is simple and does the majority of what most people need. It basically does a default mode scan, but without performing pings.

How To Scan Like An Attacker

First, identify your network subnets and the device you are scanning from. You need to either be on that network or be able to reach it. If a basic internal network has a device address of 192.168.0.1., you can scan that entire subnet by adding the network subnet and mask as the target mask: -sS 192.168.1.0/24.

To scan multiple subnets, just add them in together: nmap -sS 192.168.1.0/24 10.1.0.0/24

To scan the entire 192.0.0.0 or 10.0.0.0 space, just adjust the subnet mask as needed (for example, /16 pr /8). This will take a bit longer because we are checking every possible address.

If you would like to automate this, it’s important to understand Nmap’s different outputs. The two main outputs are a grepable format with the flag -oG or XML with -oX. Both options will want a filename and path afterwards; for example:

nmap scanme.nmap.org -oG /path/to/file.txt or nmap scanme.nmap.org -oX /path/to/file.xml

However if you leave that out ( nmapscanme.nmap.org-oX ) Nmap will just create a file with the hostname to the directory you are working in. If you’re planning on doing regular scanning you can use the flag –append-output to keep the same file and append results to the end like a log file.

So if we put that all together it might look like this.

nmap -sS -oG --append-output scan.txt 192.168.0.0/16

Don’t forget to add sudo or run as an administrator.

You can also identify host operating systems in Nmap by adding the -O flag. However, this is not 100% accurate and is mostly useful for determining which device that random IP address is associated with. It’s also not ideal for mass scanning, as it will be a bit noisy and add significant time to your scans. You are better off for any concerning open ports and then doing more scans to determine the OS.

Level Up Scanning With NSE Scripts

Once you’ve experimented with syn scanning, you can use NSE scripts to find vulnerabilities within your network. NSE scripts have a few use cases.

If you found a host with open RDP ports, you would want to know if that device is vulnerable to attack on that port. Nmap has plenty of specific vulnerability NSE scripts that can tell you if that device is vulnerable.

A catch-all script called vulners can also be useful. Scanning with that would look like this: nmap –script vulners scanme.nmap.org

This should output any vulnerabilities nmap can scan for and their related CVEs.

Because you can do all of this with a single command line tool, automation becomes fairly easy; run your desired script with something such as Task Manager for Windows, launchd for MacOS and cron for Linux.

This should give you a good baseline as well for what devices on your network are doing. You may be surprised at what you find — especially if you’re not running firewalls on each device.

Happy scanning!

Blumira: Security for IT Teams

Scanning with Nmap, and our free domain security assessment, can provide more visibility into your environment, but for more coverage you’ll need a threat detection and response solution. Blumira is designed for busy IT teams, with fast deployment and an easy-to-use interface that doesn’t require cybersecurity expertise.

Our cloud SIEM with threat detection and response detects and alerts you about suspicious behavior in your environment so that you can stop an incident early enough to prevent damage. Each finding we send is accompanied with a security playbook, giving you clear recommendations on how to remediate an attack. Our support team of security analysts is always available to answer questions on how to interpret a finding, or for other security help.

Our free edition is easy to deploy; IT and security teams can start seeing immediate security value for their organizations.

How To Use Nmap To Scan For Open Ports | Blumira (5)

Tag(s): Security How-To , Blog

How To Use Nmap To Scan For Open Ports | Blumira (2024)

FAQs

How To Use Nmap To Scan For Open Ports | Blumira? ›

First, fire up your command line or GUI. Typing scanme.nmap.org will perform a default scan for open ports on the domain name scanme.nmap.org. Nmap provides this server to test out different scans. If you want to scan something else, type in the device's DNS name or IP address.

How do I scan all 65535 ports in Nmap? ›

To instruct Nmap to scan all 65,535 ports on a target, use the (-p-) option in your command. For example, nmap -p- <target> would initiate a scan of all ports on the specified target, providing a comprehensive overview of all potential entry points for services and applications.

How to check for open ports? ›

Via a third-party website
  1. Go to yougetsignal.com.
  2. Fill in the IP address or hostname into the Remote Address field and the port number into the Port Number field.
  3. Click Check to test the port status.
  4. If the port is open, a message will say Port XXX is open on XXX. XXX. XXX.

What technique does Nmap use to identify open ports on the host? ›

TCP scans represent 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.

Which command should you use to scan for open TCP ports? ›

Use nmap -sT to scan for open TCP ports. Open ports can provide information about which operating system a computer uses and might provide entry points or information about ways to formulate an attack. Use nmap -sU to scan for open UDP ports.

How do I scan only open ports in Nmap? ›

First, fire up your command line or GUI. Typing scanme.nmap.org will perform a default scan for open ports on the domain name scanme.nmap.org. Nmap provides this server to test out different scans. If you want to scan something else, type in the device's DNS name or IP address.

How do I scan top 100 ports? ›

By default, Nmap scans the 1,000 most popular ports of each protocol it is asked to scan. Alternatively, you can specify the -F (fast) option to scan only the 100 most common ports in each protocol or --top-ports to specify an arbitrary number of ports to scan.

How to check if port 443 is open? ›

Check if port 443 is open:

On Windows: open the Command Prompt on your Windows machine > type telnet <IP address or domain name> 443 and press Enter.

Which tools are used to check for open ports? ›

Nmap is the de-facto tool for finding open ports and services due to how effective it is.

Why is Nmap not showing open ports? ›

Nmap cannot determine whether the port is open because packet filtering prevents its probes from reaching the port. The filtering could be from a dedicated firewall device, router rules, or host-based firewall software. These ports frustrate attackers because they provide so little information.

How do hackers scan for open ports? ›

Port Scan FAQs

Hackers use a port checker or port scanner attack to learn the weak points or vulnerabilities in a business's network. When hackers send a message to a port number, the response they receive tells them whether it is open and helps them discover potential weaknesses.

What is the most popular Nmap scan? ›

Nmap Ping Scan

The most famous type of scan is the Nmap ping scan (so-called because it's often used to perform Nmap ping sweeps), and it's the easiest way to detect hosts on any network.

How to identify open ports? ›

If you would like to test ports on your computer, use the Windows command prompt and the CMD command netstat -ano. Windows will show you all currently existing network connections via open ports or open, listening ports that are currently not establishing a connection.

What command checks for open ports? ›

To find open ports on a computer and to check what application is using specified port, use the netstat command line: Open the command prompt (Start > Run > cmd) and use netstat -ano | find /i "<port_number>". It will show you all processes that use the specified port. Notice the PID (process id) in the right column.

How do you scan a machine for open ports? ›

You'll use the netstat program to identify open ports, and then use the nmap program to get information about the state of a machine's ports on a network. When you're done you'll be able to identify common ports and scan your systems for open ports.

What is the Nmap option for all ports? ›

-p0- asks Nmap to scan every possible TCP port, -v asks Nmap to be verbose about it, -A enables aggressive tests such as remote OS detection, service/version detection, and the Nmap Scripting Engine (NSE). Finally, -T4 enables a more aggressive timing policy to speed up the scan.

How to use Nmap to scan a range of ports? ›

Scanning specific port ranges
  1. Port list separated by commas: $ nmap -p80,443 localhost.
  2. Port range denoted with hyphens: $ nmap -p1-100 localhost.
  3. Alias for all ports from 1 to 65535: # nmap -p- localhost.
  4. Specific ports by protocol: # nmap -pT:25,U:53 <target>
  5. Service name: # nmap -p smtp <target>
Jan 27, 2022

How do you specify all ports to be scanned? ›

Ports can also be specified by name according to what the port is referred to in the nmap-services . You can even use the wildcards * and ? with the names. For example, to scan FTP and all ports whose names begin with “http”, use -p ftp,http* . Be careful about shell expansions and quote the argument to -p if unsure.

How do I scan an entire IP range in Nmap? ›

For this, Nmap supports CIDR-style addressing. You can append / <numbits> to an IP address or hostname and Nmap will scan every IP address for which the first <numbits> are the same as for the reference IP or hostname given. For example, 192.168. 10.0/24 would scan the 256 hosts between 192.168.

Top Articles
Lazy Portfolios
BaCloud Datacenter
13 Easy Ways to Get Level 99 in Every Skill on RuneScape (F2P)
Boomerang Media Group: Quality Media Solutions
The Idol - watch tv show streaming online
THE 10 BEST River Retreats for 2024/2025
Music Archives | Hotel Grand Bach - Hotel GrandBach
Cranberry sauce, canned, sweetened, 1 slice (1/2" thick, approx 8 slices per can) - Health Encyclopedia
Craigslist Dog Kennels For Sale
Our Facility
What Is Njvpdi
Jasmine Put A Ring On It Age
Available Training - Acadis® Portal
Price Of Gas At Sam's
Ou Class Nav
Vermont Craigs List
Mflwer
Star Wars: Héros de la Galaxie - le guide des meilleurs personnages en 2024 - Le Blog Allo Paradise
Teacup Yorkie For Sale Up To $400 In South Carolina
Canvasdiscount Black Friday Deals
R&S Auto Lockridge Iowa
Troy Gamefarm Prices
The Creator Showtimes Near R/C Gateway Theater 8
Cpt 90677 Reimbursem*nt 2023
Divina Rapsing
Churchill Downs Racing Entries
Cvs Sport Physicals
Craigslist Boerne Tx
Star News Mugshots
Bratislava | Location, Map, History, Culture, & Facts
Lichen - 1.17.0 - Gemsbok! Antler Windchimes! Shoji Screens!
Devin Mansen Obituary
2024 Ford Bronco Sport for sale - McDonough, GA - craigslist
Wal-Mart 2516 Directory
Kerry Cassidy Portal
Daly City Building Division
2023 Fantasy Football Draft Guide: Rankings, cheat sheets and analysis
How Does The Common App Work? A Guide To The Common App
The Angel Next Door Spoils Me Rotten Gogoanime
Tricia Vacanti Obituary
Gotrax Scooter Error Code E2
Arnesons Webcam
Tacos Diego Hugoton Ks
Paperlessemployee/Dollartree
Minterns German Shepherds
Race Deepwoken
Walmart Listings Near Me
Barber Gym Quantico Hours
San Diego Padres Box Scores
Edt National Board
Estes4Me Payroll
Turning Obsidian into My Perfect Writing App – The Sweet Setup
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 6451

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.