skip to content

NSE Scripting

NSE turns Nmap into an extensible probe framework, categories running from safe discovery to brute and vuln. Expect to justify which you dare run against production and to describe a Lua script.

on this pageshow

questions

6

In Nmap 7.991, what does -sC run, and does using the default script set make a scan safe for production?

level: juniorimportance: must knowfreq 42%

answer

  1. a shorthand, not a script
  2. a category named default
  3. membership comes from the script index
  4. -A switches it on as well
  5. curated for quiet, not for permission

basics

~20 s

-sC is shorthand for --script=default: every script filed under the default category runs. The authors chose that set for speed and low noise, but the reference guide still says not to run it against a network without permission.

solid answer

~40 s

`-sC` is the same as `--script=default`. It is ignored when the command line also carries an explicit `--script`, and `-A` turns it on together with `-sV`, `-O` and `--traceroute`. A script is in `default` when its authors judged it fast, useful, concise, reliable, low in intrusiveness and low in privacy cost; that is a curation, not an enforced safety property. In the 7.991 script index (`scripts/script.db`), 127 of 611 scripts are `default` and all 127 are also `safe`, yet a few also carry `auth`, `vuln` or `external`, and the reference guide still warns that default scripts are considered intrusive. For production I preview the set with `--script-help default`, record the Nmap version, and run it only inside the written scope and window.

code

bash · 5 lines
bash
# Preview what the default category would run (no target is scanned)
nmap --script-help default

# Run it only on the documented host, with XML kept as evidence
nmap -sC -p 443 --reason -oX audit-ticket.xml 192.0.2.10

go deeper

for a junior

Recall that -sC equals --script=default and sends extra application-level probes, so it needs the same written permission as the port scan itself.

for a middle

Explain what the default category is (a curated set judged on speed, usefulness, quietness, reliability and privacy), that -A includes it and that an explicit --script makes -sC a no-op.

for a senior

Show judgment: preview with --script-help, pin the Nmap release, and notice that the set carries a few auth, vuln and external scripts, so the safe tag is not the whole picture.

for a principal

Frame a standing policy: which switches (-sC, -A) are allowed in which environments, and who approves a change to the pinned script set.

## What -sC selects `-sC` is shorthand for `--script=default`. Nmap runs every script whose `categories` list includes `default`, on top of whatever host discovery and port scan the command line asks for. Scripts are chosen through an index, `scripts/script.db`, that lists the categories of each script the release ships. Three details catch people out: 1. The shorthand is **ignored** whenever the command line also names an explicit `--script`. `-sC --script http-title` therefore runs `http-title` and nothing else. 2. `-A` enables script scanning with the default set, together with OS detection (`-O`), version detection (`-sV`) and `--traceroute`. A bare `-A` is a script scan, and it needs the same permission. 3. Script scanning normally rides on a port scan, because many scripts run only when a port is in a suitable state. With `-sn` only host scripts are eligible. ## What "default" means The Nmap book lists the factors weighed before a script is promoted into the category. None has an exact threshold; they are considered together: - **Speed**: a default scan must finish quickly, so long-running scripts such as web spiders stay out. - **Usefulness**: the output must be valuable and actionable for a network or security professional. - **Verbosity**: output is concise, and a script reports nothing when it has nothing important to say. - **Reliability**: scripts that often guess wrongly do not belong where a casual user will trust them. - **Intrusiveness**: the likelier a script is to crash a service, consume resources or look like an attack, the less suitable it is. - **Privacy**: scripts that disclose information to third parties are less suitable. The category is therefore a statement about what a typical assessor wants from a first pass. It is not a promise about what the target will experience. ## What the 7.991 index shows Counting the entries of `scripts/script.db` in the Nmap 7.991 source gives 611 scripts, of which 127 are in `default`. Their overlap with other categories: | Also tagged | Default scripts (7.991) | |---|---| | `safe` | 127 | | `auth` | 7 | | `vuln` | 4 | | `external` | 2 | | `intrusive`, `brute`, `dos`, `exploit`, `fuzzer`, `malware`, `broadcast` | 0 | Two statements look contradictory and both are worth keeping. The reference guide still says that some default scripts are considered intrusive and that neither `-sC` nor `-A` should be pointed at a network without permission. The index of this release contains no default script tagged `intrusive`. The guide is the rule to follow; the index is a fact about one release's files, and it can change with the next one. The `external` entries matter on their own: a script in that category may send data to a third party, so even a "quiet" default run can have a data-handling consequence for the owner. ## Running it on production 1. **Preview.** `nmap --script-help default` prints each selected script's name, categories and description. It exits before scanning any target. 2. **Pin the release.** Record `nmap --version` and the preview in the change record. The default set is whatever that release's files say, and scripts are added, removed and recategorised between releases. For example, 7.991 removed `hostmap-bfk` because the service it used had shut down. 3. **Write the scope down.** Target list, window, source addresses and a contact on the owner's side. The authorisation itself is the signed engagement's job; the scan plan only has to match it. 4. **Bound the run.** Name the ports with `-p`, keep `-oX` output as evidence, and tell the owner to expect extra application-level requests (for instance, `http-title` fetches a web server's default page) and the matching log lines. 5. **Treat anything beyond the preview as a new approval.** If someone adds a category or a script name to the command, the preview is no longer the approved list. ## Reading the result A default script's output is the tool's inference from what the service answered. A missing line can mean a clean service, a rule that did not match the detected service, or a script that stopped early, so do not read silence as assurance. ## Common mistakes - Treating `-sC` as "just a few extra checks" and skipping the permission step. - Equating `default` with `safe` or with `all`; the special argument `all` selects every script in the database, including ones the reference guide calls dangerous. - Forgetting that `-A` includes the default set. - Assuming the set is the same on the next release.

  • Why can -sC output differ between two Nmap releases against the same unchanged host?
    The default set is whatever categories each release's script files carry, and scripts are added, removed (7.991 dropped `hostmap-bfk`) or recategorised. Portrules also change, so a script may match a service it ignored before. Record the Nmap version and the `--script-help default` listing with every report so two runs are comparable.
  • What happens if -sC is combined with -sn?
    No port scan runs, so only host scripts are eligible; scripts that need a port never fire. With `-Pn -sn` every host is assumed up and still only host scripts run, which suits scripts that use only the target's address.

  • -sC just means a plain scan with no extra probes
  • Default scripts are guaranteed harmless, so no approval is needed
  • Adding -sC to an explicit --script list also runs the default set
  • default means every script that ships with Nmap
  • -A only turns on OS and version detection
  • The default set is identical in every Nmap release

