1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Improve parsing of CLUSTER NODES responses

- Avoid crash due to potentially unrecognized format
- Fix parsing of node flags, which may contain non-alphabetic characters
  Example: "failed?"
- Fix parsing of field ip:port@cport
- Add support for IPv6 nodes
- Remove parsing of unused node ID field
This commit is contained in:
nnposter
2022-05-11 21:58:28 +00:00
parent b49c927c78
commit 97ec8d2de2
2 changed files with 13 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ o [GH#2331][GH#2471] Script oracle-tns-version was not reporting the version
correctly for Oracle 19c or newer [linholmes]
o [GH#2296][GH#2342] Script redis-info was crashing or producing inaccurate
information about client connections. [nnposter]
information about client connections and/or cluster nodes. [nnposter]
o [GH#2379] Nmap and Nping were unable to obtain system routes on FreeBSD
[benpratt, nnposter]

View File

@@ -152,20 +152,23 @@ local extras = {
end
},
{
-- https://redis.io/commands/cluster-nodes/
"Cluster nodes", {"CLUSTER", "NODES"}, function(data)
local restab = stringaux.strsplit("\n", data)
if not restab or 0 == #restab then
if not data then
stdnse.debug1("Failed to parse response from server")
return nil
end
local ips = {}
for _, item in ipairs(restab) do
local id, ip, port, flags = item:match("^([a-f0-9]+) ([0-9.:a-f]+):([0-9]+) ([a-z,]+)")
stdnse.debug1("ip=%s port=%s flags=%s", ip, port, flags)
table.insert(ips, ip .. ":" .. port .. " (" .. flags .. ")")
local out = {}
for node in data:gmatch("[^\n]+") do
local ipport, flags = node:match("^%x+%s+([%x.:%[%]]+)@?%d*%s+(%S+)")
if ipport then
table.insert(out, ("%s (%s)"):format(ipport, flags))
else
stdnse.debug1("Unable to parse cluster node info")
end
return ips
end
return #out > 0 and out or nil
end
},
}