1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-30 03:19:02 +00:00

Move date/time functions from stdnse to datetime. See #517

This commit is contained in:
dmiller
2018-08-27 22:00:10 +00:00
parent 9c3e676871
commit 46eca7f35f
35 changed files with 282 additions and 255 deletions

View File

@@ -1,4 +1,4 @@
local os = require "os"
local datetime = require "datetime"
local shortport = require "shortport"
local stdnse = require "stdnse"
local tab = require "tab"
@@ -67,7 +67,7 @@ action = function(host, port)
if ( target.ALLOW_NEW_TARGETS ) then
target.add(node.address.host)
end
tab.addrow(response, ("%s:%d"):format(node.address.host, node.address.port), stdnse.format_timestamp(node.ts))
tab.addrow(response, ("%s:%d"):format(node.address.host, node.address.port), datetime.format_timestamp(node.ts))
end
if ( #response > 1 ) then

View File

@@ -63,7 +63,7 @@ action = function(host, port)
datetime.record_skew(host, ver.timestamp, request_time)
local result = stdnse.output_table()
result["Timestamp"] = stdnse.format_timestamp(ver.timestamp)
result["Timestamp"] = datetime.format_timestamp(ver.timestamp)
result["Network"] = NETWORK[ver.magic]
result["Version"] = ver.ver
result["Node Id"] = ver.nodeid

View File

@@ -1,4 +1,5 @@
local coroutine = require "coroutine"
local datetime = require "datetime"
local formulas = require "formulas"
local math = require "math"
local nmap = require "nmap"
@@ -103,9 +104,9 @@ hostaction = function(host)
if mean ~= 0 or stddev ~= 0 or nmap.verbosity() > 1 then
local out = {mean = mean, stddev = stddev, median = median}
return out, ("mean: %s, deviation: %s, median: %s"):format(
stdnse.format_time(mean),
stdnse.format_time(stddev),
stdnse.format_time(median)
datetime.format_time(mean),
datetime.format_time(stddev),
datetime.format_time(median)
)
end
end
@@ -169,10 +170,10 @@ postaction = function()
for mean, group in pairs(groups) do
-- Collapse the biggest group
if #groups > 1 and #group > host_count // 2 then
out[stdnse.format_time(mean)] = "Majority of systems scanned"
out[datetime.format_time(mean)] = "Majority of systems scanned"
elseif #group > 1 then
-- Only record groups of more than one system together
out[stdnse.format_time(mean)] = group
out[datetime.format_time(mean)] = group
end
end

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local math = require "math"
local match = require "match"
local nmap = require "nmap"
@@ -113,7 +114,7 @@ local function decodeTag(tag, lines)
"version" == tag ) then
return ("%s: %s"):format(long_names[tag], lines[1])
elseif ( "uptime" == tag ) then
return ("%s: %s"):format(long_names[tag], stdnse.format_time(lines[1] * 60))
return ("%s: %s"):format(long_names[tag], datetime.format_time(lines[1] * 60))
elseif ( "mem" == tag ) then
local total, used = table.unpack(stdnse.strsplit("%s", lines[1]))
if ( not(total) or not(used) ) then

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local gps = require "gps"
local match = require "match"
local nmap = require "nmap"
@@ -96,7 +97,7 @@ action = function(host, port)
end
local output = {
("Time of fix: %s"):format(stdnse.format_timestamp(gps.Util.convertTime(gpsinfo.date, gpsinfo.time))),
("Time of fix: %s"):format(datetime.format_timestamp(gps.Util.convertTime(gpsinfo.date, gpsinfo.time))),
("Coordinates: %.4f,%.4f"):format(tonumber(gpsinfo.latitude), tonumber(gpsinfo.longitude)),
("Speed: %s knots"):format(gpsinfo.speed)
}

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local http = require "http"
local os = require "os"
local shortport = require "shortport"
@@ -42,16 +43,16 @@ action = function(host, port)
if not response_date then
return
end
local response_time = stdnse.date_to_timestamp(response_date)
local response_time = datetime.date_to_timestamp(response_date)
local output_tab = stdnse.output_table()
output_tab.date = stdnse.format_timestamp(response_time, 0)
output_tab.date = datetime.format_timestamp(response_time, 0)
output_tab.delta = os.difftime(response_time, request_time)
datetime.record_skew(host, response_time, request_time)
local output_str = string.format("%s; %s from local time.",
response.header["date"], stdnse.format_difftime(os.date("!*t", response_time), os.date("!*t", request_time)))
response.header["date"], datetime.format_difftime(os.date("!*t", response_time), os.date("!*t", request_time)))
return output_tab, output_str
end

