mirror of
https://github.com/nmap/nmap.git
synced 2026-10-24 04:43:03 +00:00
Use stdnse.format_timestamp in scripts that output structured dates.
This commit is contained in:
parent
e9b2a8aa5d
commit
87bce81b8c
4 changed files with 15 additions and 20 deletions
|
|
@ -18,7 +18,7 @@ sent, so the difference includes at least the duration of one RTT.
|
|||
-- |_http-date: Thu, 02 Aug 2012 22:07:12 GMT; -3m51s from local time.
|
||||
--
|
||||
-- @xmloutput
|
||||
-- <elem key="date">2012-08-02T23:07:12Z</elem>
|
||||
-- <elem key="date">2012-08-02T23:07:12+00:00</elem>
|
||||
-- <elem key="delta">-231</elem>
|
||||
|
||||
author = "David Fifield"
|
||||
|
|
@ -31,8 +31,7 @@ categories = {"discovery", "safe"}
|
|||
portrule = shortport.http
|
||||
|
||||
action = function(host, port)
|
||||
-- Get the local date in UTC.
|
||||
local request_date = os.date("!*t")
|
||||
local request_time = os.time()
|
||||
local response = http.get(host, port, "/")
|
||||
if not response.status or not response.header["date"] then
|
||||
return
|
||||
|
|
@ -42,14 +41,14 @@ action = function(host, port)
|
|||
if not response_date then
|
||||
return
|
||||
end
|
||||
local response_time = stdnse.date_to_timestamp(response_date)
|
||||
|
||||
local output_tab = stdnse.output_table()
|
||||
-- ISO 8601 date and time.
|
||||
output_tab.date = os.date("%Y-%m-%dT%H:%M:%SZ", os.time(response_date))
|
||||
output_tab.delta = os.difftime(os.time(response_date), os.time(request_date))
|
||||
output_tab.date = stdnse.format_timestamp(response_time, 0)
|
||||
output_tab.delta = os.difftime(response_time, request_time)
|
||||
|
||||
local output_str = string.format("%s; %s from local time.",
|
||||
response.header["date"], stdnse.format_difftime(response_date, request_date))
|
||||
response.header["date"], stdnse.format_difftime(os.date("!*t", response_time), os.date("!*t", request_time)))
|
||||
|
||||
return output_tab, output_str
|
||||
end
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ will speed up the script on targets that do not allow guest access.
|
|||
-- | FQDN: Sql2008.lab.test.local
|
||||
-- | NetBIOS computer name: SQL2008
|
||||
-- | NetBIOS domain name: LAB
|
||||
-- |_ System time: 2011-04-20 13:34:06 UTC-5
|
||||
-- |_ System time: 2011-04-20T13:34:06-05:00
|
||||
--
|
||||
--@xmloutput
|
||||
-- <elem key="OS">Windows Server (R) 2008 Standard 6001 Service Pack 1 (Windows Server (R) 2008 Standard 6.0)</elem>
|
||||
|
|
@ -67,7 +67,7 @@ will speed up the script on targets that do not allow guest access.
|
|||
-- <elem key="FQDN">Sql2008.lab.test.local</elem>
|
||||
-- <elem key="NetBIOS computer name">SQL2008</elem>
|
||||
-- <elem key="NetBIOS domain name">LAB</elem>
|
||||
-- <elem key="System time">2011-04-20 13:34:06 UTC-5</elem>
|
||||
-- <elem key="System time">2011-04-20T13:34:06-05:00</elem>
|
||||
|
||||
author = "Ron Bowes"
|
||||
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
||||
|
|
@ -125,8 +125,8 @@ action = function(host)
|
|||
if (result['os'] and result['lanmanager']) then
|
||||
os_string = string.format( "%s (%s)", get_windows_version( result['os'] ), result['lanmanager'] )
|
||||
end
|
||||
if (result['date'] and result['timezone_str']) then
|
||||
time_string = string.format("%s%+03d%02d", os.date("%Y-%m-%dT%H:%M:%S", result.time), result.timezone, math.abs(math.fmod(result.timezone, 1)) * 60)
|
||||
if (result['time'] and result['timezone']) then
|
||||
time_string = stdnse.format_timestamp(result.time, result.timezone * 60 * 60)
|
||||
end
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -96,8 +96,8 @@ certificate.
|
|||
-- <elem key="bits">2048</elem>
|
||||
-- </table>
|
||||
-- <table key="validity">
|
||||
-- <elem key="notBefore">2011-03-23T00:00:00Z</elem>
|
||||
-- <elem key="notAfter">2013-04-01T23:59:59Z</elem>
|
||||
-- <elem key="notBefore">2011-03-23T00:00:00+00:00</elem>
|
||||
-- <elem key="notAfter">2013-04-01T23:59:59+00:00</elem>
|
||||
-- </table>
|
||||
-- <elem key="md5">bf47cecad861efa77d1488ad4a73cb5b</elem>
|
||||
-- <elem key="sha1">d8465221467a0d153df09f2eaf6d439002139a68</elem>
|
||||
|
|
@ -183,10 +183,6 @@ local function name_to_table(name)
|
|||
return output
|
||||
end
|
||||
|
||||
local function format_time(t)
|
||||
return os.date("%Y-%m-%dT%H:%M:%SZ", os.time(t))
|
||||
end
|
||||
|
||||
local function output_tab(cert)
|
||||
local o = stdnse.output_table()
|
||||
o.subject = name_to_table(cert.subject)
|
||||
|
|
@ -194,7 +190,7 @@ local function output_tab(cert)
|
|||
o.pubkey = cert.pubkey
|
||||
o.validity = {}
|
||||
for k, v in pairs(cert.validity) do
|
||||
o.validity[k] = format_time(v)
|
||||
o.validity[k] = stdnse.format_timestamp(stdnse.date_to_timestamp(v, 0), 0)
|
||||
end
|
||||
o.md5 = stdnse.tohex(cert:digest("md5"))
|
||||
o.sha1 = stdnse.tohex(cert:digest("sha1"))
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ end
|
|||
-- |_ssl-date: 2012-08-02T18:29:31Z; +4s from local time.
|
||||
--
|
||||
-- @xmloutput
|
||||
-- <elem key="date">2012-08-02T18:29:31Z</elem>
|
||||
-- <elem key="date">2012-08-02T18:29:31+00:00</elem>
|
||||
-- <elem key="delta">4</elem>
|
||||
|
||||
--
|
||||
|
|
@ -164,7 +164,7 @@ action = function(host, port)
|
|||
status, result = extract_time(response)
|
||||
if status then
|
||||
local output = {
|
||||
date = os.date("!%Y-%m-%dT%H:%M:%SZ",result),
|
||||
date = stdnse.format_timestamp(result, 0),
|
||||
delta = os.difftime(result, now),
|
||||
}
|
||||
return output, string.format("%s; %s from local time.", output.date,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue