The Nmap Scripting Engine (NSE) runs small Lua scripts against the hosts and services a scan finds. Scripts grab banners, enumerate shares, check TLS settings, test for known vulnerabilities and, in some cases, guess passwords or exploit a flaw. Some are harmless reads and others can crash a service, so know which you are about to run. Test only networks and systems you own or are authorised to assess. This is a companion to the Nmap scanning guide, part of Penetration Testing Field Notes.
What NSE is, and the one warning in the manual
Scripts are written in Lua. Most run in parallel once host discovery, the port scan and any version or OS detection have finished for a host. Nmap 7.993 ships 619 scripts, which the NSEDoc portal documents with 139 libraries. The Nmap documentation says scripts are not run in a sandbox, so they can damage the system they run on or expose your privacy, and it says never to run third party scripts unless you trust the author or have audited them.
Categories decide what a script may do
Every script lists its categories, and the usage chapter defines fourteen: auth, broadcast, brute, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version and vuln. (NSEDoc also lists info, which only multicast-profinet-discovery declares.) The ones that matter most on a live network:
safe: scripts not designed to crash services, use large amounts of bandwidth or exploit holes. The manual gives no guarantee.intrusive: scripts that risk crashing the target, using significant resources, or being read as an attack. Anything that is notsafeand notversionshould be here.default: what-sCruns. The project weighs speed, usefulness, concise output, reliability, intrusiveness and privacy, and occasionally admits a mildly intrusive script. All 128defaultscripts in 7.993 are alsosafe, yet the manual warns that some are considered intrusive and should not be run against a network without permission.vuln: checks for specific known vulnerabilities, which usually report only when they find one.brute,dos,exploitandfuzzer: guessing credentials, denial of service, exploiting flaws and sending malformed input.external: may send data, such as your target’s address, to a third party.whois-ipis the manual’s example.version: runs only with-sVand folds its output into version detection.
In the script database shipped with Nmap 7.993, smb-vuln-ms17-010 is vuln and safe, whois-ip is external and safe, while ssl-enum-ciphers is discovery and intrusive and http-enum is discovery, intrusive and vuln. vuln does not mean dangerous and discovery does not mean harmless, so check.
Selecting scripts with -sC and --script
-sC equals --script=default. It is ignored when you also pass --script, and -A implies it. --script takes a comma separated list of script names, categories and directories ending in /, and each item is tried first as an expression, then a category, then a file or directory. You can drop the .nse extension. A shell style * matches names from the database and needs quotes, for example "http-*".
Expressions use and, or, not and brackets, with not binding tightest, and they must be quoted because they contain spaces. "default and safe" runs scripts in both categories, and "not intrusive" runs everything else, which is not the same as safe: in 7.993, 23 scripts outside version carry neither tag, 12 of them exploit scripts. Filter on safe instead. The word all selects every script in the database, which includes the exploit, brute force and denial of service scripts, so avoid it. A + prefix forces a script to run even when its port or host rule would skip it, for instance on a service Nmap did not identify.
Read the script before you run it
- Preview what a selection would run:
nmap --script-help "default and safe". For each script it prints the name, categories, a link and the description, and it accepts the same specifications as--script. - Open the
.nsefile. Itscategoriestable,descriptionand any@argscomments are at the top, and theportrule,hostrule,preruleorpostrulefunction says when it runs. - Find the script directory. Relative names are searched in
scriptsunder--datadir,$NMAPDIR,~/.nmapand the executable’s directory (and its../share/nmap), among others. Scripts are indexed inscripts/script.db. - If you add, remove or recategorise a script in that directory, run
nmap --script-updatedbonce so the index matches.
Arguments, tracing and debugging
--script-args passes name=value pairs. Quote the argument for your shell, and note that names and values may not contain whitespace or the characters {, }, = and , unless quoted. Many arguments are qualified by script, such as http-title.url. Library arguments such as http.useragent affect every script that uses the library, and an unqualified name such as timeout reaches every script that reads it; where both forms are given, the most specific wins. All arguments share one global namespace, so the manual advises against short names such as user. --script-args-file reads the same arguments from a file, separated by commas or new lines, with no shell quoting needed, and command line arguments override it. A relative file name is looked up in Nmap’s data directories, not the current directory, so give a full path.
--script-trace prints the communication scripts send and receive, one layer above --packet-trace, and --packet-trace turns it on too. Use it to see what a script sent before you report what it found.
Commands
Checked against Nmap 7.993 (released 23 October 2026) and its NSE usage chapter. 192.0.2.0/24 is a documentation range, so replace it with your own lab. Categories below are from the 7.993 script database.
# see what a selection would run, without running anything
nmap --script-help "default and safe"
nmap --script-help ssl-enum-ciphers
# the default scripts after a port scan, saving all formats
nmap -sC -oA lab-default 192.0.2.10
# safe, read only scripts: web title, headers, methods, SSH host key
nmap -p 22,80,443 --script "http-title,http-headers,http-methods,ssh-hostkey" -oA lab-web 192.0.2.10
# a Boolean expression: safe scripts, minus any that contact a third party or broadcast on the local network
nmap -sV --script "safe and not (external or broadcast)" -oA lab-safe 192.0.2.10
# SMB checks on a lab Windows host (both are safe; the second reads SMB2 and SMB3 signing,
# because smb-security-mode speaks only SMBv1, which current Windows does not install)
nmap -p 445 --script smb-protocols,smb2-security-mode 192.0.2.20
# arguments from a file, which also tags your traffic with a custom User-Agent;
# pass a full path, because Nmap does not look for the file in the current directory
printf 'http.useragent=lab-audit-1\nhttp-title.url=/\n' > lab.args
nmap -p 80 --script http-title --script-args-file "$PWD/lab.args" 192.0.2.10
# watch the conversation a script has, then refresh the index after adding scripts
nmap -p 22 --script ssh-hostkey --script-trace 192.0.2.10
nmap --script-updatedbTo practise selecting and reading scripts with guided labs, work through the Nmap: Network Discovery and Port Scanning course.
Detection and defence
NSE traffic is mostly ordinary protocol traffic, so what stands out is volume: many application requests to one host’s services in a short time. Scripts that use Nmap’s HTTP library send a distinctive User-Agent by default, Mozilla/5.0 (compatible; Nmap Scripting Engine; https://nmap.org/book/nse.html), which nselib/http.lua in 7.993 shows can be replaced through the http.useragent argument. Web server and proxy logs therefore catch careless scans. This Suricata 8.0.8 rule alerts on the default string from any source, inside the network or out, using the http.user_agent sticky buffer from the HTTP keywords documentation:
alert http any any -> $HOME_NET any (msg:"Nmap NSE default User-Agent"; flow:established,to_server; http.user_agent; content:"Nmap Scripting Engine"; classtype:attempted-recon; sid:1000002; rev:1;)Test it with suricata -T before deploying. Suricata does not decrypt TLS, so the rule sees only cleartext HTTP; for HTTPS, search the web server’s own log. It is a weak signal, since the value can be changed and many scripts do not use the HTTP library, so pair it with port scan thresholds.
Scripts only report what the service gives away, so reducing that is the defence. Close and filter services nobody needs, which also removes the scripts’ targets. Retire SMBv1 and keep systems patched, because smb-vuln-ms17-010 exists to find an SMBv1 server vulnerable to the flaw behind WannaCry. Disable anonymous FTP, which ftp-anon tests for, and remove weak ciphers that ssl-enum-ciphers grades. Trim server banners and test pages that banner and http-title read. Finally, run your own "default and safe" pass on a schedule to see what a first script scan would see.
Where to go next
Practise choosing, reading and running scripts safely in the Nmap: Network Discovery and Port Scanning course, and revisit Nmap scanning basics for discovery, ports and timing.
This article replaces the KSEC ARK notes first published in 2019.
More from this author
- One capture, three questions2 December, 2026
- Payload channels versus timing channels2 December, 2026
