From c38aa90312d72c22492c234309ebf35e06d87599 Mon Sep 17 00:00:00 2001 From: jah Date: Mon, 10 Nov 2008 22:55:08 +0000 Subject: [PATCH] Fix http.lua which ignores port.protocol and assumes it to be 'tcp' even if it is 'udp'. Now http.request() returns nil if port.protocol is not 'tcp'. Changed the portrule in html-title.nse to accept only TCP ports. Fixed a redirect rule in html-title.nse which was comparing the string url.port with the number port.number - which would always be false. --- nselib/http.lua | 4 ++++ scripts/html-title.nse | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nselib/http.lua b/nselib/http.lua index 779dce553..142392a01 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -123,6 +123,10 @@ request = function( host, port, data, options ) local protocol = 'tcp' if type(port) == 'table' then + if port.protocol and port.protocol ~= 'tcp' then + stdnse.print_debug(1, "http.request() supports the TCP protocol only, your request to %s cannot be completed.", host) + return nil + end if port.service == 'https' or ( port.version and port.version.service_tunnel == 'ssl' ) then protocol = 'ssl' end diff --git a/scripts/html-title.nse b/scripts/html-title.nse index c3b095562..c7d487e0d 100644 --- a/scripts/html-title.nse +++ b/scripts/html-title.nse @@ -27,7 +27,7 @@ local ipOps = require 'ipOps' local stdnse = require 'stdnse' portrule = function(host, port) - if not (port.service == 'http' or port.service == 'https') then + if port.protocol ~= 'tcp' or not (port.service == 'http' or port.service == 'https') then return false end -- Don't bother running on SSL ports if we don't have SSL. @@ -123,7 +123,7 @@ function redirect_ok(url, host, port) function (loc, url, host, port) -- if present, url.port must be the same as the scanned port -- loc.port must be set if returning true - if (not url.port) or url.port == port.number then + if (not url.port) or tonumber(url.port) == port.number then loc.port = port return true end