Elasticsearch — 2 vulnerability checks
noctis ships 2 vulnerability checks for Elasticsearch, covering 2 CVEs; each one has to observe the bug on the live service before it reports a finding.
← All products · Feeds on GitHub
Elasticsearch Groovy Scripting Sandbox Bypass
| CVE | CVE-2015-1427 |
|---|---|
| Severity | critical · CVSS 9.8 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | set_var, script, http_request, match · highest QoD 75 |
| Feed | tests/vulnerabilities/elasticsearch/CVE-2015-1427.yaml |
Detects Elasticsearch nodes that evaluate inline Groovy scripts in a _search request — the condition CVE-2015-1427 abuses to escape the scripting sandbox. The probe is a benign arithmetic script (sum of two random integers); a vulnerable node reflects the computed value, a patched node returns a script error. Detection only — no exploitation of the sandbox bypass.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
POST /_searchwith a crafted body - Parses / computes the next value with a Rhai script
- Checks
detect.hitfortrue→ finding QoD 75: Elasticsearch evaluates inline Groovy scripts (CVE-2015-1427)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2015-1427
- https://www.elastic.co/community/security
- https://github.com/XiphosResearch/exploits/tree/master/ElasticSearch
Feed source — tests/vulnerabilities/elasticsearch/CVE-2015-1427.yaml
# Elasticsearch Groovy scripting sandbox bypass — CVE-2015-1427
#
# Elasticsearch 1.3.0–1.3.7 and 1.4.0–1.4.2 ship with the Groovy scripting
# engine enabled by default and a sandbox that fails to contain a crafted
# script, letting a _search request evaluate arbitrary Groovy and (in the
# public exploit) reach java.lang.Runtime for remote code execution.
#
# DETECTION (safe, non-exploitative):
# We do NOT exploit the bypass. We prove the server *evaluates* an inline
# Groovy script — the precondition for the CVE — using a purely ARITHMETIC
# expression. A _search with a `script_fields` Groovy script computes the sum
# of two random integers chosen fresh per run. A vulnerable node (dynamic
# Groovy scripting on) evaluates it and reflects the computed sum in the
# script_fields of the response. A patched/secured node refuses with a script
# compilation / "scripts of type [inline] ... not enabled" error and never
# returns the computed value. No Runtime/exec, no file read, no system
# command — only addition, so the probe cannot alter or read the target.
#
# The match keys on OUR freshly-computed sum under OUR field name, so it is
# marker-swap safe: change the operands and the expected result changes with
# them; a server that merely echoed a fixed constant would not pass.
uid: 428641df-1153-4b76-8fcf-f9015f5f9b29
name: "Elasticsearch Groovy Scripting Sandbox Bypass (CVE-2015-1427)"
description: |
Detects Elasticsearch nodes that evaluate inline Groovy scripts in a _search
request — the condition CVE-2015-1427 abuses to escape the scripting sandbox.
The probe is a benign arithmetic script (sum of two random integers); a
vulnerable node reflects the computed value, a patched node returns a script
error. Detection only — no exploitation of the sandbox bypass.
cves: [CVE-2015-1427]
cvss: 9.8
severity: critical
category: rce
confidence_base: 0.30
tags: [elasticsearch, groovy, scripting, sandbox-bypass, rce, detection]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2015-1427"
- "https://www.elastic.co/community/security"
- "https://github.com/XiphosResearch/exploits/tree/master/ElasticSearch"
steps:
# 1 — pick two random operands fresh per run and compute their expected sum.
# Returned as a map so later templated fields can read calc.a / calc.b /
# calc.sum. A unique field name (noctis_calc) scopes the reflected value.
- id: pick-operands
action: set_var
var_name: marker
var_value: noctis_calc
- id: compute
action: script
store_as: calc
code: |
let a = rand_int(100000, 999999);
let b = rand_int(100000, 999999);
#{ a: a, b: b, sum: a + b }
# 2 — POST a benign Groovy script to _search that returns a + b. Reqwest is
# fine here: the payload lives in a JSON body, not an encoded path.
- id: groovy-probe
action: http_request
method: POST
path: "/_search"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
headers:
Content-Type: "application/json"
body: '{"size":1,"script_fields":{"noctis_calc":{"lang":"groovy","script":"{{calc.a}} + {{calc.b}}"}}}'
store_as: resp
# 3 — did the node EVALUATE the script and reflect OUR computed sum under OUR
# field name? Whitespace-insensitive containment of "noctis_calc":[<sum>.
# stridx >= 0 ⇒ the arithmetic ran server-side (sandbox precondition met).
- id: detect
action: script
condition: "resp.status == 200"
store_as: detect
code: |
let body = if type_of(resp.body) == "string" { str_replace(resp.body, " ", "") } else { "" };
let want = "\"" + marker + "\":[" + calc.sum.to_string();
#{ hit: stridx(body, want) >= 0, want: want }
- id: confirm
action: match
source: detect.hit
pattern: "true"
condition: "resp.status == 200"
on_match:
finding:
title: "Elasticsearch evaluates inline Groovy scripts (CVE-2015-1427)"
description: "A _search request with an inline Groovy script_fields script was evaluated server-side and reflected the computed arithmetic result, confirming dynamic Groovy scripting is enabled — the sandbox-bypass precondition for CVE-2015-1427."
remediation: "Upgrade to Elasticsearch >= 1.4.3 / 1.3.8, set script.groovy.sandbox.enabled and dynamic scripting appropriately (disable inline scripts: script.inline: false), and restrict network access to port 9200."
confidence_delta: 0.45
qod: 75
evidence: "Server evaluated Groovy {{calc.a}} + {{calc.b}} and reflected {{detect.want}}; response (HTTP {{resp.status}}): {{resp.body}}"Elasticsearch < 1.2 Dynamic MVEL Scripting RCE
| CVE | CVE-2014-3120 |
|---|---|
| Severity | high · CVSS 8.1 |
| Category | rce — Remote code execution |
| Services | http, https |
| Detection | script, set_var, http_request, match · highest QoD 97 |
| Feed | tests/vulnerabilities/elasticsearch/CVE-2014-3120.yaml |
Detects Elasticsearch nodes (< 1.2, or with dynamic scripting re-enabled) that run dynamic MVEL scripts sent in a _search request. The probe makes the node instantiate java.lang.StringBuilder and reverse a random token — the arbitrary Java class access that gives unauthenticated remote code execution — and matches the reversed token in the response. Benign: no file read, command or write on the target.
How noctis detects it
- Parses / computes the next value with a Rhai script
- HTTP(S) request
GET / - HTTP(S) request
POST /_searchwith a crafted body - Parses / computes the next value with a Rhai script
- Checks
verdict.rcefortrue→ finding QoD 97: Elasticsearch executes dynamic MVEL scripts — remote code execution (CVE-2014-3120) - Checks
verdict.emptyfortrue→ finding QoD 70: Elasticsearch accepts dynamic MVEL scripts (CVE-2014-3120)
References:
- https://nvd.nist.gov/vuln/detail/CVE-2014-3120
- https://www.elastic.co/community/security
- https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/elasticsearch/script_mvel_rce.rb
- https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2014/CVE-2014-3120.yaml
Feed source — tests/vulnerabilities/elasticsearch/CVE-2014-3120.yaml
# Elasticsearch < 1.2 dynamic MVEL scripting RCE — CVE-2014-3120
#
# Ported from OpenVAS/Greenbone NVT 2014/gb_elastisearch_code_execution_05_14.nasl
# (OID 1.3.6.1.4.1.25623.1.0.105032, GPL-2.0-only).
#
# Elasticsearch before 1.2 ships with dynamic scripting enabled and MVEL as the
# default script language. MVEL is not sandboxed: a script in a _search request
# (`script_fields`) can instantiate and call any Java class, which is remote code
# execution for anyone who reaches port 9200 (KEV, Metasploit script_mvel_rce).
# 1.2 turned dynamic scripting off by default (script.disable_dynamic: true).
#
# DETECTION — real exploitation, benign proof:
# The NASL sends a _search whose MVEL script reads /etc/passwd with
# java.util.Scanner and greps for "root:.*:0:0". We exercise the very same
# primitive (arbitrary Java class instantiation from an MVEL script) without
# touching the filesystem: the script builds a java.lang.StringBuilder from a
# random per-run token and returns it reversed. A vulnerable node returns the
# reversed token under our script field; the reversed string never appears in
# the request, so an echo cannot match. No file read, no command, no write.
# `"lang":"mvel"` is explicit, so a 1.3/1.4 Groovy node (CVE-2015-1427, its own
# feed) does not answer for this CVE.
#
# Better than the NASL:
# - no /etc/passwd read (the NASL exfiltrates file contents into its report);
# - the NASL needs at least one indexed document: script_fields only run on a
# hit, so an empty cluster is a false negative. A dynamic-scripting-disabled
# node (>= 1.2, or script.disable_dynamic: true) rejects the request at
# parse time on every shard, documents or not. So a 200 with every shard
# successful, no failure and zero hits means the MVEL script was accepted by
# the shards: reported as a lower-QoD (70) finding when the exploit proof
# could not run for lack of a document. That weaker branch also requires a
# GET / banner in the MVEL era (0.x, 1.0–1.3), so an ES-shaped proxy or
# honeypot that ignores script_fields is not flagged. With zero shards (no
# index at all) nothing is provable and nothing is reported.
# - 0.90.x returns a single-valued field as a scalar ("f":"v"), 1.x as an
# array ("f":["v"]); both shapes are matched.
uid: aa6b4c88-dc11-4698-8eaf-7f0518baadf7
name: "Elasticsearch < 1.2 Dynamic MVEL Scripting RCE (CVE-2014-3120)"
description: |
Detects Elasticsearch nodes (< 1.2, or with dynamic scripting re-enabled) that
run dynamic MVEL scripts sent in a _search request. The probe makes the node
instantiate java.lang.StringBuilder and reverse a random token — the arbitrary
Java class access that gives unauthenticated remote code execution — and
matches the reversed token in the response. Benign: no file read, command or
write on the target.
cves: [CVE-2014-3120]
cvss: 8.1
severity: high
category: rce
confidence_base: 0.30
tags: [elasticsearch, mvel, scripting, rce, kev, intrusive]
services: [http, https]
author: noctis
version: "1.0.0"
references:
- "https://nvd.nist.gov/vuln/detail/CVE-2014-3120"
- "https://www.elastic.co/community/security"
- "https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/elasticsearch/script_mvel_rce.rb"
- "https://github.com/projectdiscovery/nuclei-templates/blob/main/http/cves/2014/CVE-2014-3120.yaml"
steps:
# 1 — a fresh random token per run, and its reversal (what the node must return).
- id: token
action: script
store_as: p
code: |
let tok = "noctis" + rand_str(16);
let rev = "";
for c in tok.chars() { rev = c.to_string() + rev; }
#{ tok: tok, rev: rev }
# 2 — banner, only used to gate the weaker empty-cluster branch. Pre-set so a
# failed request leaves a defined (non-map) value instead of aborting.
- id: banner-init
action: set_var
var_name: banner
var_value: none
- id: banner
action: http_request
method: GET
path: "/"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
store_as: banner
# 3 — _search with an MVEL script_fields script that instantiates a Java class.
# The payload lives in a JSON body, so reqwest is fine (no encoded path).
- id: mvel-probe
action: http_request
method: POST
path: "/_search"
port: "{{port}}"
tls_insecure: true
follow_redirects: false
timeout_secs: 10
headers:
Content-Type: "application/json"
body: '{"size":1,"query":{"match_all":{}},"script_fields":{"noctis_mvel":{"lang":"mvel","script":"new java.lang.StringBuilder(\"{{p.tok}}\").reverse().toString()"}}}'
store_as: resp
# 4 — classify the reply.
# rce: our field carries the reversed token (array on 1.x, scalar on
# 0.90.x) → the Java code ran.
# empty: 200, all shards successful (> 0), none failed, zero hits, no
# script error → the shards accepted the dynamic MVEL script but
# there was no document to run it on; banner version 0.x–1.3.
- id: classify
action: script
condition: "resp.status == 200"
store_as: verdict
code: |
let body = if type_of(resp.body) == "string" { str_replace(resp.body, " ", "") } else { "" };
let want = "\"noctis_mvel\":[\"" + p.rev + "\"";
let want_scalar = "\"noctis_mvel\":\"" + p.rev + "\"";
let rce = stridx(body, want) >= 0 || stridx(body, want_scalar) >= 0;
if stridx(body, want_scalar) >= 0 { want = want_scalar; }
let ver = if type_of(banner) == "map" && type_of(banner.body) == "string" { str_replace(banner.body, " ", "") } else { "" };
let mvel_era = ereg("\"number\":\"(0\\.|1\\.[0-3]\\.)", ver);
let empty = !rce && mvel_era
&& ereg("\"_shards\":\\{\"total\":[1-9][0-9]*,\"successful\":[1-9][0-9]*,\"failed\":0\\}", body)
&& ereg("\"hits\":\\{\"total\":0,", body)
&& !ereg("(?i)ScriptException|scripting|failures", body);
#{ rce: rce, empty: empty, want: want }
- id: confirm-rce
action: match
condition: "resp.status == 200"
source: verdict.rce
pattern: "true"
on_match:
finding:
title: "Elasticsearch executes dynamic MVEL scripts — remote code execution (CVE-2014-3120)"
description: "A _search request carrying an MVEL script_fields script made the node instantiate java.lang.StringBuilder and return a random token reversed. Dynamic MVEL scripting is enabled and unsandboxed, so any client that reaches this port can run arbitrary Java code (and OS commands) as the Elasticsearch user."
remediation: "Upgrade to Elasticsearch >= 1.2 (dynamic scripting disabled by default) or set script.disable_dynamic: true, and never expose port 9200 to untrusted networks."
confidence_delta: 0.65
qod: 97
evidence: "MVEL script new java.lang.StringBuilder(\"{{p.tok}}\").reverse() returned {{verdict.want}}; response (HTTP {{resp.status}}): {{resp.body}}"
- id: confirm-accepted
action: match
condition: "resp.status == 200"
source: verdict.empty
pattern: "true"
on_match:
finding:
title: "Elasticsearch accepts dynamic MVEL scripts (CVE-2014-3120)"
description: "A _search request carrying an MVEL script_fields script was accepted by every shard (no script error), which a node with dynamic scripting disabled refuses at parse time. The cluster holds no document, so the script itself could not be run to confirm code execution."
remediation: "Upgrade to Elasticsearch >= 1.2 (dynamic scripting disabled by default) or set script.disable_dynamic: true, and never expose port 9200 to untrusted networks."
confidence_delta: 0.40
qod: 70
evidence: "MVEL script_fields request accepted by all shards with zero hits; response (HTTP {{resp.status}}): {{resp.body}}"