Skip to content

Commit

Permalink
Fix to use to best hostname and include hostname in output. Fixes #17.
Browse files Browse the repository at this point in the history
  • Loading branch information
freb committed Feb 6, 2019
1 parent 14fbf14 commit f57b993
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion http-sec-headers.nse
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,23 @@ local stdnse = require "stdnse"

portrule = shortport.http

---Get the best possible hostname for the given host. Like stdnse.get_hostname
-- but does not use reverse dns name.
local function get_hostname(host)
if type(host) == "table" then
return host.targetname or host.ip
else
return host
end
end

action = function(host, port)
local path = "/"
local method = "GET"
local https_redirect = false
local hostname = get_hostname(host)

response = http.generic_request(host, port, method, path)
response = http.generic_request(hostname, port, method, path)

-- validate response
if response == nil then
Expand All @@ -66,6 +77,7 @@ action = function(host, port)
local output = stdnse.output_table()
output.missing = {}
output.present = {}
output.hostname = hostname
if not response.ssl then
output["redirect-http-to-https"] = https_redirect
end
Expand Down

0 comments on commit f57b993

Please sign in to comment.