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

Examples of version detection scripts


Now we will briefly cover a few examples of different NSE version scripts to familiarize ourselves with the structure and required components.

NSE script – modbus-discover

The modbus-discover script was written by Alexander Rudakov to retrieve device information through the modbus protocol. Modbus is very popular among Supervisory Control And Data Acquisition (SCADA) systems. The script attempts to discover valid Slave IDs (SIDs) and retrieve additional device information:

action = function(host, port)
    -- If false, stop after first sid.
    local aggressive = stdnse.get_script_args('modbus-discover.aggressive')

    local opts = {timeout=2000}
    local results = {}

    for sid = 1, 246 do
        stdnse.print_debug(3, "Sending command with sid = %d", sid)
        local rsid = form_rsid(sid, 0x11, "")

        local status, result = comm.exchange(host, port, rsid, opts)
        if ( status and (#result >= 8) ) then
            local ret_code =...