近日,GitHub代碼中安全研究員S00pY發布一個Apache Solr Velocity模版注入遠程命令執行的POC,該漏洞通過WEB遠程執行,攻擊利用簡易,危害重點。截止目前該漏洞還未上報獲得PVE編號,Solr官方也沒有任何漏洞的補丁,建議使用Solr的用戶通過策略性設置封禁8983埠埠對外開放,以防止被人攻擊。
漏洞介紹:
Velocity Java 模板引擎: Velocity是一個基於Java的模板引擎。它允許任何人使用簡單但功能強大的模板語言來引用Java代碼中定義的對象。該模板引擎用java代碼執行,其基本語法如下:
// 變量定義
#set($name ="velocity")
// 變量賦值
#set($foo = $bar)
// 函數調用
#set($foo ="hello") #set(foo.name=bar.name) #set(foo.name=bar.getName($arg))
// 循環語法
#foreach($element in $list)
This is $element
$velocityCount
#end
// 執行模板
template.merge(context, writer);
於是通過最後調用的惡意template的merge方法,成功造成了RCE,漏洞執行調用鏈如下:
HttpSolrCall.call獲取responseWriter的時候,會根據參數wt的值去獲取reponseWriter對象,當wt為velocity時,VelocityResponseWriter內容如下:
最後調用了VelocityResponseWriter.write函數,通過createEngine函數,生成了包含custom.vrm->payload的惡意template的engine,
惡意的template放在engine的overridingProperties的params.resource.loader.instance和solr.resource.loader.instance中
這裡有一個很重要的點,要想讓惡意template進入params.resource.loader.instance和solr.resource.loader.instance中,是需要保證paramsResourceLoaderEnabled和solrResourceLoaderEnabled為True的,這也就是我們第一個數據包做的事情,
然後再VelocityResponseWriter.getTemplate就會根據我們提交的v.template參數獲取我們構造的惡意template
最終取出了惡意的template,並調用了它的merge方法,
漏洞範圍:
Apache Solr 5.x到8.2.0均受影響。
修複方案:
官方暫未給出修補補丁,建議通過限制Solr公網訪問的方法,防火牆開啟白名單策略,只允許對需要通訊的IP開放Solr默認8983埠。
參考文章:
freebuf/vuls/218730.html