Nmap Scripting Engine (NSE) | Nmap Network Scanning (2024)

  • Nmap Network Scanning
  • Chapter15.Nmap Reference Guide
  • Nmap Scripting Engine (NSE)

The Nmap Scripting Engine (NSE) is one of Nmap's most powerful and flexible features. It allows users to write (and share) simple scripts (using the Lua programming language ) to automate a wide variety of networking tasks. Those scripts are executed in parallel with the speed and efficiency you expect from Nmap. Users can rely on the growing and diverse set of scripts distributed with Nmap, or write their own to meet custom needs.

Tasks we had in mind when creating the system include network discovery, more sophisticated version detection, vulnerability detection. NSE can even be used for vulnerability exploitation.

To reflect those different uses and to simplify the choice of which scripts to run, each script contains a field associating it with one or more categories. Currently defined categories are auth, broadcast, default. discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, and vuln. These are all described in the section called “Script Categories”.

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.

The Nmap Scripting Engine is described in detailin Chapter9, Nmap Scripting Engine and is controlled by the following options:

-sC

Performs a script scan using the default set of scripts. It is equivalent to --script=default. Some of the scripts in this category are considered intrusive and should not be run against a target network without permission.

--script <filename>|<category>|<directory>/|<expression>[,...]

Runs a script scan using the comma-separated list of filenames, scriptcategories, and directories. Each element in the list may also be aBoolean expression describing a more complex set of scripts. Eachelement is interpreted first as an expression, then as a category, andfinally as a file or directory name.

There are two special features for advanced users only.One is to prefix script names and expressions with+ to force them to run even if they normallywouldn't (e.g. the relevant service wasn't detected on the targetport). The other is that the argument all may beused to specify every script in Nmap's database. Be cautious withthis because NSE contains dangerous scripts such as exploits, bruteforce authentication crackers, and denial of service attacks.

File and directory names may be relative or absolute. Absolute names areused directly. Relative paths are looked for in thescripts of each of the following places untilfound:

--datadir
$NMAPDIR
~/.nmap (not searched on Windows)
<APPDATA>\nmap (only on Windows)
the directory containing the nmapexecutable
the directory containing the nmapexecutable, followed by ../share/nmap (not searched on Windows)
NMAPDATADIR (not searched on Windows)
the current directory.

When a directory name ending in / is given, Nmap loads every file in the directorywhose name ends with .nse. All other files areignored and directories are not searched recursively. When a filename isgiven, it does not have to have the .nse extension;it will be added automatically if necessary.

Nmap scripts are stored in a scriptssubdirectory of the Nmap data directory by default(see Chapter14, Understanding and Customizing Nmap Data Files).For efficiency, scripts are indexed ina database storedin scripts/script.db,which lists the category or categories in which each script belongs.

When referring to scripts from script.db by name, you can use a shell-style ‘*’ wildcard.

nmap --script "http-*"

Loads all scripts whose name starts with http-, such as http-auth and http-open-proxy. The argument to --script had to be in quotes to protect the wildcard from the shell.

More complicated script selection can be done using the and, or, and not operators to build Boolean expressions. The operators have the same precedence as in Lua: not is the highest, followed by and and then or. You can alter precedence by using parentheses. Because expressions contain space characters it is necessary to quote them.

nmap --script "not intrusive"

Loads every script except for those in the intrusive category.

nmap --script "default or safe"

This is functionally equivalent to nmap --script "default,safe". It loads all scripts that are in the default category or the safe category or both.

nmap --script "default and safe"

Loads those scripts that are in both the default and safe categories.

nmap --script "(default or safe or intrusive) and not http-*"

Loads scripts in the default, safe, or intrusive categories, except for those whose names start with http-.

--script-args <n1>=<v1>,<n2>={<n3>=<v3>},<n4>={<v4>,<v5>}

Lets you provide arguments to NSE scripts. Arguments are a comma-separated listof name=value pairs. Names and values may be strings notcontaining whitespace or the characters‘{’,‘}’,‘=’, or‘,’.To include one of these characters in a string, enclose the string in single ordouble quotes. Within a quoted string, ‘\’escapes a quote. A backslash is only used to escape quotation marks in thisspecial case; in all other cases a backslash is interpreted literally. Valuesmay also be tables enclosed in {}, just as in Lua. A tablemay contain simple string values or more name-value pairs, including nestedtables. Many scripts qualify their arguments with the script name, as in xmpp-info.server_name. You may use that full qualified version to affect just the specified script, or you may pass the unqualified version (server_name in this case) to affect all scripts using that argument name. A script will first check for its fully qualified argument name (the name specified in its documentation) before it accepts an unqualified argument name. A complex example of script arguments is--script-args 'user=foo,pass=",{}=bar",whois={whodb=nofollow+ripe},xmpp-info.server_name=localhost'. The online NSE Documentation Portal at https://nmap.org/nsedoc/lists the arguments that each script accepts.

--script-args-file <filename>

Lets you load arguments to NSE scripts from a file. Any arguments on the command line supersede ones in the file. The file can be an absolute path, or a path relative to Nmap's usual search path (NMAPDIR, etc.) Arguments can be comma-separated or newline-separated, but otherwise follow the same rules as for --script-args, without requiring special quoting and escaping, since they are not parsed by the shell.

--script-help <filename>|<category>|<directory>|<expression>|all[,...]

