Grafana 任意文件讀取漏洞 (CVE-2021-43798)學習


漏洞概述

Grafana是一個跨平台、開源的數據可視化網絡應用程序平台。用戶配置連接的數據源之后,Grafana可以在網絡瀏覽器里顯示數據圖表和警告。
Grafana 的讀取文件接口存在未授權,且未對文件地址進行過濾,導致可以目錄穿越/../../../../../../../../../os filepath實現系統任意文件讀取。

漏洞詳情

1、官方修復代碼:https://github.com/grafana/grafana/commit/c798c0e958d15d9cc7f27c72113d572fa58545ce

2、可以看到問題出在pkg/api/api.go中的 getPluginAssets()函數,如下:

通過pluginid得到插件信息,如果插件不存在就返回404;
通過requestedFile := filepath.Clean(web.Params(c.Req)["*"]) 文件path,並且通過了clean函數的處理,但這里沒有處理徹底,導致可以通過../../../../../方式繞過,pluginFilePath := filepath.Join(plugin.PluginDir, requestedFile) 拼接插件目錄。

poc:/public/plugins/exit-plugin-name/../../../../../../../../etc/passwd

3、官方修復增加了 rel, err := filepath.Rel("/", requestedFile),我們來看看go中的rel()函數是做什么的:
Rel(basepath, targpath string) (string, error),官方解釋有點繞,說人話就是:
函數返回值等於 targpath 減去 basepath ,要求 targpath 和 basepath 必須“都是相對路徑”或“都是絕對路徑”。

rel, err := filepath.Rel("/", requestedFile)/是絕對路徑,我們要實現目錄穿越的話,../../是相對路徑,因此這里就過不去,無法成功利用了。

影響范圍

Grafana 8.0.0-beta1 - 8.3.0

安全版本

Grafana >= 8.3.1
Grafana >= 8.2.7
Grafana >= 8.1.8
Grafana >= 8.0.7

受影響plugins

alertGroups
alertlist
alertmanager
annolist
barchart
bargauge
canvas
cloudwatch
dashboard
dashlist
debug
elasticsearch
gauge
geomap
gettingstarted
grafana-azure-monitor-datasource
grafana
graph
graphite
heatmap
histogram
influxdb
jaeger
live
logs
loki
mixed
mssql
mysql
news
nodeGraph
opentsdb
piechart
pluginlist
postgres
prometheus
stat
state-timeline
status-history
table-old
table
tempo
testdata
text
timeseries
welcome
xychart
zipkin>
yon


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM