mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 06:01:28 +00:00
Scripts may now return a key–value table, or such a table in addition to a string. The table will be automatically formatted for normal output and will appear as a hierarchy of elements in XML output. Some history and discussion of this development can be found at https://secwiki.org/w/Nmap/Structured_Script_Output. This is a merge of r29484:29569 from /nmap-exp/david/xml-output.
56 lines
1.5 KiB
Lua
56 lines
1.5 KiB
Lua
local http = require "http"
|
|
local os = require "os"
|
|
local shortport = require "shortport"
|
|
local stdnse = require "stdnse"
|
|
local string = require "string"
|
|
|
|
description = [[
|
|
Gets the date from HTTP-like services. Also prints how much the date
|
|
differs from local time. Local time is the time the HTTP request was
|
|
sent, so the difference includes at least the duration of one RTT.
|
|
]]
|
|
|
|
---
|
|
-- @output
|
|
-- 80/tcp open http
|
|
-- |_http-date: Thu, 02 Aug 2012 22:11:03 GMT; 0s from local time.
|
|
-- 80/tcp open http
|
|
-- |_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="delta">-231</elem>
|
|
|
|
author = "David Fifield"
|
|
|
|
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
|
|
|
|
categories = {"discovery", "safe"}
|
|
|
|
|
|
portrule = shortport.http
|
|
|
|
action = function(host, port)
|
|
-- Get the local date in UTC.
|
|
local request_date = os.date("!*t")
|
|
local response = http.get(host, port, "/")
|
|
if not response.status or not response.header["date"] then
|
|
return
|
|
end
|
|
|
|
local response_date = http.parse_date(response.header["date"])
|
|
if not response_date then
|
|
return
|
|
end
|
|
|
|
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))
|
|
|
|
local output_str = string.format("%s; %s from local time.",
|
|
response.header["date"], stdnse.format_difftime(response_date, request_date))
|
|
|
|
return output_tab, output_str
|
|
end
|