Shows help about scripts. For each script matching the given specification, Nmap prints the script name, its categories, and its description. The specifications are the same as those accepted by --script; so for example if you want help about the ftp-anon script, you would run nmap --script-help ftp-anon. In addition to getting help for individual scripts, you can use this as a preview of what scripts will be run for a specification, for example with nmap --script-help default.

--script-trace

This option does what --packet-trace does, just one ISO layer higher. If this option is specified all incoming and outgoing communication performed by a script is printed. The displayed information includes the communication protocol, the source, the target and the transmitted data. If more than 5% of all transmitted data is not printable, then the trace output is in a hex dump format. 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 generally used by itself: nmap --script-updatedb.

Nmap Scripting Engine (NSE) | Nmap Network Scanning (2024)

FAQs

What is NSE in Nmap scan? ›

The Nmap Scripting Engine (NSE) is one of Nmap's most powerful and flexible features. It allows users to write (and share) simple scripts to automate a wide variety of networking tasks. Those scripts are then executed in parallel with the speed and efficiency you expect from Nmap.

Is it illegal to scan a network with Nmap? ›

Network probing or port scanning tools are only permitted when used in conjunction with a residential home network, or if explicitly authorized by the destination host and/or network. Unauthorized port scanning, for any reason, is strictly prohibited.

How do I run a Nmap to scan a network? ›

How to Use Nmap to Scan a Network: A Step-by-Step Guide
  1. Install Nmap.
  2. Nmap Command Generator.
  3. Ensure You Have Permission.
  4. Select Network Range.
  5. Scan Types.
  6. Scan Option.
  7. Scanning an Entire Network Walkthrough.
  8. Disruption Mitigation.
May 11, 2024

Where is the NSE file in Nmap? ›

nse. They are stored in the scripts subdirectory of the main Nmap directory. The script. db file is also located in the main Nmap directory, and it contains the list of all NSE scripts and their associated categories (safe, intrusive, malware, backdoor, version, discovery, vulnerability).

What was the command you run to use the NSE script? ›

The primary option to add common NSE scripts to the nmap command is -sC . The --script option defines which script to run if you're using your own script. Some scripts use customized arguments or react to the results of a more traditional Nmap scan.

What is the most powerful Nmap scan? ›

Let's get to know a few useful command-line based best Nmap scans that can be performed.
  1. Basic Nmap Scan against IP or host. ...
  2. Nmap Ping Scan. ...
  3. Scan specific ports or scan entire port ranges on a local or remote server. ...
  4. Scan multiple IP addresses. ...
  5. Scan IP ranges. ...
  6. Scan the most popular ports.
Apr 11, 2024

Why do hackers use Nmap? ›

However, hackers can also use Nmap to access uncontrolled ports on a system. They can run Nmap on a targeted approach, identify vulnerabilities, and exploit them. But Nmap is not only used by hackers - IT security companies also use it to simulate potential attacks that a system may face.

Do people still use Nmap? ›

Nmap users include everyone from beginners to cyber security professionals. Network administrators use Nmap (and Zenmap) to map subnets and discover hosts. Cyber security professionals use Nmap to scan target systems for open ports and services they might be running.

Can an Nmap scan be detected? ›

Log monitoring tools such as Logwatch and Swatch can certainly help, but the reality is that system logs are only marginally effective at detecting Nmap activity. Special purpose port scan detectors are a more effective approach to detecting Nmap activity. Two common examples are PortSentry and Scanlogd.

Can nmap scan entire networks? ›

To make Nmap scan all the resolved addresses instead of only the first one, use the --resolve-all option. Sometimes you wish to scan a whole network of adjacent hosts. For this, Nmap supports CIDR-style addressing.

Is Nmap safe to use? ›

Yes, Nmap is generally safe to install and use, provided it is used responsibly and legally. Nmap (Network Mapper) is a powerful and widely-used open-source network scanning tool that helps in discovering and mapping networks, identifying open ports, and detecting vulnerabilities.

How do I see devices on my network using Nmap? ›

3. Using nmap
  1. 3.1. Install nmap. Let's install nmap on a Linux system if it isn't already installed: $ sudo apt-get install nmap.
  2. 3.2. Run the nmap Command. Then, let's run the nmap command to list the connected devices in the wireless access point. We'll use the -sn option in nmap to launch the ping scan.
Mar 18, 2024

What is the NSE script? ›

The Nmap Scripting Engine (NSE) is one of Nmap's most powerful and flexible features. It allows users to write (and share) simple scripts (using the Lua programming language ) to automate a wide variety of networking tasks.

What language are NSE scripts written in? ›

The core of the Nmap Scripting Engine is an embeddable Lua interpreter. Lua is a lightweight language designed for extensibility.

What is SMB in Nmap? ›

SMB (Server Message Block) is a protocol used for file and printer sharing in a Windows environment. SMB is commonly used in corporate networks to share files and resources among users. SMBs can also be used by attackers to gain unauthorized access to sensitive information and systems.

What is Nmap PN used for? ›

A no ping scan prevents Nmap from doing any host discovery. It is specified with the -Pn option. By default, Nmap only probes active machines found via host discovery. With this option selected, Nmap will do the requested scanning functions against every target IP specified, as if every one is active.

What is TCP full scan in Nmap? ›

A TCP connect scan establishes a complete connection to the target host by completing a TCP three-way handshake. After the scan is complete, Nmap terminates the connection.

What does an Nmap scan tell you? ›

At its core, Nmap is a network scanning tool that uses IP packets to identify all the devices connected to a network and to provide information on the services and operating systems they are running.

Top Articles
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 5546

Rating: 4.4 / 5 (45 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.