mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 14:11:29 +00:00
Handle https://example.com:80 and http://example.com:443 cases
The shortport.ssl check can be expensive (6-second timeout on HTTP
services if you don't use -sV), so we want to avoid it if possible. As
discussed at
b2deb019ed (commitcomment-30289632)
this commit restores the SSL check in cases where it might matter (http
and https default ports) and adds a bypass when the URI scheme is
explicitly requested, as in http.get_url and when following redirects.
This commit is contained in:
@@ -415,11 +415,31 @@ local get_default_port_ports = {http=80, https=443}
|
||||
-- @param scheme for determining the port, such as "http" or "https".
|
||||
-- @return A port number as an integer, such as 443 for scheme "https",
|
||||
-- or nil in case of an undefined scheme
|
||||
-----------------------------------------------------------------------------
|
||||
function get_default_port (scheme)
|
||||
return get_default_port_ports[(scheme or ""):lower()]
|
||||
end
|
||||
|
||||
local function invert(t)
|
||||
local out = {}
|
||||
for k, v in pairs(t) do
|
||||
out[v] = k
|
||||
end
|
||||
return out
|
||||
end
|
||||
|
||||
get_default_scheme_schemes = invert(get_default_port_ports)
|
||||
|
||||
---
|
||||
-- Provides the default URI scheme for a given port.
|
||||
--
|
||||
-- @param port A port number as a number or port table
|
||||
-- @return scheme for addressing the port, such as "http" or "https".
|
||||
-----------------------------------------------------------------------------
|
||||
function get_default_scheme (port)
|
||||
local number = (type(port) == "number") and port or port.number
|
||||
return get_default_scheme_schemes[port]
|
||||
end
|
||||
|
||||
if not unittest.testing() then
|
||||
return _ENV
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user