LLI Wiki — My Digital Knowledge Base

nmap cheat sheet for network diagnostics

nmap commands to check ports, services, versions and SQL Server instances on hosts you administer.

This cheat sheet covers scanning hosts you administer or are authorised to test; it collects a few nmap commands for checking ports, services and SQL Server instances on your own network.

Data location

Nmap keeps its scripts and data files in these folders:

System Path
Windows C:\Program Files\Nmap\
Non-Windows /usr/local/share/nmap/ or /usr/share/nmap/

Service and OS detection on a subnet

Scan a list of common web and administration ports on a whole /24 with -A (OS detection, version detection, script scanning and traceroute):

nmap -A -p 80,8000,8080,443,8443,7443,7070,7000,22,23,21 192.0.2.10/24

Check that a port is open

Basic TCP connect scan of a single port (here the default SQL Server port 1433 as an example):

nmap -sT 192.0.2.11 -p 1433
sudo nmap -p 1433 192.0.2.11

Add -sV to detect the service and its version:

nmap -sV 192.0.2.11 -p 1433

Aggressive scan (-A) with faster timing (-T4) and verbose output (-v):

nmap -p 1433 -T4 -A -v sqlserver01

Discover SQL Server instances

The ms-sql-info NSE script retrieves instance information (name, version, ports):

nmap -p 1433 --script ms-sql-info sqlserver01
nmap -p 1433 --script ms-sql-info sqlserver01/24 -R
nmap -p 1433 --script ms-sql-info --script-args mssql.instance-port=1433 192.0.2.0/24

To discover every instance on each host, use mssql.instance-all. Adding -O enables OS detection and -oX writes the result as XML (the file name here is an example):

sudo nmap -O -p 1433 --script ms-sql-info --script-args mssql.instance-all 192.0.2.0/24 -oX sql_scan.xml

UDP scan with all output formats

UDP scan with service detection, extra verbosity, ICMP echo host discovery (-PE), no DNS resolution (-n) and output in all formats (-oA). Targets can be read from a file (-iL) and some hosts excluded (--excludefile):

nmap -vv -PE -sU -iL input.lst --excludefile banned.lst -p 1434 -n -oA sql_svr -sV
nmap -vv -PE -sU -p 1434 -n -oA sql_svr -sV

Option summary

Option Purpose
-p Ports to scan
-sT TCP connect scan
-sU UDP scan
-sV Service and version detection
-O OS detection
-A OS detection, version detection, script scanning and traceroute
-T4 Faster timing template
-v, -vv Increase verbosity
-PE ICMP echo host discovery
-n Never resolve DNS names
-R Always resolve DNS names
-iL Read targets from a file
--excludefile Exclude targets listed in a file
-oX Write XML output
-oA Write output in all formats
--script Run an NSE script
--script-args Pass arguments to the script

Post-processing

Nmap XML output can be converted to CSV for analysis, for example with the approach described in nmap XML to CSV.

Notes

Mastodon LLIMastodon SocialFosstodon