--- scripts/http-hsts-verify.nse.orig 2016-12-30 14:09:23.879165193 +0000 +++ scripts/http-hsts-verify.nse 2016-12-30 12:59:06.183351176 +0000 @@ -1,5 +1,4 @@ local http = require "http" -local nmap = require "nmap" local shortport = require "shortport" local stdnse = require "stdnse" local table = require "table" @@ -15,7 +14,7 @@ --- -- @usage --- nmap -p --script=http-hsts-verify.nse +-- nmap -p --script http-hsts-verify -- -- @output -- PORT STATE SERVICE @@ -23,10 +22,11 @@ -- | http-hsts-verify: -- | HSTS is configured. -- |_ Header: Strict-Transport-Security: max-age=31536000 +-- +-- @args http-hsts-verify.path The URL path to request. The default path is "/". author = "Icaro Torres" license = "Same as Nmap--See https://nmap.org/book/man-legal.html" - categories = {"discovery", "safe"} portrule = shortport.http @@ -35,36 +35,33 @@ action = function(host, port) local path = stdnse.get_script_args(SCRIPT_NAME..".path") or "/" - local status = false local response local output_info = {} - local is_hsts = 0 - local hsts_header + local hsts_header = {} response = http.head(host, port, path) - if(response == nil) then - return fail("Header request failed") + if response == nil then + return fail("Request failed") end - if(response.rawheader == nil) then - return fail("GET header request didn't return a proper header") + if response.rawheader == nil then + return fail("Response didn't include a proper header") end - for _,line in pairs(response.rawheader) do + for _, line in pairs(response.rawheader) do if line:match("strict.transport.security") or line:match("Strict.Transport.Security") then - is_hsts = is_hsts + 1 - hsts_header = line + table.insert(hsts_header, line) end end - if is_hsts >= 1 then + if #hsts_header > 0 then table.insert(output_info, "HSTS is configured.") - table.insert(output_info, "Header: " .. hsts_header) + table.insert(output_info, "Header: " .. table.concat(hsts_header, " ")) else table.insert(output_info, "HSTS is not configured.") end return stdnse.format_output(true, output_info) -end \ No newline at end of file +end