From 0896c64baebd675446b09a5092af15b296de08b4 Mon Sep 17 00:00:00 2001 From: dmiller Date: Wed, 25 May 2016 20:14:13 +0000 Subject: [PATCH] Add xml output to resolveall, improve warnings --- scripts/resolveall.nse | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/scripts/resolveall.nse b/scripts/resolveall.nse index a9484339e..d0f93d1c3 100644 --- a/scripts/resolveall.nse +++ b/scripts/resolveall.nse @@ -26,6 +26,16 @@ record) returned for each host name. -- | 74.125.39.105 -- | 74.125.39.104 -- |_ Successfully added 6 new targets +-- @xmloutput +-- 4 +-- +--
+-- 74.125.39.106 +-- 74.125.39.147 +-- 74.125.39.99 +-- 74.125.39.103 +--
+-- author = "Kris Katterjohn" @@ -36,7 +46,7 @@ categories = {"safe", "discovery"} prerule = function() if not stdnse.get_script_args("resolveall.hosts") then - stdnse.debug3("Skipping '%s' %s, 'resolveall.hosts' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE) + stdnse.verbose1("Skipping '%s', missing required argument 'resolveall.hosts'.", SCRIPT_NAME) return false end return true @@ -50,7 +60,7 @@ local addtargets = function(list) if st then sum = sum + 1 else - stdnse.debug1("Couldn't add target " .. t .. ": " .. err) + stdnse.debug1("Couldn't add target %s: %s", t, err) end end @@ -64,25 +74,29 @@ action = function() hosts = {hosts} end - local sum, output = 0, {} + local sum = 0 + local output = {} + local xmloutput = {} for _, host in ipairs(hosts) do local status, list = nmap.resolve(host, nmap.address_family()) if status and #list > 0 then if target.ALLOW_NEW_TARGETS then sum = sum + addtargets(list) end - table.insert(output, - string.format("Host '%s' resolves to:", host)) + xmloutput[host] = list + table.insert(output, string.format("Host '%s' resolves to:", host)) table.insert(output, list) end end + xmloutput = { + hosts = xmloutput, + newtargets = sum or 0, + } if sum > 0 then - table.insert(output, - string.format("Successfully added %d new targets", - tostring(sum))) + table.insert(output, string.format("Successfully added %d new targets", sum)) else table.insert(output, "Use the 'newtargets' script-arg to add the results as targets") end - return stdnse.format_output(true, output) + return xmloutput, stdnse.format_output(true, output) end