Book Image

NMAP Essentials

By : David Shaw
Book Image

NMAP Essentials

By: David Shaw

Overview of this book

Table of Contents (17 chapters)
Nmap Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Triggering functions – the rule


The rule or portrule section of an Nmap script determines when the action should take place (which we'll cover in the next section). It's important to define this clearly so that we are confident that our script will run every time we need it to (based on port number and version). There are two ways to accomplish this type of rule: standard portrule documentation, and a helper library built in the NSE called shortport.

Defining a rule is actually very simple, depending on what we're looking for. In the case of our robots.txt detection script (aptly named robots.nse), we just want to trigger on port 80 to see if robots.txt exists.

If we were writing a production script, rather than a proof of concept, it would probably be a good idea to use shortport's port or service functionality to trigger on port 80, or any web server that Nmap detects through its underlying functionality. However, in our case, we can simply define something much easier to digest:

  portrule...