Grafana 任意檔案讀取漏洞 (CVE-2021-43798)學習

01發表於2021-12-12

漏洞概述

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

相關文章