Skip to content

Commit 041c715

Browse files
authored
Merge pull request #2064 from HackTricks-wiki/research_update_src_network-services-pentesting_pentesting-web_grafana_20260328_130736
Research Update Enhanced src/network-services-pentesting/pen...
2 parents ebee807 + 4c05101 commit 041c715

1 file changed

Lines changed: 67 additions & 7 deletions

File tree

  • src/network-services-pentesting/pentesting-web

src/network-services-pentesting/pentesting-web/grafana.md

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,58 @@
44

55
## Interesting stuff
66

7-
- The file **`/etc/grafana/grafana.ini`** can contain sensitive information such as **admin** **username** and **password.**
8-
- Inside the platform you could **invite people** or **generate API keys** (might need to be admin)
9-
- You could check which plugins are installed (or even install new)
10-
- By default it uses **SQLite3** database in **`/var/lib/grafana/grafana.db`**
11-
- `select user,password,database from data_source;`
7+
- Main config is usually in **`/etc/grafana/grafana.ini`** (Deb/RPM) and can contain sensitive values such as **`admin_user`**, **`admin_password`**, **`secret_key`**, OAuth settings, SMTP creds, and renderer tokens.
8+
- By default Grafana stores data in **SQLite3** under **`/var/lib/grafana/grafana.db`**.
9+
- Provisioning files are very interesting after host access:
10+
- **`/etc/grafana/provisioning/datasources/*.yaml`**
11+
- **`/etc/grafana/provisioning/plugins/*.yaml`**
12+
- Environment-variable expansion is supported in provisioning files, so leaked YAML often reveals both secrets and the env var names backing them.
13+
- Installed plugins are commonly found under **`/var/lib/grafana/plugins`**.
14+
- Inside the platform you could **invite people**, **generate API keys / service account tokens**, **list plugins**, or **install new plugins** depending on the role.
15+
- The browser is also loot: Grafana exposes non-secret datasource config to the frontend. If you have a **Viewer** session (or **anonymous access** is enabled), inspect **`window.grafanaBootData`** from DevTools.
16+
17+
Useful SQLite checks:
1218

13-
---
19+
```sql
20+
.tables
21+
.schema data_source
22+
SELECT id,org_id,name,type,url,access,is_default,json_data FROM data_source;
23+
SELECT id,org_id,uid,login,email,is_admin FROM user;
24+
SELECT id,org_id,uid,name,slug FROM dashboard;
25+
```
26+
27+
## Looting datasources and secrets
28+
29+
Grafana separates browser-readable configuration from encrypted secrets:
30+
31+
- **`jsonData`** is visible to users in the browser and is commonly enough to enumerate internal hosts, tenants, auth modes, header names, AWS regions, Elasticsearch indexes, Loki tenants, Prometheus URLs, and similar recon data.
32+
- **`secureJsonData`** is encrypted server-side and no longer readable from the browser after the datasource is saved.
33+
34+
Post-exploitation workflow:
35+
36+
1. Dump **`grafana.ini`** and recover **`secret_key`**.
37+
2. Loot **`grafana.db`** and provisioning files.
38+
3. Enumerate datasources and plugin configuration to find reusable credentials and internal endpoints.
39+
4. If migrating or replaying the database in another Grafana instance, keep the same **`secret_key`** or stored datasource passwords/tokens will not decrypt correctly.
40+
41+
Why **`secret_key`** matters in newer versions:
42+
43+
- Since Grafana v9, database secrets use envelope encryption.
44+
- Grafana encrypts secrets with **data encryption keys (DEKs)**, and those DEKs are encrypted with a **key encryption key (KEK)** derived from **`secret_key`**.
45+
- From an attacker perspective, **`grafana.db` + `secret_key`** is the pair worth stealing.
46+
47+
## Plugin attack surface
48+
49+
Treat plugins as part of the target, not a footnote:
50+
51+
- Enumerate them from the filesystem, from the UI, or from the API:
52+
53+
```bash
54+
curl -s http://grafana.target/api/plugins | jq '.[].id'
55+
```
56+
57+
- Older or third-party plugins regularly expand Grafana's reach into internal networks because they proxy HTTP requests or interact with local files/databases.
58+
- Recent examples include SSRF in the **Infinity** plugin (`< 3.4.1`) and abuse paths where the **Image Renderer** plugin turns another bug into **full-read SSRF**.
1459

1560
## CVE-2024-9264 – SQL Expressions (DuckDB shellfs) post-auth RCE / LFI
1661

@@ -25,7 +70,7 @@ Impact
2570
Quick checks
2671
- In the UI/API, browse Admin settings (Swagger: `/swagger-ui`, endpoint `/api/admin/settings`) to confirm:
2772
- `expressions.enabled` is true
28-
- Optional: version (e.g., v11.0.0 vulnerable), datasource types, etc.
73+
- Optional: version, datasource types, and general hardening settings
2974
- Shell on host: `which duckdb` must resolve for the exploit path below.
3075

3176
Manual query pattern using DuckDB + shellfs
@@ -64,10 +109,25 @@ python3 CVE-2024-9264.py -u <USER> -p <PASS> \
64109
```
65110
If output shows `uid=0(root)`, Grafana is running as root (common inside some containers).
66111

112+
## 2025 client-side traversal / open redirect chain
113+
114+
The 2025 Grafana client-side traversal and open-redirect chain is already documented in more generic client-side pages. Use those techniques against Grafana-specific paths such as plugin assets, dashboard script loaders, and token-rotation redirects:
115+
116+
{{#ref}}
117+
../../../pentesting-web/client-side-path-traversal.md
118+
{{#endref}}
119+
120+
{{#ref}}
121+
../../../pentesting-web/open-redirect.md
122+
{{#endref}}
67123

68124
## References
69125

70126
- [Grafana Advisory – CVE-2024-9264 (SQL Expressions RCE/LFI)](https://grafana.com/security/security-advisories/cve-2024-9264/)
127+
- [Grafana docs – Add authentication for data source plugins (`jsonData`, `secureJsonData`, `window.grafanaBootData`)](https://grafana.com/developers/plugin-tools/how-to-guides/data-source-plugins/add-authentication-for-data-source-plugins)
128+
- [Grafana docs – Configure database encryption](https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-database-encryption/)
129+
- [Grafana docs – Provision Grafana](https://grafana.com/docs/grafana/latest/administration/provisioning/)
130+
- [Cycode – One Plugin Away: Breaking Into Grafana from the Inside](https://cycode.com/blog/one-plugin-away-breaking-into-grafana-from-the-inside/)
71131
- [DuckDB shellfs community extension](https://duckdb.org/community_extensions/extensions/shellfs.html)
72132
- [nollium/CVE-2024-9264 PoC](https://github.com/nollium/CVE-2024-9264)
73133
- [cfreal/ten framework](https://github.com/cfreal/ten)

0 commit comments

Comments
 (0)