漏洞描述
Apache Solr
是一个开源的搜索服务,使用Java
语言开发。Apache Solr
的某些功能存在过滤不严格,在Apache Solr
未开启认证的情况下,攻击者可直接构造特定请求开启特定配置,并最终造成SSRF和文件读取漏洞。
综上,存在两个漏洞:任意文件读取和SSRF,同时SSRF也可以导致任意文件读取。
漏洞详情
两个漏洞在同一个HTTP请求中触发,分别对应不同的参数,触发漏洞的url为_http://x.x.x.x:8983/solr/newcore/debug/dump?stream.url=file:///etc/passwd¶m=ContentStream&stream.file=/etc/passwd_
,其中,newcore
是solr中core的名称,可通过solr控制面板创建及查看;漏洞分别对应以下两个参数:
stream.url
触发SSRF漏洞,Java中可利用file协议利用SSRF,可用来实现任意文件读取
stream.file
参数触发任意文件读取漏洞
一、手工分析
手工分析代码时,一般是看源码,然后debug,效率偏低。手工分析的过程不再赘述,漏洞的核心原因见下面代码:
ava
private SolrQueryRequest buildRequestFrom(SolrCore core, SolrParams params, Collection<ContentStream> streams, RTimerTree requestTimer, final HttpServletRequest req) throws Exception {
String contentType = params.get("stream.contentType");
String[] strs = params.getParams("stream.url");
// 省略若干代码
for(var10 = 0; var10 < var9; ++var10) {
body = var8[var10];
// stream.url 导致SSRF
ContentStreamBase stream = new URLStream(new URL(body));
if (contentType != null) {
stream.setContentType(contentType);
}
streams.add(stream);
}
strs = params.getParams("stream.file");
var8 = strs;
var9 = strs.length;
for(var10 = 0; var10 < var9; ++var10) {
body = var8[var10];
// stream.file参数导致任意文件读取
ContentStreamBase stream = new FileStream(new File(body));
if (contentType != null) {
stream.setContentType(contentType);
}
streams.add(stream);
}
// 省略代码
}
二、灵芝IAST(洞态IAST)自动挖掘漏洞
洞态IAST检测该漏洞,需要以下:
- 使用
vulhub-cli
创建安装灵芝IAST的solr环境(vulhub-cli教程见文末链接)
- 使用浏览器访问solr,触发相关的URL
- 前往洞态IAST的搜索页面,输入漏洞对应的
sink
方法,搜索漏洞
洞态IAST的结果如下,漏洞实时检测:

上图中,蓝色的线条代表污点的流向,图中共搜索到两条污点调用链,一条指向java.io.File.<init>
方法,另一条指向java.net.URL.openConnection
方法;分别对应任意文件读取漏洞和SSRF漏洞;
两个漏洞的污点调用链存在重合不分,下面先分析重合的污点链
1. 寻找污点来源
根据污点调用链找到污点的起始位置:发现在org.apache.solr.servlet.SolrRequestParsers$StandardRequestParser.parseParamsAndFillStreams
方法中,调用getQueryString
方法获取HTTP参数,拿到初始污点

2. 跟踪污点变化
根据污点调用链跟踪污点的变化:在org.apache.solr.servlet.SolrRequestParsers$StandardRequestParser.parseParamsAndFillStreams
方法中,调用parseQueryString
方法对污点进行解析,转换为MultiMapSolrParams
对象

根据污点调用链跟踪污点的变化:在buildRequestFrom
方法中,调用MultiMapSolrParams.getParams
方法,获取污点

到此为止,公共污点链结束,接下来是两个漏洞独立的调用链,我们分别分析:
3. SSRF漏洞
继续根据污点调用链跟踪污点的变化:接下来的污点链就清晰了很多,分别是用污点创建URL
对象和调用URL
对象的openConnection
方法触发漏洞,详细的调用链如下:

利用污点数据创建URL

URL
对象调用openConnection
方法触发漏洞

4. 任意文件读取漏洞
任意文件读取的链路与SSRF的链路类似,使用污点创建File
对象,然后读取文件内容


更多漏洞,等你来发现
洞态IAST 现提供SaaS版本和开源版本,可自动化挖掘部分0 Day漏洞,可前往查看版本介绍并联系技术支持获取试用。
相关链接
本文迁移自知识星球“火线Zone”