Book Image

Mastering the Nmap Scripting Engine

By : Paulino Calderon
Book Image

Mastering the Nmap Scripting Engine

By: Paulino Calderon

Overview of this book

Table of Contents (23 chapters)
Mastering the Nmap Scripting Engine
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Scan Phases
Script Categories
Nmap Options Mind Map
References
Index

Writing your own version detection scripts


When writing our own NSE scripts, we will use the API provided by Nmap to interact with the host and port database. To write a version script, we simply need to do the following:

  1. Add your script to the category version.

  2. Write the corresponding portrule.

  3. Set the port version in our script after successful detection.

Defining the category of a version detection script

The first step is very straightforward. In your NSE script, add the category field as follows:

category = {"version"}

The category field is actually a regular Lua table, so feel free to add more categories to your script if necessary.

Defining the portrule of a version detection script

The next important thing is to have a portrule matching the desired service. Keep in mind that we have function aliases that will help define these portrules, such as:

  • shortport.portnumber(port, protos, states)

  • shortport.version_port_or_service(ports, services, protos, states)

  • shortport.port_or_service(ports, services...