0 ­ˆò�þZ•ÇnQ8ëq‘â¼@?ñ „Ÿð¿ó?÷­--- -- Minimalistic DHCP6 (Dynamic Host Configuration Protocol for IPv6) -- implementation supporting basic DHCP6 Solicit requests The library -- is structured around the following classes: -- * DHCP6.Option - DHCP6 options encoders (for requests) and decoders -- (for responses) -- * DHCP6.Request - DHCP6 request encoder and decoder -- * DHCP6.Response - DHCP6 response encoder and decoder -- * Helper - The helper class, primary script interface -- -- The following sample code sends a DHCP6 Solicit request and returns a -- response suitable for script output: -- -- local helper = DHCP6.Helper:new("eth0") -- local status, response = helper:solicit() -- if ( status ) then -- return stdnse.format_output(true, response) -- end -- -- -- @author Patrik Karlsson -- local datetime = require "datetime" local ipOps = require "ipOps" local math = require "math" local nmap = require "nmap" local os = require "os" local stdnse = require "stdnse" local string = require "string" local table = require "table" _ENV = stdnse.module("dhcp6", stdnse.seeall) DHCP6 = {} -- DHCP6 request and response types DHCP6.Type = { SOLICIT = 1, ADVERTISE = 2, REQUEST = 3, } -- DHCP6 type as string DHCP6.TypeStr = { [DHCP6.Type.SOLICIT] = "Solicit", [DHCP6.Type.ADVERTISE] = "Advertise", [DHCP6.Type.REQUEST] = "Request", } -- DHCP6 option types DHCP6.OptionTypes = { OPTION_CLIENTID = 0x01, OPTION_SERVERID = 0x02, OPTION_IA_NA = 0x03, OPTION_IAADDR = 0x05, OPTION_ELAPSED_TIME = 0x08, OPTION_STATUS_CODE = 0x0d, OPTION_DNS_SERVERS = 0x17, OPTION_DOMAIN_LIST = 0x18, OPTION_IA_PD = 0x19, OPTION_SNTP_SERVERS = 0x1f, OPTION_CLIENT_FQDN = 0x27, } local DHCP6_EPOCH = os.time({year=2000, day=1, month=1, hour=0, min=0, sec=0}) -- DHCP6 options DHCP6.Option = { [DHCP6.OptionTypes.OPTION_ELAPSED_TIME] = { -- Create a new class instance -- @param time in ms since last request -- @return o new instance of class new = function(self, time) local o = { type = DHCP6.OptionTypes.OPTION_ELAPSED_TIME, time = time, -- in case no time was created, we need this to be able to -- calculate time since instantiation created = os.time(), } setmetatable(o, self) self.__index = self return o end, -- Converts option to a string -- @return str string containing the class instance as string __tostring = function(self) local data if ( self.time ) then data = string.pack(">I2", self.time) else data = string.pack(">I2", (os.time() - self.created) * 1000) end return string.pack(">I2s2", self.type, data) end, }, [DHCP6.OptionTypes.OPTION_CLIENTID] = { -- Create a new class instance -- @param mac string containing the mac address -- @param duid number the duid of the client -- @param hwtype number the hwtype of the client -- @param time number time since 2000-01-01 00:00:00 -- @return o new instance of class new = function(self, mac, duid, hwtype, time) local o = { type = DHCP6.OptionTypes.OPTION_CLIENTID, duid = duid or 1, hwtype = hwtype or 1, time = time or os.time() - DHCP6_EPOCH, mac = mac, } setmetatable(o, self) self.__index = self return o end, -- Parse the data string and create an instance of the class -- @param data string containing the data as received over the socket -- @return opt new instance of option parse = function(data) local opt = DHCP6.Option[DHCP6.OptionTypes.OPTION_CLIENTID]:new() local pos opt.duid, pos = string.unpack(">I2", data, pos) if ( 1 ~= opt.duid ) then stdnse.debug1("Unexpected DUID type (%d)", opt.duid) return end opt.hwtype, opt.time = string.unpack(">I2I4", data, pos) opt.mac = data:sub(pos) opt.time = opt.time + DHCP6_EPOCH return opt end, -- Convert