mirror of
https://github.com/nmap/nmap.git
synced 2025-12-22 07:29:01 +00:00
Reverted bad commit to http-title
This commit is contained in:
@@ -5,7 +5,6 @@ local nmap = require "nmap"
|
|||||||
local shortport = require "shortport"
|
local shortport = require "shortport"
|
||||||
local stdnse = require "stdnse"
|
local stdnse = require "stdnse"
|
||||||
local string = require "string"
|
local string = require "string"
|
||||||
local table = require "table"
|
|
||||||
local url = require "url"
|
local url = require "url"
|
||||||
|
|
||||||
description = [[
|
description = [[
|
||||||
@@ -39,9 +38,11 @@ categories = {"default", "discovery", "safe"}
|
|||||||
|
|
||||||
portrule = shortport.http
|
portrule = shortport.http
|
||||||
|
|
||||||
local function getTitle(host, port, path)
|
action = function(host, port)
|
||||||
local resp = http.get( host, port, path )
|
local resp, redirect_url, title
|
||||||
local redirect_url
|
|
||||||
|
resp = http.get( host, port, '/' )
|
||||||
|
|
||||||
-- check for a redirect
|
-- check for a redirect
|
||||||
if resp.location then
|
if resp.location then
|
||||||
redirect_url = resp.location[#resp.location]
|
redirect_url = resp.location[#resp.location]
|
||||||
@@ -51,14 +52,10 @@ local function getTitle(host, port, path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- try and match title tags
|
-- try and match title tags
|
||||||
local title
|
|
||||||
if ( resp.body ) then
|
|
||||||
title = string.match(resp.body, "<[Tt][Ii][Tt][Ll][Ee][^>]*>([^<]*)</[Tt][Ii][Tt][Ll][Ee]>")
|
title = string.match(resp.body, "<[Tt][Ii][Tt][Ll][Ee][^>]*>([^<]*)</[Tt][Ii][Tt][Ll][Ee]>")
|
||||||
else
|
|
||||||
title = "No reponse received from server"
|
|
||||||
end
|
|
||||||
|
|
||||||
local display_title = title
|
local display_title = title
|
||||||
|
|
||||||
if display_title and display_title ~= "" then
|
if display_title and display_title ~= "" then
|
||||||
display_title = string.gsub(display_title , "[\n\r\t]", "")
|
display_title = string.gsub(display_title , "[\n\r\t]", "")
|
||||||
if #display_title > 65 then
|
if #display_title > 65 then
|
||||||
@@ -73,25 +70,14 @@ local function getTitle(host, port, path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return title, display_title, redirect_url
|
local output_tab = stdnse.output_table()
|
||||||
end
|
output_tab.title = title
|
||||||
|
output_tab.redirect_url = redirect_url
|
||||||
|
|
||||||
action = function(host, port)
|
local output_str = display_title
|
||||||
local path = stdnse.get_script_args(SCRIPT_NAME .. ".path") or "/"
|
|
||||||
local str_res, xml_res = {}, stdnse.output_table()
|
|
||||||
|
|
||||||
for _, p in ipairs(stdnse.strsplit(",", path)) do
|
|
||||||
local title, display_title, redirect_url = getTitle(host, port, p)
|
|
||||||
|
|
||||||
local result_part = { ("%s: %s"):format(p, display_title) }
|
|
||||||
if redirect_url then
|
if redirect_url then
|
||||||
table.insert(result_part, { ("Requested resource was %s"):format( redirect_url ) })
|
output_str = output_str .. "\n" .. ("Requested resource was %s"):format( redirect_url )
|
||||||
end
|
|
||||||
table.insert(str_res, result_part)
|
|
||||||
|
|
||||||
xml_res.urls = xml_res.urls or {}
|
|
||||||
table.insert(xml_res.urls, { path = p, title = title, redirect_url = redirect_url })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return xml_res, stdnse.format_output(true, str_res)
|
return output_tab, output_str
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user