SpringCloudGateway(spel)漏洞复现 && Spring + Swagger 接口泄露问题

发布于:2025-06-25 ⋅ 阅读:(25) ⋅ 点赞:(0)

环境配置 gateway

Spring Cloud : 这个就是分布式的微服务组件     

微服务 : 一般指的是独立的,专注于一项功能的服务

Gateway 这个其实是个云端的网关配置(他的作用就是对访问web的流量进行防护比如一些爬虫的阻截)
新建项目的时候选择:

以上两个

新建项目的时候选择  cloudRounting 下的Gateway
和ops下的监控



<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
    <version>3.1.0</version>
</dependency>

配置一些pom.xml

还有一个配置就是配置上 Gateway的 yml

application.yml
server:
  port: 8081

management:
  endpoints:
    web:
      exposure:
        include: gateway
  endpoint:
    gateway:
      enabled: true
spring:
  cloud:
    gateway:
      routes:
        - id: baidu
          uri: 'https://www.baidu.com/'
          order: 8000
          predicates:
            - Path=/skip/baidu
          filters:
            - StripPrefix=2

更改springboot版本:

<spring-boot.version>2.5.2</spring-boot.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>

配置好之后直接运行 :

访问监控器 如果这是个正常的情况说明 对方的Actuator配置的非常好

但是这个 Gateway也是可以造成Spel注入漏洞的

前提条件就是对方需要开启了监控模式的同时 gateway配置端口泄露 

利用 :

Swagger配置和api的利用

简介 :

什么是  Swagger?

它的作用就是 对项目进行提前的测试运行到web中,这个api主要的作用就是进行测试项目各个页面的


它在开发的作用就是进行api接口的测试 api在正常情况下是隐藏的 但是这个依赖项是可以对其进行测试的 因为api有很多的接口 使用这个可以更简单的进行测试 

这个功能类似于 :java自带的自我检测接口(接口就是指有参数能让web页面变化的东西)

使用Fafo 进行搜索 :

配置

新建项目的时候只需要选择一个

pom文件
1、引入依赖
先引用 2.9版本的
<--2.9.2版本-->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>
不同版本的服务端不同 :/swagger-ui.html

<--3.0.0版本-->
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-boot-starter</artifactId>
  <version>3.0.0</version>
</dependency>

/swagger-ui/index.html
2、 服务配置 :@EnableSwagger  第几版本就写几 如 @EnableSwagger2



3、配置访问
#application.properties
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
或
#application.yml
spring
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

注意一点就是 不要把 SpringBootApplication删掉 这个是spring必须有的东西

运行:

利用介绍

例如这个 这些是api接口的参数 我们可以通过操作参数来测试其安全性

但是大规模的参数我们怎么辨别敏感的:就是通过参数的名字或者api的名字 如api的名字是 user admin等

练习 :

这边建一个 RCE的利用文件

这样就能触发 whoami

但是在

这么多接口面前 就需要使用工具进行api的分析

工具分析Swagger api 接口

使用 :

导入之后就能在接口找到

然后把接口的数据进行导入到测试项目去