From ab654ecc341518181eea96f7804861c4f2ea06f3 Mon Sep 17 00:00:00 2001 From: ron Date: Wed, 7 Apr 2010 21:47:22 +0000 Subject: [PATCH] Fixed a bug in dhcp-discover -- the read_boolean() function appears to never have worked, but I didn't run into anything that returned a boolean value until Brandon tried running it. It now handles booleans properly, along with a lot of extra debug output (especially on -d2 and higher) --- scripts/dhcp-discover.nse | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/dhcp-discover.nse b/scripts/dhcp-discover.nse index 91be62750..8495e216d 100644 --- a/scripts/dhcp-discover.nse +++ b/scripts/dhcp-discover.nse @@ -195,11 +195,11 @@ local function read_boolean(data, pos, length) if(result == nil) then stdnse.print_debug(1, "dhcp-discover: Couldn't read the 1-byte boolean") - return nil + return pos, nil elseif(result == 0) then - return "false" + return pos, "false" else - return "true" + return pos, "true" end end @@ -499,7 +499,7 @@ local function dhcp_parse(data) -- Receive the first bit and make sure we got the correct operation back pos, result['op'], result['htype'], result['hlen'], result['hops'] = bin.unpack(">CCCC", data, pos) if(result['op'] ~= 2) then - return false, string.format("DHCP server returned invalid reply ('op' wasn't BOOTREPLY (0x%02x))", result['op']) + return false, string.format("DHCP server returned invalid reply ('op' wasn't BOOTREPLY (it was 0x%02x))", result['op']) end -- Confirm the transaction id @@ -550,6 +550,9 @@ local function dhcp_parse(data) pos = pos + length else -- Call the function to parse the option, and insert the result into our results table + local value + + stdnse.print_debug(2, "dhcp-discover: Attempting to parse %s", action['name']) pos, value = action['func'](data, pos, length) if(nmap.verbosity() == 0 and action.default == false) then @@ -715,6 +718,7 @@ end action = function(host, port) local status, results = go(host, port) + if(status == false) then return stdnse.format_output(false, results) end