Chapter 9. Nmap Scripting Engine | Nmap Network Scanning (2024)

  • Nmap Network Scanning
  • Chapter9.Nmap Scripting Engine

Table of Contents

  • Introduction
  • Usage and Examples
    • Script Categories
    • Script Types and Phases
    • Command-line Arguments
    • Script Selection
    • Arguments to Scripts
    • Complete Examples
  • Script Format
    • description Field
    • categories Field
    • author Field
    • license Field
    • dependencies Field
    • Rules
    • Action
    • Environment Variables
  • Script Language
    • Lua Base Language
  • NSE Scripts
  • NSE Libraries
    • List of All Libraries
    • Hacking NSE Libraries
    • Adding C Modules to Nselib
  • Nmap API
    • Information Passed to a Script
    • Network I/O API
      • Connect-style network I/O
      • Raw packet network I/O
    • Structured and Unstructured Output
    • Exception Handling
    • The Registry
  • Script Writing Tutorial
    • The Head
    • The Rule
    • The Action
  • Writing Script Documentation (NSEDoc)
    • NSE Documentation Tags
  • Script Parallelism in NSE
    • Worker Threads
    • Mutexes
    • Condition Variables
    • Collaborative Multithreading
      • The base thread
  • Version Detection Using NSE
  • Example Script: finger
  • Implementation Details
    • Initialization Phase
    • Script Scanning

Introduction

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. Users can rely on the growing and diverse set of scripts distributed with Nmap, or write their own to meet custom needs.

We designed NSE to be versatile, with the following tasks in mind:

Network discovery

This is Nmap's bread and butter. Examples include looking up whois data based on the target domain, querying ARIN, RIPE, or APNIC for the target IP to determine ownership, performing identd lookups on open ports, SNMP queries, and listing available NFS/SMB/RPC shares and services.

More sophisticated version detection

The Nmap version detection system (Chapter7, Service and Application Version Detection) is able to recognize thousands of different services through its probe and regular expression signature based matching system, but it cannot recognize everything. For example, identifying the Skype v2 service requires two independent probes, which version detection isn't flexible enough to handle. Nmap could also recognize more SNMP services if it tried a few hundred different community names by brute force. Neither of these tasks are well suited to traditional Nmap version detection, but both are easily accomplished with NSE. For these reasons, version detection now calls NSE by default to handle some tricky services. This is described in the section called “Version Detection Using NSE”.

Vulnerability detection

When a new vulnerability is discovered, you often want to scan your networks quickly to identify vulnerable systems before the bad guys do. While Nmap isn't a comprehensive vulnerability scanner, NSE is powerful enough to handle even demanding vulnerability checks. When the Heartbleed bug affected hundreds of thousands of systems worldwide, Nmap's developers responded with the ssl-heartbleed detection script within 2 days. Many vulnerability detection scripts are already available and we plan to distribute more as they are written.

Backdoor detection

Many attackers and some automated worms leave backdoors to enable later reentry. Some of these can be detected by Nmap's regular expression based version detection, but more complex worms and backdoors require NSE's advanced capabilities to reliably detect. NSE has been used to detect the Double Pulsar NSA backdoor in SMB and backdoored versions of UnrealIRCd, vsftpd, and ProFTPd.

Vulnerability exploitation

As a general scripting language, NSE can even be used to exploit vulnerabilities rather than just find them. The capability to add custom exploit scripts may be valuable for some people (particularly penetration testers), though we aren't planning to turn Nmap into an exploitation framework such as Metasploit.

These listed items were our initial goals, and we expect Nmap users to come up with even more inventive uses for NSE.

Scripts are written in the embedded Lua programming language, version 5.3. The language itself is well documented in the books Programmingin Lua, Fourth Edition and Lua5.2 Reference Manual.The reference manual, updated for Lua 5.3, is also freely available online, as is the first edition of Programming in Lua. Given the availability of these excellent general Lua programming references, this document only covers aspects and extensions specific to Nmap's scripting engine.

NSE is activated with the -sC option (or --script if you wish to specify a custom set of scripts) and results are integrated into Nmap normal and XML output.

