How Nmap service scanning works
masterThe Nmap struct implements a probe-based service detection engine.
The Scanning Lifecycle
- Probe Selection: For a given port, the engine selects a list of probes. It prioritizes probes mapped specifically to that port, then adds general probes (
allProbeMap), and finally adds SSL-specific probes (sslProbeMap). - Execution: It executes the first probe. If the port is not
ClosedorMatched, it proceeds to subsequent probes. - Fingerprinting: When a probe returns data, the engine uses
getFingerto match the response against known service patterns. It converts binary responses to UTF-8 strings to facilitate regex matching. - Fallback Mechanism: If a probe fails to match a service, it can follow a
fallbackchain to try related probes (e.g., falling back from a specific protocol to a more generic one). - SSL/HTTPS Refinement: If a service is identified as
ssl, the engine automatically triggersgetResponseBySSLSecondProbesto ensure the service isn't actually standardhttprunning over TLS (identifying it ashttps).