Assumes Nmap 7.991: the default set is whatever that release's scripts/script.db lists (127 of 611 scripts); other releases differ.

open as a page

What parts make up an NSE script file, and how do prerule, hostrule, portrule and postrule decide when its action runs?

level: middleimportance: should knowfreq 18%

basics

~20 s

An NSE script is a Lua file with descriptive fields such as description and categories, at least one rule function and an action. The action runs only when a rule returns true: prerule before scanning, hostrule per host, portrule per port, postrule at the end.

open as a page

In Nmap, how do you preview which scripts a --script expression such as "safe and not http-*" would select, and how do arguments reach them?

level: middleimportance: should knowfreq 24%

basics

~10 s

--script-help takes the same specification as --script and prints each matching script's name, categories and description, without scanning. Arguments go in through --script-args name=value,... or --script-args-file, and a command-line value supersedes the file.

open as a page

A change board asks which NSE script categories may run against production hosts in an authorised audit; what do you allow, and what does the safe label not promise?

level: seniorimportance: should knowfreq 33%

basics

~20 s

Allow only previewed scripts in the safe category, and require separate written authorisation for intrusive, brute, dos, exploit and fuzzer. Safe is the author's own label, not a guarantee, and it says nothing about scripts that send data to third parties.

open as a page

An Nmap vuln script prints State: LIKELY VULNERABLE under a VULNERABLE: heading on one host and nothing on another; what does each result actually prove?

level: seniorimportance: should knowfreq 29%

basics

~20 s

LIKELY VULNERABLE means the script found indirect evidence, such as a version or uptime comparison, not a confirmed flaw, and the VULNERABLE: heading also covers it. Silence proves nothing: scripts normally report only positives and may not have run.

open as a page

In a web server's access log, what does the Nmap Scripting Engine's default User-Agent tell the owner, and what can it not prove?

level: middleimportance: nice to knowfreq 12%

basics

~20 s

Scripts that use Nmap's HTTP library send the User-Agent Mozilla/5.0 (compatible; Nmap Scripting Engine; https://nmap.org/book/nse.html) by default, a good hint of an NSE web script. It is a client-chosen header, so match source and time to the scan ticket and never read its absence as proof.

open as a page