针对Swagger接口泄露未授权访问的各种姿势
字数 1623 2025-08-22 22:47:30
Swagger接口泄露与未授权访问漏洞全面指南
0x1 漏洞概述
Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化RESTful风格的Web服务。当开发人员配置不当,可能导致以下安全问题:
- Swagger接口泄露:攻击者可以访问API文档,获取系统功能API接口的详细参数
- 未授权访问:由于访问控制措施不足,攻击者无需认证即可查看敏感API信息
- 信息泄露风险:通过获取的API信息构造payload,可能导致系统大量敏感信息泄露
0x2 常见Swagger未授权访问路径
以下是常见的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
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工具:
- GitHub地址:https://github.com/AabyssZG/SpringBoot-Scan
- 使用命令:
python SpringBoot-Scan.py -u url
Swagger-hack工具:
- GitHub地址:https://github.com/jayus0821/swagger-hack
- 功能:自动化爬取并自动测试所有swagger接口
- 使用命令:
python3 swagger-hack2.0.py -u ip地址 - 输出:生成swagger.csv文档,包含泄露的接口信息
2. 手动检测方法
- 使用Burp Suite对常见Swagger路径进行爆破
- 查找Swagger-UI插件中的"Authorize"关键字(可能需要输入加密信息)
- 直接访问
swagger/v1/swagger.json等JSON文件目录查看API信息
3. FOFA搜索引擎
使用FOFA检索语句查找潜在目标:
body="Whitelabel Error Page"(查找Spring-Boot经典报错页面)
0x4 Spring-Boot相关接口信息泄露
Swagger常与Spring-Boot框架一起使用,以下是与Spring-Boot相关的敏感接口:
Actuator端点泄露
/actuator # 查看开放的Actuator端点
/actuator/auditevent # 提供应用程序审计事件信息
/actuator/beans # 提供应用程序bean信息
/actuator/conditions # 提供配置和自动配置类条件评估信息
/actuator/configprops # 提供@ConfigurationProperties bean信息
/actuator/env # 查看全部环境属性(自动替换敏感字段)
/actuator/flyway # 提供Flyway数据库迁移信息
/actuator/health # 提供应用程序运行状况信息
/actuator/heapdump # 提供JVM堆转储(可能含敏感数据)
/actuator/httptrace # 提供HTTP请求-响应交换信息(可能泄露Cookie)
/actuator/info # 提供应用程序的一般信息(可能泄露版本信息)
/actuator/loggers # 获取服务器的日志级别
重点敏感接口分析
-
/actuator/env:
- 查看全部环境属性
- 可以看到SpringBoot载入的properties及其值
- 自动用
*替换key、password、secret等关键字的properties值
-
/actuator/heapdump:
- 提供来自应用程序JVM的堆转储
- 可能含有敏感数据如数据库密码明文
- 返回GZip压缩的JVM堆dump文件(50M-500M,有时大于2G)
-
/actuator/httptrace:
- 包含用户HTTP请求的Cookie数据,可能导致Cookie泄露
0x5 漏洞利用流程
-
信息收集:
- 使用工具或手动扫描Swagger常见路径
- 访问
swagger.json获取API文档
-
接口分析:
- 检查是否需要认证(Authorize关键字)
- 使用swagger-hack工具自动化测试接口
-
敏感信息提取:
- 从/env端点获取环境变量
- 从/heapdump分析堆转储
- 从/httptrace获取HTTP跟踪信息
-
权限提升:
- 利用获取的API信息构造有效payload
- 尝试未授权访问敏感操作接口
0x6 防御措施
-
访问控制:
- 对Swagger UI和API文档实施认证
- 限制访问IP范围
-
生产环境配置:
- 生产环境禁用Swagger UI
- 关闭不必要的Actuator端点
-
敏感信息保护:
- 避免在环境变量中存储明文密码
- 对敏感接口实施严格的权限控制
-
监控与日志:
- 监控对Swagger和Actuator端点的访问
- 记录异常访问行为
0x7 法律与道德声明
- 文章中涉及的敏感信息应做打码处理
- 文章仅做经验分享用途,切勿用于非法目的
- 未授权的攻击属于非法行为
- 传播、利用本文章所提供的信息而造成的任何后果及损失,均由使用者本人负责