Nmap has cemented its place as one of the most powerful open source security tools over the last 20+ years. Originally created in 1997 to scan networks and discover hosts, Nmap has evolved to become much more.
With its extensive scripting engine, Nmap can now detect vulnerabilities in networks and applications rapidly and efficiently.
According to Nmap‘s official website, they have averaged over 300,000 downloads per month since 2006! Companies across tech, government, finance, healthcare industries are leveraging Nmap.
In this comprehensive guide, we will dive into:
- A brief history of Nmap
- Installation guide
- Useful Nmap vulnerability scanning scripts
- Detecting specific flaws like CSRF, directory traversal etc.
- Scan techniques to avoid detection
- Integrating with other security tools
- Remediation tips
- And more!
By the end, you will be well-versed in conducting vulnerability scans using Nmap scripts to uncover security issues, just like professional pen testers!
A Quick History of Nmap
Nmap was created in 1997 by Gordon Lyon, known popularly as Fyodor. He continues to maintain Nmap to this day.
The initial purpose was to help scan large networks and determine which hosts were up and available. Network administrators found it useful for taking inventory of their assets.
Over time, Nmap gained many more capabilities like:
- Determining open ports and services running on servers
- Operating system detection
- Detecting versions of services like Apache/SSH etc.
- Flexible scanning options like TCP/UDP scans, ping sweeps etc.
With the addition of the Nmap Scripting Engine (NSE) in 2008, Nmap could do much more than just port scanning. NSE allowed the community to write scripts to detect vulnerabilities in networks and apps.
Let‘s discuss the common Nmap scripts and usage in more detail.
Useful Vulnerability Scanning Scripts in Nmap
Nmap ships with hundreds of scripts out of the box in categories like vuln, safe, intrusive etc. located at /usr/share/nmap/scripts.
Some particularly useful ones for vulnerability scanning are:
| Script | Description |
|---|---|
| nmap-vulners | Checks app versions against Vulners database |
| vulscan | Queries multiple databases for vulnerabilities |
| vuln | Finds vulnerabilities based on banner grabbing |
Scanning with Nmap Vulners
Nmap-vulners is one of the most powerful vulnerability scanners. It detects vulnerabilities by comparing app versions retrieved via the -sV flag against the Vulners database which has 140k+ vulnerabilities.
Usage:
nmap -sV --script nmap-vulners <target>
We can also specify port numbers, minimum CVSS score etc:
nmap -sV --script nmap-vulners <target> -p80,443 --script-args mincvss=7.0
This will scan ports 80 and 443, and show vulns with CVSS >= 7.0.
Multi-Database Checks with Vulscan
Vulscan script queries different databases like ExploitDB, OSVDB etc. for known vulnerabilities.
Installation:
git clone https://github.com/scipag/vulscan.git
ln -s `pwd`/vulscan /usr/share/nmap/scripts/vulscan
Usage:
nmap -sV --script vulscan <target>
For quicker scans, use only one database:
--script-args vulscandb=openvas.csv
Discovering Vulnerabilities with Nmap Vuln
The vuln script category checks for vulnerabilities based on banner grabbing. For example:
nmap -sV --script vuln <target>
This will fingerprint the services like Apache, SSH etc. and match banners against known vulnerabilities for those versions.
Table: Comparing the Top 3 Nmap Vulnerability Scanners
| Script | Underlying Database | Pros | Cons |
|---|---|---|---|
| nmap-vulners | Vulners (140k+ vulns) | Comprehensive, frequently updated | Slower scan speed |
| vulscan | Multiple databases | Checks many sources | No unified database |
| vuln | Based on banner grabbing | Quick scan | Limited vulnerability checks |
As you can see, each scanner has its own pros and cons. nmap-vulners is powerful but slower, whereas vuln is quick but limited. We can pick one based on the scan requirements.
Now let‘s look at scanning for specific vulnerabilities and flaws beyond just using the main scripts.
Scanning for Specific Vulnerabilities
Nmap has scripts that check for common vulnerabilities like SQLi, CSRF, directory traversal etc.
For example, to scan for CSRF flaws:
nmap -sV --script http-csrf <target>
To check for the Shellshock bash vulnerability:
nmap --script http-shellshock <target>
And to check for directory traversal issues:
nmap --script http-passwd <target>
There are hundreds of scripts targeted at specific flaws like XSS, DoS, code injection etc.
Checking out Nmap‘s script documentation gives the full list.
Evading Detection When Scanning
Since attackers often use Nmap for malicious scanning, organizations try to detect Nmap scans.
Some ways to avoid detection include:
- Using a proxy chain to distribute scanning from multiple IPs
- Limiting scan rate to slow down traffic
- Fragmenting packets to avoid IDS signatures
- Scanning from cloud networks and regions
- Automating scans during low-traffic periods
Carefully constructed scans during authorized pen tests can minimize detection.
Integrating Nmap into Your Workflows
Nmap can be integrated into security workflows using tools like:
- Metasploit – import Nmap scan data to search for exploits
- Burp Suite – for spidering web apps based on ports/services info
- Nessus – import Nmap results into Nessus for agent-based scans
- SIEMs like Splunk – analyze syslogs to detect Nmap scans
Remediating Flaws Found by Nmap
Simply running Nmap scans is not enough. Once vulnerabilities are discovered via scans, you need to:
- Prioritize remediation based on severity
- Isolate impacted assets if needed
- Patch vulnerable software versions
- Work with vendors if needed to fix bugs
- Harden configurations that are exposed
- Update firewall rules if required
Following these best practices allows you to minimize risk exposure.
The Evolving Vulnerability Scanning Landscape
Nmap has dominated for years as an open source vulnerability scanner. But other commercial scanners like Nessus, Qualys and open source tools like OpenVAS are also popular.
Each tool has evolved adding capabilities like:
- Automated scanning
- User-friendly dashboards
- Integration with ticket systems
- Detailed remediation guidance
Nmap still remains one of the most flexible and extensible scanners especially for tech savvy pen testers.
Conclusion
I hope this guide gives you a good overview of conducting vulnerability scans using Nmap‘s powerful NSE scripting engine.
Nmap can help you uncover flaws like:
- Outdated software versions
- Default/weak configurations
- Missing patches
- Cross-site flaws like CSRF, XSS etc.
Carefully crafted scans during authorized pen tests can reveal vulnerabilities before attackers exploit them.
Use this knowledge to find security gaps proactively. Combine Nmap with good vulnerability management to identify, prioritize and fix flaws in your infrastructure.
Go forth and scan responsibly!