The bin
and packet
NSE libraries must be mentioned now because they support methods that are useful when manipulating raw packets and generally when working with network I/O operations. In this section, we will learn about binary data strings, handy conversions supported by the libraries, and raw packet and frame generation.
Once you start working with network I/O operations, you'll quickly realize the need to encode binary data strings correctly. NSE has the bin
library (http://nmap.org/nsedoc/lib/bin.html) that helps us pack and unpack formatted binary data strings. This library contains only the pack()
and
unpack()
methods. We will learn how flexible and useful they are.
The following are the operator characters supported by the library:
H
:H
represents a hex stringB
:B
represents a bit stringx
:x
represents a null bytez
:z
represents a zero-terminated stringp
:p
represents a string preceded by a 1-byte integer lengthP
:P
represents...