1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-16 11:29:02 +00:00

Add xmloutput for ntp-info.nse

This commit is contained in:
dmiller
2013-10-18 18:35:05 +00:00
parent 25a2a184c4
commit 34cd23e101

View File

@@ -31,7 +31,27 @@ documentation of the protocol.
-- | system: Linux/2.6.24-24-server
-- | stratum: 2
-- |_ refid: 195.145.119.188
--
-- @xmloutput
-- <elem key="receive time stamp">2013-10-18T18:03:05</elem>
-- <elem key="version">ntpd 4.2.6p3@1.2290-o Tue Jun 5 20:12:11 UTC 2012 (1)</elem>
-- <elem key="processor">i686</elem>
-- <elem key="system">Linux/3.9.3-24</elem>
-- <elem key="leap">3</elem>
-- <elem key="stratum">16</elem>
-- <elem key="precision">-20</elem>
-- <elem key="rootdelay">0.000</elem>
-- <elem key="rootdisp">2502.720</elem>
-- <elem key="refid">INIT</elem>
-- <elem key="reftime">0x00000000.00000000</elem>
-- <elem key="clock">0xd60bf655.4cc0ba51</elem>
-- <elem key="peer">0</elem>
-- <elem key="tc">3</elem>
-- <elem key="mintc">3</elem>
-- <elem key="offset">0.000</elem>
-- <elem key="frequency">-46.015</elem>
-- <elem key="jitter">0.001</elem>
-- <elem key="wander">0.000</elem>
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