Nmap Security Scanner
Intro
Ref Guide
Install Guide
Download
Changelog
Book
Docs
Security Lists
Nmap Hackers
Nmap Dev
Bugtraq
Full Disclosure
Pen Test
Basics
More
Security Tools
Pass crackers
Sniffers
Vuln Scanners
Web scanners
Wireless
Exploitation
Packet crafters
More
Site News
Site Search:
Exploit World
Advertising
About/Contact
Credits
Sponsors:
|

While NSE has a complex implementation for efficiency, it is
strikingly easy to use. Simply specify
-sC
to enable the most common scripts. Or specify the
--script
option to choose your own scripts to
execute by providing categories, script file names, or the name of
directories full of scripts you wish to execute. You can customize
some scripts by providing arguments to them via the
--script-args
option. The two remaining options,
--script-trace
and --script-updatedb,
are generally only used for script debugging and development. Script scanning is also included as part of the -A (aggressive scan) option.
NSE scripts define a list of categories they belong to.
Currently defined categories
are auth, default, discovery, external,
intrusive, malware, safe, version,
and vuln. Category names are not case sensitive. The following list describes each category. -
auth
These scripts try to determine authentication credentials
on the target system, often through a brute-force attack. Examples include snmp-brute, http-auth, and ftp-anon. -
default
These scripts are the default set and are run when
using the -sC or -A
options rather than listing scripts
with --script. This category can also be
specified explicitly like any other
using --script=default. Many factors are
considered in deciding whether a script should be run by
default: - Speed
A default scan must finish quickly, which excludes brute force authentication crackers, web spiders, and any other scripts which can take minutes or hours to scan a single service. - Usefulness
Default scans need to produce valuable and actionable information. If even the script author has trouble explaining why an average networking or security professional would find the output valuable, the script should not run by default. The script may still be worth including in Nmap so that administrators can run for those occasions when they do need the extra information. - Verbosity
Nmap output is used for a wide variety of
purposes and needs to be readable and concise. A script which
frequently produces pages full of output should not be added
to the default category. When there is no
important information to report, NSE scripts (particularly
default ones) should return nothing. Checking for an obscure
vulnerability may be OK by default as long as it only produces output
when that vulnerability discovered. - Reliability
Many scripts use heuristics and fuzzy signature matching to reach conclusions about the target host or service. Examples include sniffer-detect and sql-injection. If the script is often wrong, it doesn't belong in the default category where it may confuse or mislead casual users. Users who specify a script or category directly are generally more advanced and likely know how the script works or at least where to find its documentation. - Intrusiveness
Some scripts are very intrusive because they use significant resources on the remote system, are likely to crash the system or service, or are likely to be perceived as an attack by the remote administrators. The more intrusive a script is, the less suitable it is for the default category. - Privacy
Some scripts, particularly those in the external category described later, divulge information to third parties by their very nature. For example, the whois script must divulge the target IP address to regional whois registries. We have also considered (and decided against) adding scripts which check target SSH and SSL key fingerprints against Internet weak key databases. The more privacy-invasive a script is, the less suitable it is for default category inclusion.
We don't have exact thresholds for each of these criteria,
and many of them are subjective. All of these factors are
considered together when making a decision whether to promote a
script into the default category. A few default scripts are identd-owners (determines the username running remote services using identd), http-auth (obtains authentication scheme and realm of web sites requiring authentication), and ftp-anon (tests whether an FTP server allows anonymous access). -
discovery
These scripts try to actively discover more about the
network by querying public registries, SNMP-enabled
devices, directory services, and the like. Examples include html-title (obtains the title of the root path of web sites), smb-enum-shares (enumerates Windows shares), and snmp-sysdescr (extracts system details via SNMP). -
external
Scripts in this category may send data to a
third-party database or other network resource. An example
of this is whois, which makes a
connection to
whois servers
to learn about the address of the target. There is always
the possibility that operators of the third-party
database will record anything you send to them, which in
many cases will include your IP address and the address of
the target. Most scripts involve traffic strictly between
the scanning computer and the client; any that do not are
placed in this category. -
intrusive
These are scripts that cannot be classified in the
safe category because the risks are too
high that they will crash the target system, use up
significant resources on the target host (such as
bandwidth or CPU time), or otherwise be perceived as
malicious by the target's system administrators. Examples
are http-open-proxy (which attempts to
use the target server as an HTTP proxy)
and snmp-brute (which tries to guess a
device's SNMP community string by sending common values
such
as public, private,
and cisco). -
malware
These scripts test whether the target platform is
infected by malware or backdoors. Examples include smtp-strangeport, which watches for SMTP servers running on unusual port numbers, and auth-spoof, which detects identd spoofing daemons which provide a fake answer before even receiving a query. Both of these behaviors are commonly associated with malware infections. -
safe
Scripts
which weren't designed to crash services, use large
amounts of network bandwidth or other resources, or
exploit security holes are categorized as safe. These are less likely to offend
remote administrators, though (as with all other Nmap
features) we cannot guarantee that they won't ever cause
adverse reactions. Most of these perform general
network discovery. Examples are
ssh-hostkey (retrieves an SSH host key) and
html-title (grabs the title from a
web page). -
version
The scripts in this special category are an
extension to the version detection feature and cannot be
selected explicitly. They are selected to run only if
version detection (-sV) was requested.
Their output cannot be distinguished from version
detection output and they do not produce service or host
script results. Examples
are skypev2-version, pptp-version,
and iax2-version. -
vuln
These scripts check for specific known vulnerabilities and
generally only report results if they are found. Examples include realvnc-auth-bypass and xampp-default-auth.
These are the five command line arguments specific to script-scanning:
-
-sC
Performs a script scan using the default set of scripts. It is
equivalent to --script=default. Some of the
scripts in this default category are considered intrusive and should
not be run against a target network without permission. -
--script <script-categories>|<directory>|<filename>|all Runs a script scan (like -sC) using the comma-separated list of
script categories, individual scripts, or directories containing
scripts, rather than the default set. Nmap first tries to interpret the
arguments as categories, then (if that fails) as files or
directories. A script or directory of scripts may be specified as an
absolute or relative path. Absolute paths are used as
supplied. Relative paths are searched for in the following places
until found:
--datadir/;
$NMAPDIR/;
~/.nmap/ (not searched on Windows);
NMAPDATADIR/ or
./. A scripts/ subdirectory
is also tried in each of these. If a directory is specified and found, Nmap loads all NSE
scripts (any filenames ending with .nse) from that
directory. Filenames without the nse extension are
ignored. Nmap does not search recursively into subdirectories to find
scripts. If individual file names are specified, the file extension
does not have to be nse. Nmap scripts are stored in a scripts
subdirectory of the Nmap data directory by default (see
Chapter 14, Understanding and Customizing Nmap Data Files). For efficiency, scripts are indexed in
a database stored
in scripts/script.db.
which lists the category or categories in which each script belongs.
Give the argument all to execute all scripts in the
Nmap script database. Scripts are not run in a sandbox and thus could accidentally or maliciously damage your system or invade your privacy. Never run scripts from third parties unless you trust the authors or have carefully audited the scripts yourself. -
--script-args
provides arguments to the scripts. See the section called “Arguments to Scripts” for a detailed explanation. -
--script-trace
This option is similar to
--packet-trace, but works at the
application level rather than packet by packet. If this
option is specified, all incoming and outgoing
communication performed by scripts is printed. The
displayed information includes the communication
protocol, source and target addresses, and the
transmitted data. If more than 5% of transmitted data is
unprintable, hex dumps are given instead.
Specifying --packet-trace enables script
tracing too.
-
--script-updatedb
This option updates the script database found
in scripts/script.db which is used by
Nmap to determine the available default scripts and
categories. It is only necessary to update the database if
you have added or removed NSE scripts from the
default scripts directory or if you
have changed the categories of any script. This option is
used by
itself without arguments: nmap --script-updatedb.
Some other Nmap options have effects on script scans. The most
prominent of these is
-sV.
A version scan automatically executes
the scripts in the
version category.
The scripts
in this category are slightly different than other scripts because their
output blends in with the version scan results and they do not produce any
script scan output.
Another option which affects the scripting engine is
-A.
The aggressive Nmap mode implies
the -sC option.
Arguments may be passed to NSE scripts using the
--script-args option. The script arguments are generally
name-value pairs. They are provided to scripts as a Lua table named
args inside nmap.registry.
The argument names are keys for the corresponding values. The values can be
either strings or tables. Subtables can be used to pass arguments to
scripts with finer granularity, such as passing different usernames for
different scripts. Here is a typical Nmap invocation with script arguments:
$ nmap -sC --script-args user=foo,pass=bar,whois={whodb=nofollow+ripe}
The aforementioned command results in this Lua table:
{user="foo",pass="bar",whois={whodb="nofollow+ripe"}}
You could therefore access the username (foo)
inside your script with this statement: local username = nmap.registry.args.user
Subtables used to override
options for scripts are usually named after the script to ease retrieval.
A simple script scan using the default set of scripts:
$ nmap -sC example.com
Executing a specific script with tracing enabled:
$ nmap --script=./showSSHVersion.nse --script-trace example.com
Execute all scripts in the mycustomscripts directory as well as all default scripts in the safe category:
$ nmap --script=mycustomscripts,safe example.com
|
|