


























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.
Only scan networks and hosts you have permission for. Many hosting providers do not allow the scanning of other networks, and doing it anyways could cause you trouble. Please be aware of it.
This blog post will cover the general usage of nmap scripts, not the scripting itself. Check out the getting started with nmap post if you are new to nmap.
The Nmap Scripting Engine (NSE) allows you to run and share pre-made and custom scripts. Scripts are written in Lua and use the file extension .nse. NSE will enable you to scan and analyze any host and network in-depth and according to your needs. Automation, vulnerability scans, and many other functions are possible with the NSE.
A list of all, by default, included scripts can be found in their official docs.
I mainly use scripts to find, enumerate and check SMB shares and SSH servers, finding potential rogue DHCP servers (consumer routers ftw), and some specific vuln scans for like log4j and other recent attacks.
nmap --script=SCRIPTNAME TARGETNETWORK/HOSTnmap --script http-title scanme.nmap.orgnmap --script=http-title scanme.nmap.orgnmap --script 'http-title' scanme.nmap.orgnmap --script "http-title" scanme.nmap.orgnmap --script="http-title" scanme.nmap.org.nse right afterOutput:
[...]
80/tcp open http
|_http-title: Go ahead and ScanMe!
[...]
Side note: Scanning the domain scanme.nmap.org is permitted in low volumes as stated on their page, but please do not abuse it!
There are various ways to use multiple scripts at once. The easiest way would be to separate them with a comma.
nmap -p 80 --script=http-title,http-headers scanme.nmap.org
Another way would be to use a whole directory with with --datadir argument, in which all scripts within the chosen directory would be running.
The last way is to pick a whole category of scripts. I'll write about categories further down in this post.
You can use --script-help to get additional information of a script.
nmap --script-help http-title.nse
Starting Nmap 7.80 ( https://nmap.org ) at 2023-04-07 16:23 CEST
http-title
Categories: default discovery safe
https://nmap.org/nsedoc/scripts/http-title.html
Shows the title of the default page of a web server.
The script will follow up to 5 HTTP redirects using the default rules in the
http library.
Some scripts require arguments. You can find them with --script-help or on the official page of the script.
--script-args <n1>=<v1>,<n2>={<n3>=<v3>},<n4>={<v4>,<v5>}If you have many arguments to run, you can call them from a file with --script-args-file FILENAME.
You usually can find the default scripts in the following directories.
/usr/local/share/nmap/scripts or /usr/share/nmap/scripts or somewhere else, depending on the installing method.locate *.nseC:\Program Files\Nmap\scriptsYou can choose a different directory with the --datadir argument.
nmap --datadir /some/random/path/to/scripts/ -sC -sV TARGETNETWORK
--datadir$NMAPDIR~/.nmap (Linux)APPDATA>\nmap (Windows)nmap executable + ../share/nmap in LinuxNMAPDATADIRMore complex scripts require separate data sets, databases, and other things. Those must be placed in the NSE data directory. It works similarly to the script directory but is out of this post's scope. Most scripts that require this function will let you know. I just thought it would be beneficial to mention.
It is straightforward to use and add custom scripts, that are either created by yourself or downloaded from the internet.
I want to point to the disclaimer at the top of the post: only run scripts that you trust!
nmap --script /path/to/script.nse TARGETUsing the absolute path of a script would be the easiest way to do so. If the script works and you plan to use it more often, you can add it you the script.db, which contains all scripts and let you call the script with the name only. This file is generally in the same directory as the already included scripts.
Add the .nse file to the script directory and run the following command to add the script to script.db:
sudo nmap --script-updatedb
You should now be able to run the script with the name only.
NSE categorizes its scripts, so you can run a bunch of them at once. The following categories are currently there:
auth, broadcast, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, and vuln
Most names are self-explanatory, and for more information, I'd like to refer you to the official docs.
default scripts with the following command:nmap --script=default TARGETnmap -sC TARGET # -sC is the short form and no other category has one to my knowledgeLike the scripts, you could run multiple categories. Simply separate them with a comma.
I bet there are easier ways to check what scripts are in a category, but I'd just check the script.db for the specific category:
grep -i 'default' script.db
Output
Entry { filename = "address-info.nse", categories = { "default", "safe", } }
Entry { filename = "afp-serverinfo.nse", categories = { "default", "discovery", "safe", } }
Entry { filename = "ajp-auth.nse", categories = { "auth", "default", "safe", } }
Entry { filename = "ajp-methods.nse", categories = { "default", "safe", } }
Entry { filename = "amqp-info.nse", categories = { "default", "discovery", "safe", "version", } }
[...]
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。