mirror of
https://github.com/nmap/nmap.git
synced 2025-12-24 08:29:04 +00:00
o Added NSE HTTP library which allows scripts to easily fetch URLs
with http.get_url() or create more complex requests with http.request(). There is also an http.get() function which takes components (hostname, port, and path) rather than a URL. The HTTPAuth, robots, and showHTMLTitle NSE scripts have been updated to use this library. Sven Klemm wrote all of this code.
This commit is contained in:
@@ -11,7 +11,7 @@ license = "See nmaps COPYING for licence"
|
||||
|
||||
categories = {"demo", "safe"}
|
||||
|
||||
require "stdnse"
|
||||
require 'http'
|
||||
|
||||
portrule = function(host, port)
|
||||
if not (port.service == 'http' or port.service == 'https') then
|
||||
@@ -26,41 +26,20 @@ portrule = function(host, port)
|
||||
end
|
||||
|
||||
action = function(host, port)
|
||||
local socket, request, result, status, s, title, protocol
|
||||
local data, result, title, protocol
|
||||
|
||||
socket = nmap.new_socket()
|
||||
data = http.get( host, port, '/' )
|
||||
result = data.body
|
||||
|
||||
if port.service == 'https' or port.version.service_tunnel == 'ssl' then
|
||||
protocol = "ssl"
|
||||
else
|
||||
protocol = "tcp"
|
||||
end
|
||||
|
||||
socket:connect(host.ip, port.number, protocol )
|
||||
request = "GET / HTTP/1.0\r\n\r\n"
|
||||
socket:send(request)
|
||||
|
||||
result = ""
|
||||
while true do
|
||||
status, s = socket:receive_lines(1)
|
||||
if not status then
|
||||
break
|
||||
end
|
||||
|
||||
result = result .. s
|
||||
end
|
||||
socket:close()
|
||||
|
||||
-- watch out, this doesn't really work for all html tags
|
||||
-- also string.lower consumes the /
|
||||
result = string.gsub(result, "</?(%a+)>", function(c) return "<" .. string.lower(c) .. ">" end)
|
||||
|
||||
title = string.match(result, "<title>(.+)<title>")
|
||||
result = string.gsub(result, "<(/?%a+)>", function(c) return "<" .. string.lower(c) .. ">" end)
|
||||
|
||||
title = string.match(result, "<title>(.+)</title>")
|
||||
|
||||
if title ~= nil then
|
||||
result = string.gsub(title , "[\n\r\t]", "")
|
||||
if string.len(title) > 50 then
|
||||
stdnse.print_debug("showHTMLTitle.nse: Title got truncated!");
|
||||
stdnse.print_debug("showHTMLTitle.nse: Title got truncated!");
|
||||
result = string.sub(result, 1, 62) .. "..."
|
||||
end
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user