From 11a8c315ed31b32c082a74c157bc4bb83a93186a Mon Sep 17 00:00:00 2001 From: nnposter Date: Sat, 1 Apr 2017 14:33:54 +0000 Subject: [PATCH] Includes port information in the Host header for non-standard ports. Fixes #766 --- nselib/http.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nselib/http.lua b/nselib/http.lua index d9c84f268..1343ce3f3 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -114,6 +114,7 @@ local coroutine = require "coroutine" local nmap = require "nmap" local os = require "os" local sasl = require "sasl" +local shortport = require "shortport" local slaxml = require "slaxml" local stdnse = require "stdnse" local string = require "string" @@ -159,7 +160,14 @@ end --- Get a value suitable for the Host header field. -- See RFC 2616 sections 14.23 and 5.2. local function get_host_field(host, port) - return stdnse.get_hostname(host) + if not host then return nil end + local ssl = shortport.ssl(host, port) + local pn = port.number + if not ssl and pn == 80 or ssl and pn == 443 then + return stdnse.get_hostname(host) + else + return stdnse.get_hostname(host) .. ":" .. pn + end end -- Skip *( SP | HT ) starting at offset. See RFC 2616, section 2.2.