mirror of
https://github.com/nmap/nmap.git
synced 2025-12-09 22:21:29 +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
|
||||
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;
|
||||
|
||||
@@ -73,14 +73,6 @@ hostrule = function(host)
|
||||
return true
|
||||
end
|
||||
|
||||
local function keys(t)
|
||||
local ret = {}
|
||||
for k, _ in pairs(t) do
|
||||
ret[#ret+1] = k
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
action = function(host)
|
||||
-- Do reverse-DNS lookup of the IP
|
||||
-- Can't just use host.name because some IPs have multiple PTR records
|
||||
@@ -135,7 +127,7 @@ action = function(host)
|
||||
str_out = nil
|
||||
elseif str_out == nil then
|
||||
-- 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
|
||||
table.sort(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
|
||||
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 hello = tls.client_hello({
|
||||
["protocol"] = version,
|
||||
-- Claim to support every cipher
|
||||
-- Doesn't work with IIS, but IIS isn't vulnerable
|
||||
["ciphers"] = keys(tls.CIPHERS),
|
||||
["ciphers"] = stdnse.keys(tls.CIPHERS),
|
||||
["compressors"] = {"NULL"},
|
||||
["extensions"] = {
|
||||
-- Claim to support every elliptic curve
|
||||
["elliptic_curves"] = tls.EXTENSION_HELPERS["elliptic_curves"](
|
||||
keys(tls.ELLIPTIC_CURVES)),
|
||||
stdnse.keys(tls.ELLIPTIC_CURVES)),
|
||||
-- Claim to support every EC point format
|
||||
["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
|
||||
|
||||
-- Read the alert message
|
||||
local vulnerable
|
||||
status,vulnerable = alert_unexpected_message(s)
|
||||
|
||||
-- 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
|
||||
|
||||
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 ret = {}
|
||||
for k, _ in pairs(t) do
|
||||
@@ -709,8 +701,7 @@ function sorted_by_key(t)
|
||||
local out = {}
|
||||
setmetatable(out, {
|
||||
__pairs = function(_)
|
||||
local order = keys(t)
|
||||
table.sort(order)
|
||||
local order = sorted_keys(t)
|
||||
return coroutine.wrap(function()
|
||||
for i,k in ipairs(order) do
|
||||
coroutine.yield(k, t[k])
|
||||
@@ -753,7 +744,7 @@ action = function(host, port)
|
||||
end
|
||||
until next(threads) == nil
|
||||
|
||||
if #( keys(results) ) == 0 then
|
||||
if #( stdnse.keys(results) ) == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
@@ -68,27 +68,19 @@ local function recvmsg(s, len)
|
||||
return true, pay
|
||||
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 hello = tls.client_hello({
|
||||
["protocol"] = version,
|
||||
-- Claim to support every cipher
|
||||
-- Doesn't work with IIS, but IIS isn't vulnerable
|
||||
["ciphers"] = keys(tls.CIPHERS),
|
||||
["ciphers"] = stdnse.keys(tls.CIPHERS),
|
||||
["compressors"] = {"NULL"},
|
||||
["extensions"] = {
|
||||
-- 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
|
||||
["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
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user