mirror of
https://github.com/nmap/nmap.git
synced 2025-12-18 05:29:02 +00:00
Fix infinite loop in tls-alpn when server is forcing a protocol.
This commit is contained in:
@@ -112,13 +112,13 @@ local check_alpn = function(response)
|
|||||||
|
|
||||||
if record.type == "handshake" and record.body[1].type == "server_hello" then
|
if record.type == "handshake" and record.body[1].type == "server_hello" then
|
||||||
if record.body[1].extensions == nil then
|
if record.body[1].extensions == nil then
|
||||||
stdnse.debug1("Server does not support TLS ALPN extension.")
|
stdnse.debug1("Server did not return TLS ALPN extension.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local results = {}
|
local results = {}
|
||||||
local alpndata = record.body[1].extensions[ALPN_NAME]
|
local alpndata = record.body[1].extensions[ALPN_NAME]
|
||||||
if alpndata == nil then
|
if alpndata == nil then
|
||||||
stdnse.debug1("Server does not support TLS ALPN extension.")
|
stdnse.debug1("Server did not return TLS ALPN extension.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
-- Parse data
|
-- Parse data
|
||||||
@@ -185,26 +185,26 @@ action = function(host, port)
|
|||||||
local result = check_alpn(response)
|
local result = check_alpn(response)
|
||||||
if not result then
|
if not result then
|
||||||
stdnse.debug1("None of %d protocols chosen", #alpn_protos)
|
stdnse.debug1("None of %d protocols chosen", #alpn_protos)
|
||||||
break
|
goto ALPN_DONE
|
||||||
end
|
end
|
||||||
for i, p in ipairs(result) do
|
for i, p in ipairs(result) do
|
||||||
if i > 1 then
|
if i > 1 then
|
||||||
stdnse.verbose1("Server violates RFC: sent additional protocol %s", p)
|
stdnse.verbose1("Server violates RFC: sent additional protocol %s", p)
|
||||||
end
|
else
|
||||||
chosen[#chosen+1] = p
|
chosen[#chosen+1] = p
|
||||||
if not find_and_remove(alpn_protos, p) then
|
if not find_and_remove(alpn_protos, p) then
|
||||||
stdnse.debug1("Chosen ALPN protocol %s was not offered", p)
|
stdnse.debug1("Chosen ALPN protocol %s was not offered", p)
|
||||||
if stdnse.contains(chosen, p) then
|
-- Server is forcing this protocol, no need to continue offering.
|
||||||
stdnse.debug1("Server is forcing %s", p)
|
goto ALPN_DONE
|
||||||
break
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
stdnse.debug1("Client hello failed with %d protocols", #alpn_protos)
|
stdnse.debug1("Client hello failed with %d protocols", #alpn_protos)
|
||||||
break
|
goto ALPN_DONE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
::ALPN_DONE::
|
||||||
if next(chosen) then
|
if next(chosen) then
|
||||||
return chosen
|
return chosen
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user