A few Nmap tips

There are only a handful of nmap options I use regularly. The combinations depend on the situation, balancing scan speed against what I need to discover.

0x01 Options and results

1. Comparing the output of a few options

For scanning, -A == -sC -sV -O -traceroute: script scanning, service detection, OS detection, and traceroute.

  • Left: -sC -sV -O
  • Right: -A

I'd expect -A to add only one or two traceroute results, but that isn't always what happens. The right side above has five additional results:

  • Device type: Device type enumeration.
  • Running (JUST GUESSING): Enumeration of the target operating system.
  • OS CPE: Common Platform Enumeration, a naming scheme for identified software, hardware, and operating systems.
  • Network Distance: Distance to the target, measured in hops.
  • TRACEROUTE: The route to the target.
  1. Device type, Running, and OS CPE come from -O, or OS detection. Sometimes these three results don't appear. My understanding is that they appear as possible matches when the scan can't identify the system precisely.
  2. Network Distance and TRACEROUTE come from -traceroute.

0x02 Scan speed

I compared scan speeds with a pretty small sample.

1. No extra options vs. -A

Both commands ran in the same environment and scanned every port on the target, which was known to have only five open ports.

nmap -p- 10.10.10.3
nmap -A -p- 10.10.10.3

Run time: 306.66 vs. 399.79 My initial guess is that the extra time in the second scan goes into service detection. Ports found to be closed don't get service detection. So finding open ports first, then scanning their services doesn't appear to be faster than scanning services directly.

UDP scans are painfully slow. I haven't compared those yet; maybe the VPN for this machine is the problem.

My conclusion for a single server: just use nmap -A -p- IP.

0x03 Maximum retries: --max-retries

By default, a scan sends more than one request to each port. I'm not sure how many. Change this option when you want to speed up a scan or send a specific sequence of port requests. One example is knock knock, where contacting ports in a particular order opens the firewall.

# 比如为了加速,设置为1
nmap -A -p- -oA xx.nmap 10.10.10.3 --man-retries 1

0x04 Report stylesheet: --stylesheet

You can load a fancy output template. https://github.com/honze-net/nmap-bootstrap-xsl

nmap -A -p- -oA xx.nmap --stylesheet tools/nmap-bootstrap.xsl 10.10.10.3