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

Raw packet handling and NSE sockets


You are now familiar with NSE sockets and raw packet handling. Now we will review an example of everything we have seen in this chapter working together in one script. The following script, broadcast-dhcp-discover.nse, illustrates the usage of connection-oriented sockets, raw packet reception, manipulation, and frame building. Pay close attention to the bin.pack(), pcap_receive(), and sendto() method calls, and the helper functions that perform error checking during script execution.

The script starts by declaring its library dependencies and required script fields such as description, author, and categories:

local bin = require "bin"
local coroutine = require "coroutine"
local dhcp = require "dhcp"
local ipOps = require "ipOps"
local math = require "math"
local nmap = require "nmap"
local packet = require "packet"
local stdnse = require "stdnse"
local string = require "string"
local table = require "table"

description = [[
Sends a DHCP request to the broadcast...