针对Swagger接口泄露未授权访问的各种姿势
字数 1748 2025-08-29 08:30:25
Swagger接口泄露与未授权访问漏洞全面指南
0x1 漏洞概述
Swagger是一个用于生成、描述、调用和可视化RESTful风格Web服务的完整框架。当开发人员配置不当,可能导致以下安全问题:
- Swagger接口文档未授权访问:攻击者可以无需认证查看API文档
- 敏感信息泄露:通过API文档获取系统功能接口的详细参数
- API滥用风险:攻击者可构造payload对系统API进行攻击
0x2 常见Swagger未授权访问路径
以下是Swagger UI常见的默认访问路径(应检查这些路径是否存在未授权访问):
/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
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
0x3 检测工具与方法
1. 自动化扫描工具
SpringBoot-Scan工具:
python SpringBoot-Scan.py -u url
该工具可自动化扫描Spring Boot相关漏洞,包括Swagger接口泄露。
2. FOFA搜索引擎
使用FOFA检索可能存在Swagger或Spring Boot漏洞的站点:
body="Whitelabel Error Page"
3. Swagger UI浏览器插件
Google Chrome插件:
https://chromewebstore.google.com/detail/liacakmdhalagfjlfdofigfoiocghoej?hl=zh
该插件可帮助分析Swagger接口文档。
0x4 加密Swagger接口的利用
当遇到需要认证的Swagger接口时:
- 首先访问
swagger/v1/swagger.json文件目录 - 使用swagger-hack工具自动化测试所有接口:
python3 swagger-hack2.0.py -u ip地址
工具地址:
https://github.com/jayus0821/swagger-hack
扫描完成后会生成swagger.csv文档,包含泄露的接口信息。
0x5 Spring Boot相关接口泄露
常见Spring Boot Actuator端点泄露路径:
| 路径 | 描述 |
|---|---|
/actuator |
查看开放的Actuator端点 |
/actuator/auditevent |
提供应用程序审计事件信息 |
/actuator/beans |
提供应用程序bean信息 |
/actuator/conditions |
提供配置和自动配置类条件评估信息 |
/actuator/configprops |
提供@ConfigurationPropertiesbean信息 |
/actuator/env |
查看全部环境属性(自动隐藏关键字段) |
/actuator/flyway |
提供Flyway数据库迁移信息 |
/actuator/health |
提供应用程序运行状况信息 |
/actuator/heapdump |
提供JVM堆转储(可能含敏感数据) |
/actuator/httptrace |
提供HTTP请求-响应交换信息(含Cookie等) |
/actuator/info |
提供应用程序的一般信息 |
高危端点:
/actuator/env:可能泄露数据库密码等敏感信息/actuator/heapdump:堆转储文件可能包含明文密码/actuator/httptrace:可能泄露用户Cookie等会话信息
0x6 漏洞利用流程
-
信息收集:
- 使用工具扫描或手动检查常见Swagger路径
- 检查Spring Boot错误页面(
Whitelabel Error Page)
-
接口分析:
- 访问
swagger.json或api-docs获取API文档 - 检查Actuator端点
- 访问
-
敏感信息提取:
- 从环境变量、配置属性中寻找凭证
- 分析堆转储文件获取内存中的敏感数据
-
权限提升:
- 利用获取的凭证尝试登录系统
- 构造API请求进行未授权操作
0x7 防御措施
-
访问控制:
- 限制Swagger UI和API文档的访问权限
- 配置认证机制保护敏感端点
-
生产环境配置:
- 生产环境禁用Swagger UI
- 关闭不必要的Actuator端点
-
敏感信息保护:
- 使用环境变量加密敏感配置
- 避免在代码中硬编码凭证
-
监控与日志:
- 监控对API文档和Actuator端点的访问
- 记录异常API请求
0x8 法律与道德声明
- 文章中涉及的敏感信息均已做打码处理
- 文章仅做经验分享用途,切勿用于非法目的
- 未授权的攻击属于非法行为
- 传播、利用本文章所提供的信息而造成的任何后果及损失,均由使用者本人负责