From 97ec8d2de26208a7111deab41c61bb823bc0acf5 Mon Sep 17 00:00:00 2001 From: nnposter Date: Wed, 11 May 2022 21:58:28 +0000 Subject: [PATCH] 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 --- CHANGELOG | 2 +- scripts/redis-info.nse | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9aa065917..99c2cd653 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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] diff --git a/scripts/redis-info.nse b/scripts/redis-info.nse index f2018f58f..fcfd4b7af 100644 --- a/scripts/redis-info.nse +++ b/scripts/redis-info.nse @@ -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 end - - return ips + return #out > 0 and out or nil end }, }