From 5cc9d5249a93a051ffe9ea72da775b01610ca0f3 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 9 Nov 2009 20:26:55 +0000 Subject: [PATCH] In http.lua, add the port number to the value of the Host header field when the number is not 80. See RFC 2616, section 14.23. This was suggested by Tom Sellers. --- nselib/http.lua | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/nselib/http.lua b/nselib/http.lua index e50e727dd..f717f0456 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -250,6 +250,24 @@ local function get_hostname(host) end end +--- Get a value suitable for the Host header field. +local function get_host_field(host, port) + local hostname = get_hostname(host) + local portno + if port == nil then + portno = 80 + elseif type(port) == "table" then + portno = port.number + else + portno = port + end + if portno == 80 then + return hostname + else + return hostname .. ":" .. tostring(portno) + end +end + --- Parses a response header and return a table with cookie jar -- -- The cookie attributes can be accessed by: @@ -339,7 +357,7 @@ local buildGet = function( host, port, path, options, cookies ) -- Private copy of the options table, used to add default header fields. local mod_options = { header = { - Host = get_hostname(host), + Host = get_host_field(host, port), ["User-Agent"] = "Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)" } } @@ -374,7 +392,7 @@ local buildHead = function( host, port, path, options, cookies ) -- Private copy of the options table, used to add default header fields. local mod_options = { header = { - Host = get_hostname(host), + Host = get_host_field(host, port), ["User-Agent"] = "Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)" } } @@ -420,7 +438,7 @@ local buildPost = function( host, port, path, options, cookies, postdata) local mod_options = { header = { - Host = get_hostname(host), + Host = get_host_field(host, port), Connection = "close", ["Content-Type"] = "application/x-www-form-urlencoded", ["User-Agent"] = "Mozilla/5.0 (compatible; Nmap Scripting Engine; http://nmap.org/book/nse.html)"