diff --git a/scripts/ntp-info.nse b/scripts/ntp-info.nse
index 6ffbb1ad9..d34b15dc5 100644
--- a/scripts/ntp-info.nse
+++ b/scripts/ntp-info.nse
@@ -31,7 +31,27 @@ documentation of the protocol.
-- | system: Linux/2.6.24-24-server
-- | stratum: 2
-- |_ refid: 195.145.119.188
-
+--
+-- @xmloutput
+-- 2013-10-18T18:03:05
+-- ntpd 4.2.6p3@1.2290-o Tue Jun 5 20:12:11 UTC 2012 (1)
+-- i686
+-- Linux/3.9.3-24
+-- 3
+-- 16
+-- -20
+-- 0.000
+-- 2502.720
+-- INIT
+-- 0x00000000.00000000
+-- 0xd60bf655.4cc0ba51
+-- 0
+-- 3
+-- 3
+-- 0.000
+-- -46.015
+-- 0.001
+-- 0.000
author = "Richard Sammet"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
@@ -45,23 +65,13 @@ portrule = shortport.port_or_service(123, "ntp", {"udp", "tcp"})
-- there's no response.
local TIMEOUT = 5000
--- Transform an array into a table where the array's values all map to true.
-local function make_set(a)
- local i, v, result
- result = {}
- for i, v in ipairs(a) do
- result[v] = true
- end
- return result
-end
-
-- Only these fields from the response are displayed with default verbosity.
-local DEFAULT_FIELDS = make_set({"version", "processor", "system", "refid", "stratum"})
+local DEFAULT_FIELDS = {"version", "processor", "system", "refid", "stratum"}
action = function(host, port)
local status
local buftres, bufrlres
- local output = {}
+ local output = stdnse.output_table()
-- This is a ntp v4 mode3 (client) date/time request.
local treq = string.char(0xe3, 0x00, 0x04, 0xfa, 0x00, 0x01, 0x00, 0x00,
@@ -89,7 +99,7 @@ action = function(host, port)
-- the NTP4 reference above.
tstamp = sec - 2208988800 + frac / 0x10000000
- table.insert(output, string.format("receive time stamp: %s", stdnse.format_timestamp(tstamp)))
+ output["receive time stamp"] = stdnse.format_timestamp(tstamp)
end
status, bufrlres = comm.exchange(host, port, rlreq, {proto=port.protocol, timeout=TIMEOUT})
@@ -106,16 +116,29 @@ action = function(host, port)
-- This parsing is not quite right with respect to quoted strings.
-- Backslash escapes should be interpreted inside strings and commas should
-- be allowed inside them.
- for k, q, v in string.gmatch(data, "%s*(%w+)=(\"?)([^,\"]*)%2,?") do
+ for k, q, v in string.gmatch(data, "%s*(%w+)=(\"?)([^,\"\r\n]*)%2,?") do
if DEFAULT_FIELDS[k] or nmap.verbosity() then
- table.insert(output, string.format("%s: %s", k, v))
+ output[k] = v
end
end
end
if(#output > 0) then
+ stdnse.print_debug("Test len: %d", #output)
nmap.set_port_state(host, port, "open")
- return stdnse.format_output(true, output)
+ if nmap.verbosity() < 1 then
+ local mt = getmetatable(output)
+ mt["__tostring"] = function(t)
+ local out = {}
+ for _,k in ipairs(DEFAULT_FIELDS) do
+ if output[k] ~= nil then
+ table.insert(out, ("%s: %s"):format(k, output[k]))
+ end
+ end
+ return "\n " .. table.concat(out, "\n ")
+ end
+ end
+ return output
else
return nil
end