Skip to content
Tutorials Center
My learning

Topics

Lesson 24 of 36 ยท Nmap Scripting Engine

Common NSE Scripts for Defenders

A tour of useful, low-risk NSE scripts for auditing your own systems: http-title, http-headers, ssl-cert, ssh-hostkey, ftp-anon, dns and banner, with output examples.

Hundreds of NSE scripts exist, but a handful cover most day-to-day audit questions on your own network: What web page is behind this port? Which TLS certificate does the server present and when does it expire? Does the FTP server allow anonymous logins? Which SSH host keys are in use? This lesson walks through the most useful low-risk scripts, shows the kind of output they produce and demonstrates how to check the results with code.

All the commands target documentation addresses (192.0.2.x, reserved for examples) and are shown read-only. Run them only against systems you own or are authorised to test.

Output blocks are illustrative examples, not live results. The runnable code is Python that works on text you paste in.

Web servers

http-title and http-headers

Terminal
# Example commands (read-only)
nmap -p 80,443,8080 --script http-title,http-headers 192.0.2.10
TEXT
PORT     STATE SERVICE
80/tcp   open  http
|_http-title: Did not follow redirect to https://lab.example.test/
443/tcp  open  https
|_http-title: Lab status page
| http-headers:
|   Server: nginx/1.24.0 (Ubuntu)
|   Content-Type: text/html
|   Strict-Transport-Security: max-age=31536000
|   Connection: close
|_  (Request type: HEAD)
8080/tcp open  http-proxy
|_http-title: 403 Forbidden

http-title is the fastest way to see what a port serves: a forgotten admin console or a default "It works!" page stands out immediately. http-headers lists response headers, which is useful for a security-header review.

Other helpful web scripts: http-methods (which HTTP methods are allowed), http-robots.txt, http-enum (known directory names; discovery and intrusive in some versions, so check its help first) and http-server-header.

Auditing headers with code

The stand-in checks pasted response headers against a list of recommended security headers.

Python Stand-in: security header review

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

TLS certificates: ssl-cert and ssl-enum-ciphers

Terminal
# Example command (read-only)
nmap -p 443 --script ssl-cert,ssl-enum-ciphers 192.0.2.10
TEXT
443/tcp open  https
| ssl-cert: Subject: commonName=lab.example.test
| Subject Alternative Name: DNS:lab.example.test, DNS:www.lab.example.test
| Issuer: commonName=Lab Test CA
| Public Key type: rsa
| Public Key bits: 2048
| Not valid before: 2026-02-01T10:00:00
|_Not valid after:  2027-02-01T10:00:00
| ssl-enum-ciphers:
|   TLSv1.2:
|     ciphers:
|       TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (secp256r1) - A
|   TLSv1.3:
|     ciphers:
|       TLS_AKE_WITH_AES_256_GCM_SHA384 (ecdh_x25519) - A
|_  least strength: A

ssl-cert shows who the certificate belongs to, who issued it and when it expires. An expiry check across all hosts is a classic automation job, and ssl-enum-ciphers grades the supported protocol versions and ciphers.

Python Stand-in: warn about expiring certificates

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

SSH and FTP

Terminal
# Example commands (read-only)
nmap -p 22 --script ssh-hostkey,ssh2-enum-algos 192.0.2.10
nmap -p 21 --script ftp-anon 192.0.2.10
TEXT
21/tcp open  ftp
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| -rw-r--r--   1 ftp  ftp   1024 Jan 10 09:00 readme.txt
|_drwxr-xr-x   2 ftp  ftp   4096 Jan 10 09:00 pub
22/tcp open  ssh
| ssh-hostkey:
|   256 3a:bc:... (ECDSA)
|_  256 9f:21:... (ED25519)

ftp-anon is in the auth and safe categories. An unexpected "Anonymous FTP login allowed" on an internal server is something to fix. ssh-hostkey prints the fingerprints, which you can compare with the known ones to detect an impostor; ssh2-enum-algos lists the algorithms the server offers so you can retire weak ones.

Network services and discovery

Script Use
banner Prints the raw greeting of a service
dns-nsid, dns-recursion Identify a DNS server and test whether it answers recursive queries for outsiders
smb-os-discovery Windows version and names via SMB
smb-security-mode Shows signing requirements
nbstat NetBIOS names on a local network
snmp-info Basic info from SNMP (with -sU)
mysql-info, ms-sql-info Product details of database ports
smtp-commands Commands supported by a mail server
sslv2, tls-nextprotoneg Old or special TLS features
traceroute-geolocation external: sends addresses to a geolocation service

An open DNS resolver is a common real-world finding: a resolver that answers anyone can be abused for reflection attacks, and dns-recursion reveals it quickly.

Reading script output programmatically

Script output is text with a regular shape. The stand-in extracts the cases that matter from a pasted scan: anonymous FTP and a missing HTTPS redirect.

Python Stand-in: flag findings in script output

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Tips

  • Always run nmap --script-help <name> first: it lists categories, arguments and warnings.
  • Save script output with -oA so findings can be compared over time (Output Formats).
  • Scripts that talk to external services (external) must be allowed by your policy.
  • Combine scripts with the correct ports (-p) instead of running everything on all ports.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which script is the quickest way to see what a web port serves?

    http-title prints the HTML title of the page returned by the web server, which quickly reveals admin consoles and default pages.
  2. 2. What problem does dns-recursion find?

    Open recursive resolvers can be used in reflection and amplification attacks, so they should only serve trusted clients.
  3. 3. Which script output tells you when a certificate must be renewed?

    ssl-cert prints validity dates in addition to subject and issuer.
  4. 4. Why check --script-help before using a script?

    Help text tells you whether a script is safe, intrusive or external, and which arguments it takes.

Summary

  • A small set of safe scripts (http-title, http-headers, ssl-cert, ssh-hostkey, ftp-anon, banner) answers many audit questions.
  • Script output is regular text that you can parse and turn into findings.
  • Certificate expiry, anonymous services and open resolvers are typical, valuable checks.
  • Know each script's category and arguments before you run it.

Next: Writing NSE Scripts