环境搭建:
本地创建maven项目:https://start.spring.io/
pom.xml 引入如下依赖
1 | <dependency> |
application.properties 如下:
1 | server.port=9000 |
漏洞分析:
查看漏洞补丁
https://github.com/spring-cloud/spring-cloud-gateway/commit/b957599edcb26107d0e16d2675f7139a2be4d996

添加了.withAssignmentDisabled()方法,禁用在 SpEL 表达式中的赋值操作。
在 CVE-2022-22947 修复后,GatewayEvaluationContext 只能使用受限制的 SimpleEvaluationContext 类。相关文章提出,使用自定义 bean 和调用带有单个参数的方法依旧可以实现信息泄漏。于是官方又增加了 spring.cloud.gateway.restrictive-property-accessor.enabled 属性来禁止。
org.springframework.cloud.gateway.support.ShortcutConfigurable.GatewayEvaluationContext#GatewayEvaluationContext
关键点在于 RestrictivePropertyAccessor() 限制了读取属性为false,但写入属性继承父类 ReflectivePropertyAccessor.ReflectivePropertyAccessor() 默认为true。
org.springframework.cloud.gateway.support.ShortcutConfigurable.RestrictivePropertyAccessor
org.springframework.expression.spel.support.ReflectivePropertyAccessor#ReflectivePropertyAccessor()
攻击者可使用 @systemPropertiesBean、@environment等来修改关键配置属性,比如:
1、访问系统环境配置 /actuator/env:显示 spring.cloud.gateway.restrictive-property-accessor.enabled 为true

2、使用 @systemPropertiesBean 来设置 spring.cloud.gateway.restrictive-property-accessor.enabled = false,然后刷新路由。

3、再次访问 /actuator/env,可以看到被修改为 false

4、然后就可以使用 @environment、@configDataContextRefresher 等来获取系统环境配置信息或者DOS等恶意操作。


