0x01 漏洞描述 - Swagger未授权访问 -
Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务。总体目标是使客户端和文件系统作为服务器以同样的速度来更新。相关的方法,参数和模型紧密集成到服务器端的代码,允许API来始终保持同步。Swagger-UI会根据开发人员在代码中的设置来自动生成API说明文档,若存在相关的配置缺陷,攻击者可以未授权翻查Swagger接口文档,得到系统功能API接口的详细参数,再构造参数发包,通过回显获取系统大量的敏感信息。
0x02 漏洞等级
0x03 漏洞验证 Swagger 未授权访问地址存在以下默认路径:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 /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 /v3/api-docs.yaml
可以添加上述默认路径到dirsearch等目录扫描工具的字典中,再对目标网站进行扫描测试。
访问/swagger-ui/index.html即可查看生成的API接口文档。
可尝试测试功能接口参数,对系统数据进行增删改查等操作。
访问api-docs或者swagger.json可以获取Json格式的接口文档。
通过Json文档地址配合swagger-scan 工具,可批量获取API功能接口地址。
0x04 漏洞修复
若生产环境无需 Swagger,直接删除依赖或关闭功能。
若生产环境需保留 Swagger(如内部运维使用),需为 Swagger 路由添加认证。
仅允许白名单 IP 访问 Swagger,拒绝公网请求。
排查接口是否存在敏感信息泄露(例如:账号密码、SecretKey、OSS配置等),若有则进行相应整改。