o Updated showHTMLTitle NSE script to follow one HTTP redirect if

necessary as long as it is on the same server. [Jah]
This commit is contained in:
fyodor 2008-06-29 04:21:30 +00:00
parent b3fc32e7a4
commit 6d52a3db77
2 changed files with 13 additions and 1 deletions

View file

@ -1,5 +1,8 @@
# Nmap Changelog ($Id$); -*-text-*-
o Updated showHTMLTitle NSE script to follow one HTTP redirect if
necessary as long as it is on the same server. [Jah]
o Added a UDP SNMPv3 probe to version detection, along with 9 vendor
match lines. [Tom Sellers]

View file

@ -12,6 +12,7 @@ license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"default", "demo", "safe"}
require 'http'
require 'url'
portrule = function(host, port)
if not (port.service == 'http' or port.service == 'https') then
@ -29,6 +30,14 @@ action = function(host, port)
local data, result, title, protocol
data = http.get( host, port, '/' )
-- follow ONE redirect if host is not some other host
if data.status == 301 or data.status == 302 then
local url = url.parse( data.header.location )
if url.host == host.targetname or url.host == ( host.name ~= '' and host.name ) or url.host == host.ip then
stdnse.print_debug("showHTMLTitle.nse: Default page is located at " .. url.scheme.. "://" .. url.authority .. url.path)
data = http.get( host, port, url.path )
end
end
result = data.body
-- watch out, this doesn't really work for all html tags
@ -38,7 +47,7 @@ action = function(host, port)
if title ~= nil then
result = string.gsub(title , "[\n\r\t]", "")
if string.len(title) > 50 then
if string.len(title) > 65 then
stdnse.print_debug("showHTMLTitle.nse: Title got truncated!");
result = string.sub(result, 1, 62) .. "..."
end