mirror of
https://github.com/nmap/nmap.git
synced 2025-12-12 18:59:03 +00:00
Add stdnse.keys() for extracting keys from a table
This commit is contained in:
@@ -1411,4 +1411,15 @@ function get_timeout(host, max_timeout, min_timeout)
|
|||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the keys of a table as an array
|
||||||
|
-- @param t The table
|
||||||
|
-- @return A table of keys
|
||||||
|
function keys(t)
|
||||||
|
local ret = {}
|
||||||
|
for k, _ in pairs(t) do
|
||||||
|
ret[#ret+1] = k
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
return _ENV;
|
return _ENV;
|
||||||
|
|||||||
@@ -73,14 +73,6 @@ hostrule = function(host)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function keys(t)
|
|
||||||
local ret = {}
|
|
||||||
for k, _ in pairs(t) do
|
|
||||||
ret[#ret+1] = k
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
action = function(host)
|
action = function(host)
|
||||||
-- Do reverse-DNS lookup of the IP
|
-- Do reverse-DNS lookup of the IP
|
||||||
-- Can't just use host.name because some IPs have multiple PTR records
|
-- Can't just use host.name because some IPs have multiple PTR records
|
||||||
@@ -135,7 +127,7 @@ action = function(host)
|
|||||||
str_out = nil
|
str_out = nil
|
||||||
elseif str_out == nil then
|
elseif str_out == nil then
|
||||||
-- we failed, and need to format a short output string
|
-- we failed, and need to format a short output string
|
||||||
fail_addrs = keys(fail_addrs)
|
fail_addrs = stdnse.keys(fail_addrs)
|
||||||
if #fail_addrs > 0 then
|
if #fail_addrs > 0 then
|
||||||
table.sort(fail_addrs)
|
table.sort(fail_addrs)
|
||||||
str_out = string.format("FAIL (%s)", table.concat(fail_addrs, ", "))
|
str_out = string.format("FAIL (%s)", table.concat(fail_addrs, ", "))
|
||||||
|
|||||||
@@ -115,28 +115,20 @@ local function alert_unexpected_message(s)
|
|||||||
return true,true
|
return true,true
|
||||||
end
|
end
|
||||||
|
|
||||||
local function keys(t)
|
|
||||||
local ret = {}
|
|
||||||
for k, _ in pairs(t) do
|
|
||||||
ret[#ret+1] = k
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
local function test_ccs_injection(host, port, version)
|
local function test_ccs_injection(host, port, version)
|
||||||
local hello = tls.client_hello({
|
local hello = tls.client_hello({
|
||||||
["protocol"] = version,
|
["protocol"] = version,
|
||||||
-- Claim to support every cipher
|
-- Claim to support every cipher
|
||||||
-- Doesn't work with IIS, but IIS isn't vulnerable
|
-- Doesn't work with IIS, but IIS isn't vulnerable
|
||||||
["ciphers"] = keys(tls.CIPHERS),
|
["ciphers"] = stdnse.keys(tls.CIPHERS),
|
||||||
["compressors"] = {"NULL"},
|
["compressors"] = {"NULL"},
|
||||||
["extensions"] = {
|
["extensions"] = {
|
||||||
-- Claim to support every elliptic curve
|
-- Claim to support every elliptic curve
|
||||||
["elliptic_curves"] = tls.EXTENSION_HELPERS["elliptic_curves"](
|
["elliptic_curves"] = tls.EXTENSION_HELPERS["elliptic_curves"](
|
||||||
keys(tls.ELLIPTIC_CURVES)),
|
stdnse.keys(tls.ELLIPTIC_CURVES)),
|
||||||
-- Claim to support every EC point format
|
-- Claim to support every EC point format
|
||||||
["ec_point_formats"] = tls.EXTENSION_HELPERS["ec_point_formats"](
|
["ec_point_formats"] = tls.EXTENSION_HELPERS["ec_point_formats"](
|
||||||
keys(tls.EC_POINT_FORMATS)),
|
stdnse.keys(tls.EC_POINT_FORMATS)),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -228,6 +220,7 @@ local function test_ccs_injection(host, port, version)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Read the alert message
|
-- Read the alert message
|
||||||
|
local vulnerable
|
||||||
status,vulnerable = alert_unexpected_message(s)
|
status,vulnerable = alert_unexpected_message(s)
|
||||||
|
|
||||||
-- Leave the target not vulnerable in case of an error. This could occur
|
-- Leave the target not vulnerable in case of an error. This could occur
|
||||||
|
|||||||
@@ -211,14 +211,6 @@ local function try_params(host, port, t)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function keys(t)
|
|
||||||
local ret = {}
|
|
||||||
for k, _ in pairs(t) do
|
|
||||||
ret[#ret+1] = k
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
local function sorted_keys(t)
|
local function sorted_keys(t)
|
||||||
local ret = {}
|
local ret = {}
|
||||||
for k, _ in pairs(t) do
|
for k, _ in pairs(t) do
|
||||||
@@ -709,8 +701,7 @@ function sorted_by_key(t)
|
|||||||
local out = {}
|
local out = {}
|
||||||
setmetatable(out, {
|
setmetatable(out, {
|
||||||
__pairs = function(_)
|
__pairs = function(_)
|
||||||
local order = keys(t)
|
local order = sorted_keys(t)
|
||||||
table.sort(order)
|
|
||||||
return coroutine.wrap(function()
|
return coroutine.wrap(function()
|
||||||
for i,k in ipairs(order) do
|
for i,k in ipairs(order) do
|
||||||
coroutine.yield(k, t[k])
|
coroutine.yield(k, t[k])
|
||||||
@@ -753,7 +744,7 @@ action = function(host, port)
|
|||||||
end
|
end
|
||||||
until next(threads) == nil
|
until next(threads) == nil
|
||||||
|
|
||||||
if #( keys(results) ) == 0 then
|
if #( stdnse.keys(results) ) == 0 then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -68,27 +68,19 @@ local function recvmsg(s, len)
|
|||||||
return true, pay
|
return true, pay
|
||||||
end
|
end
|
||||||
|
|
||||||
local function keys(t)
|
|
||||||
local ret = {}
|
|
||||||
for k, _ in pairs(t) do
|
|
||||||
ret[#ret+1] = k
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
local function testversion(host, port, version)
|
local function testversion(host, port, version)
|
||||||
|
|
||||||
local hello = tls.client_hello({
|
local hello = tls.client_hello({
|
||||||
["protocol"] = version,
|
["protocol"] = version,
|
||||||
-- Claim to support every cipher
|
-- Claim to support every cipher
|
||||||
-- Doesn't work with IIS, but IIS isn't vulnerable
|
-- Doesn't work with IIS, but IIS isn't vulnerable
|
||||||
["ciphers"] = keys(tls.CIPHERS),
|
["ciphers"] = stdnse.keys(tls.CIPHERS),
|
||||||
["compressors"] = {"NULL"},
|
["compressors"] = {"NULL"},
|
||||||
["extensions"] = {
|
["extensions"] = {
|
||||||
-- Claim to support every elliptic curve
|
-- Claim to support every elliptic curve
|
||||||
["elliptic_curves"] = tls.EXTENSION_HELPERS["elliptic_curves"](keys(tls.ELLIPTIC_CURVES)),
|
["elliptic_curves"] = tls.EXTENSION_HELPERS["elliptic_curves"](stdnse.keys(tls.ELLIPTIC_CURVES)),
|
||||||
-- Claim to support every EC point format
|
-- Claim to support every EC point format
|
||||||
["ec_point_formats"] = tls.EXTENSION_HELPERS["ec_point_formats"](keys(tls.EC_POINT_FORMATS)),
|
["ec_point_formats"] = tls.EXTENSION_HELPERS["ec_point_formats"](stdnse.keys(tls.EC_POINT_FORMATS)),
|
||||||
["heartbeat"] = "\x01", -- peer_not_allowed_to_send
|
["heartbeat"] = "\x01", -- peer_not_allowed_to_send
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user