View File

@@ -1,5 +1,5 @@
local mobileme = require "mobileme"
local os = require "os"
local datetime = require "datetime"
local stdnse = require "stdnse"
local tab = require "tab"
@@ -74,7 +74,7 @@ action = function()
end
local ts
if ( info.timestamp and 1000 < info.timestamp ) then
ts = stdnse.format_timestamp(info.timestamp//1000)
ts = datetime.format_timestamp(info.timestamp//1000)
else
ts = "-"
end

View File

@@ -1,4 +1,5 @@
local coroutine = require "coroutine"
local datetime = require "datetime"
local math = require "math"
local nmap = require "nmap"
local os = require "os"
@@ -334,7 +335,7 @@ action = function(host, port)
end
stop = os.date("!*t")
dos_time = stdnse.format_difftime(stop, start)
dos_time = datetime.format_difftime(stop, start)
if DOSed then
if Reason == "slowloris" then
stdnse.debug2("Slowloris Attack stopped, building output")

View File

@@ -57,7 +57,7 @@ local filter = {
["pid"] = { name = "Process ID" },
["uptime"] = { name = "Uptime", func = function(v) return ("%d seconds"):format(v) end },
["time"] = { name = "Server time", func = stdnse.format_timestamp },
["time"] = { name = "Server time", func = datetime.format_timestamp },
["pointer_size"] = { name = "Architecture", func = function(v) return v .. " bit" end },
["rusage_user"] = { name = "Used CPU (user)" },
["rusage_system"] = { name = "Used CPU (system)"},

View File

@@ -112,7 +112,7 @@ action = function(host, port)
datetime.record_skew(host, tstamp, recvtime)
output["receive time stamp"] = stdnse.format_timestamp(tstamp)
output["receive time stamp"] = datetime.format_timestamp(tstamp)
end
status, bufrlres = comm.exchange(host, port, rlreq, {timeout=TIMEOUT})

View File

@@ -1,4 +1,5 @@
local comm = require "comm"
local datetime = require "datetime"
local nmap = require "nmap"
local shortport = require "shortport"
local stdnse = require "stdnse"
@@ -174,7 +175,7 @@ local function formattime(data)
if not time then
return
end
return stdnse.format_timestamp(time)
return datetime.format_timestamp(time)
end
local function formatvalue(key, nson)

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local stdnse = require "stdnse"
local shortport = require "shortport"
local comm = require "comm"
@@ -192,7 +193,7 @@ local function format_dimensions(res)
values[ params[counter] ] = val
end
res["Date and Time"] = stdnse.format_timestamp(values)
res["Date and Time"] = datetime.format_timestamp(values)
end
if res["Device Type"] then

View File

@@ -59,6 +59,6 @@ action = function(host, port)
nmap.set_port_version(host, port, "hardmatched")
end
return stdnse.format_timestamp(stamp)
return datetime.format_timestamp(stamp)
end
end

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local rpc = require "rpc"
local shortport = require "shortport"
local stdnse = require "stdnse"
@@ -108,10 +109,10 @@ local function rusers2_entry(comm, data, pos)
if not pos then return fail(entry.host) end
pos, entry.time = rpc.Util.unmarshall_uint32(data, pos)
entry.time = stdnse.format_timestamp(entry.time)
entry.time = datetime.format_timestamp(entry.time)
pos, entry.idle = rpc.Util.unmarshall_uint32(data, pos)
entry.idle = stdnse.format_time(entry.idle)
entry.idle = datetime.format_time(entry.idle)
return pos, entry, data
end

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local msrpc = require "msrpc"
local smb = require "smb"
local stdnse = require "stdnse"
@@ -306,14 +307,14 @@ action = function(host)
if(time == 0) then
time = "[just logged in, it's probably you]"
else
time = stdnse.format_time(time)
time = datetime.format_time(time)
end
local idle_time = sessions[i]['idle_time']
if(idle_time == 0) then
idle_time = "[not idle]"
else
idle_time = stdnse.format_time(idle_time)
idle_time = datetime.format_time(idle_time)
end
table.insert(sessions_output, string.format("%s is connected from %s for %s, idle for %s", sessions[i]['user'], sessions[i]['client'], time, idle_time))

View File

@@ -161,7 +161,7 @@ action = function(host)
response.domain = result.domain
response.server = result.server
if result.time and result.timezone then
response.date = stdnse.format_timestamp(result.time, result.timezone * 60 * 60)
response.date = datetime.format_timestamp(result.time, result.timezone * 60 * 60)
datetime.record_skew(host, result.time - result.timezone * 60 * 60, request_time)
end
response.fqdn = result.fqdn

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local msrpc = require "msrpc"
local os = require "os"
local smb = require "smb"
@@ -156,7 +157,7 @@ local function get_info_registry(host)
result['status-currentversion'], result['currentversion'] = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "CurrentVersion")
result['status-installdate'], result['installdate'] = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "InstallDate")
if(result['status-installdate'] ~= false) then
result['installdate'] = stdnse.format_timestamp(result['installdate'])
result['installdate'] = datetime.format_timestamp(result['installdate'])
end
result['status-productname'], result['productname'] = reg_get_value(smbstate, openhklm_result['handle'], "Software\\Microsoft\\Windows NT\\CurrentVersion", "Productname")

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local datafiles = require "datafiles"
local ipOps = require "ipOps"
local nmap = require "nmap"
@@ -129,7 +130,7 @@ action = function (host, port)
output.engineIDData = stdnse.tohex(engineID:sub(5))
end
output.snmpEngineBoots = decoded[2]
output.snmpEngineTime = stdnse.format_time(decoded[3])
output.snmpEngineTime = datetime.format_time(decoded[3])
port.version = port.version or {}
port.version.service = "snmp"

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local nmap = require "nmap"
local shortport = require "shortport"
local snmp = require "snmp"
@@ -62,7 +63,7 @@ action = function(host, port)
return
end
result = result .. "\n" .. string.format(" System uptime: %s (%s timeticks)", stdnse.format_time(uptime, 100), tostring(uptime))
result = result .. "\n" .. string.format(" System uptime: %s (%s timeticks)", datetime.format_time(uptime, 100), tostring(uptime))
return result
end

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local bin = require "bin"
local nmap = require "nmap"
local shortport = require "shortport"
@@ -90,7 +91,7 @@ local date_xlate = {
sec = 7
}
-- translate date parts to positional indices for stdnse.format_timestamp
-- translate date parts to positional indices for datetime.format_timestamp
local date_metatab = {
__index = function (t, k)
return t[date_xlate[k]]
@@ -123,7 +124,7 @@ local function process_answer( tbl )
local sw_item = {
["name"] = v.value,
["install_date"] = stdnse.format_timestamp(install_date_tab)
["install_date"] = datetime.format_timestamp(install_date_tab)
}
setmetatable(sw_item, sw_metatab)

View File

@@ -1,3 +1,4 @@
local datetime = require "datetime"
local nmap = require "nmap"
local shortport = require "shortport"
local sslcert = require "sslcert"
@@ -143,7 +144,7 @@ function date_to_string(date)
if type(date) == "string" then
return string.format("Can't parse; string is \"%s\"", date)
else
return stdnse.format_timestamp(date)
return datetime.format_timestamp(date)
end
end
@@ -218,7 +219,7 @@ local function output_tab(cert)
if type(v)=="string" then
o.validity[k] = v
else
o.validity[k] = stdnse.format_timestamp(v)
o.validity[k] = datetime.format_timestamp(v)
end
end
o.md5 = stdnse.tohex(cert:digest("md5"))

View File

@@ -140,7 +140,7 @@ local get_time_sample = function (host, port)
-- extract time from response
local tstatus, ttm = extract_time(response)
if not tstatus then return nil end
stdnse.debug(detail_debug, "TLS sample: %s", stdnse.format_timestamp(ttm, 0))
stdnse.debug(detail_debug, "TLS sample: %s", datetime.format_timestamp(ttm, 0))
return {target=ttm, scanner=stm, delta=os.difftime(ttm, stm)}
end
@@ -205,11 +205,11 @@ action = function(host, port)
datetime.record_skew(host, tm.target, tm.scanner)
local output = {
date = stdnse.format_timestamp(tm.target, 0),
date = datetime.format_timestamp(tm.target, 0),
delta = tm.delta,
}
return output,
string.format("%s; %s from scanner time.", output.date,
stdnse.format_difftime(os.date("!*t", tm.target),
datetime.format_difftime(os.date("!*t", tm.target),
os.date("!*t", tm.scanner)))
end