summaryrefslogtreecommitdiffstats
path: root/scripts/smb2-time.nse
blob: 4b19400274db1a113467eac3ffc9b22a810d7b93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local os = require "os"
local datetime = require "datetime"
local smb = require "smb"
local stdnse = require "stdnse"
local smb2 = require "smb2"

description = [[
Attempts to obtain the current system date and the start date of a SMB2 server.
]]

---
-- @usage nmap -p445 --script smb2-time <target>
--
-- @output
-- Host script results:
-- | smb2-time:
-- |   date: 2017-07-28 03:06:34
-- |_  start_date: 2017-07-20 09:29:49
--
-- @xmloutput
-- <elem key="date">2017-07-28 03:07:57</elem>
-- <elem key="start_date">2017-07-20 09:29:49</elem>
---

author = "Paulino Calderon <calderon()websec.mx>"
license = "Same as Nmap--See https://nmap.org/book/man-legal.html"
categories = {"discovery", "safe", "default"}

hostrule = function(host)
  return smb.get_port(host) ~= nil
end

action = function(host,port)
  local smbstate, status
  local output = stdnse.output_table()
  status, smbstate = smb.start(host)
  status = smb2.negotiate_v2(smbstate)

  if status then
    datetime.record_skew(host, smbstate.time, os.time())
    stdnse.debug2("SMB2: Date: %s (%s) Start date:%s (%s)",
                        smbstate['date'], smbstate['time'],
            smbstate['start_date'], smbstate['start_time'])
    output.date = smbstate['date']
    output.start_date = smbstate['start_date']
    return output
  else
    stdnse.debug2("Negotiation failed")
    return "Protocol negotiation failed (SMB2)"
  end
end