A typical script scan is shown in the Example9.1. Service scripts producing output in this example are ssh-hostkey, which provides the system's RSA and DSA SSH keys, and rpcinfo, which queries portmapper to enumerate available services. The only host script producing output in this example is smb-os-discovery, which collects a variety of information from SMB servers. Nmap discovered all of this information in a third of a second.

Example9.1.Typical NSE output

# nmap -sC -p22,111,139 -T4 localhostStarting Nmap ( https://nmap.org )Nmap scan report for flog (127.0.0.1)PORT STATE SERVICE22/tcp open ssh| ssh-hostkey: 1024 b1:36:0d:3f:50:dc:13:96:b2:6e:34:39:0d:9b:1a:38 (DSA)|_2048 77:d0:20:1c:44:1f:87:a0:30:aa:85:cf:e8:ca:4c:11 (RSA)111/tcp open rpcbind| rpcinfo: | 100000 2,3,4 111/udp rpcbind | 100024 1 56454/udp status |_100000 2,3,4 111/tcp rpcbind 139/tcp open netbios-ssnHost script results:| smb-os-discovery: Unix| LAN Manager: Samba 3.0.31-0.fc8|_Name: WORKGROUPNmap done: 1 IP address (1 host up) scanned in 0.33 seconds

A 38-minute video introduction to NSE is available athttps://nmap.org/presentations/BHDC10/. Thispresentation was given by Fyodor and David Fifield at Defcon and theBlack Hat Briefings in 2010.

Chapter 9. Nmap Scripting Engine | Nmap Network Scanning (2024)
Top Articles
Dragon Age: Inquisition - God Of Secrets Side Quest Walkthrough
Are Apartment Key Fobs Waterproof? Protecting and Preserving Your Access
Cranes For Sale in United States| IronPlanet
Durr Burger Inflatable
Bild Poster Ikea
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Skycurve Replacement Mat
Gomoviesmalayalam
Yogabella Babysitter
Gamevault Agent
Pangphip Application
Ati Capstone Orientation Video Quiz
877-668-5260 | 18776685260 - Robocaller Warning!
Owatc Canvas
Hallowed Sepulchre Instances & More
CA Kapil 🇦🇪 Talreja Dubai on LinkedIn: #businessethics #audit #pwc #evergrande #talrejaandtalreja #businesssetup…
Belle Delphine Boobs
Gma Deals And Steals Today 2022
Nj State Police Private Detective Unit
Nissan Rogue Tire Size
使用 RHEL 8 时的注意事项 | Red Hat Product Documentation
Nick Pulos Height, Age, Net Worth, Girlfriend, Stunt Actor
1v1.LOL - Play Free Online | Spatial
Grayling Purnell Net Worth
Foxy Brown 2025
Pjs Obits
Jobs Hiring Near Me Part Time For 15 Year Olds
Understanding Gestalt Principles: Definition and Examples
Airline Reception Meaning
Meridian Owners Forum
Booknet.com Contract Marriage 2
Rural King Credit Card Minimum Credit Score
Delta Math Login With Google
Nurtsug
Springfield.craigslist
Rocketpult Infinite Fuel
Polk County Released Inmates
Go Upstate Mugshots Gaffney Sc
Game8 Silver Wolf
MSD Animal Health Hub: Nobivac® Rabies Q & A
Linda Sublette Actress
sacramento for sale by owner "boats" - craigslist
Subdomain Finder
Conan Exiles Tiger Cub Best Food
Spurs Basketball Reference
Arch Aplin Iii Felony
Sapphire Pine Grove
Secrets Exposed: How to Test for Mold Exposure in Your Blood!
De boeken van Val McDermid op volgorde
25100 N 104Th Way
What your eye doctor knows about your health
Buildapc Deals
Latest Posts
Article information

Author: Cheryll Lueilwitz

Last Updated:

Views: 6014

Rating: 4.3 / 5 (74 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Cheryll Lueilwitz

Birthday: 1997-12-23

Address: 4653 O'Kon Hill, Lake Juanstad, AR 65469

Phone: +494124489301

Job: Marketing Representative

Hobby: Reading, Ice skating, Foraging, BASE jumping, Hiking, Skateboarding, Kayaking

Introduction: My name is Cheryll Lueilwitz, I am a sparkling, clean, super, lucky, joyous, outstanding, lucky person who loves writing and wants to share my knowledge and understanding with you.