1. 首页
  2. 渗透测试

Swagger-ui未授权访问漏洞

【推荐学习】暗月渗透测试培训 十多年渗透经验,体系化培训渗透测试 、高效学习渗透测试,欢迎添加微信好友aptimeok 咨询。

10.Swagger-ui未授权访问漏洞

漏洞名称

Swagger-ui未授权访问漏洞

漏洞地址

https://zhuanlan.zhihu.com/p/386709187

漏洞等级

中危

漏洞描述

Swagger是一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 服务,JAVA在金融机构开发语言的地位一直居高不下,而作为JAVA届服务端的大一统框架Spring,便将Swagger规范纳入自身的标准,建立了Spring-swagger项目,所以在实际测试环境中,基于spring框架的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

漏洞成因

Swagger未开启页面访问限制,Swagger未开启严格的Authorize认证。

漏洞危害

通过翻查文档,得到api接口,点击parameters,即可得到该api接口的详细参数。直接构造参数发包,通过回显可以得到大量的用户信息,包含了手机号,邮箱等。

修复方案

1.Swagger开启页面访问限制。2.Swagger开启Authorize认证。找到Startup文件,我们看到Swagger的配置如下:“` services.AddSwaggerGen(options => { options.SwaggerDoc(“v1”, new Info { Title = “YjJob API”, Version = “v1” }); options.DocInclusionPredicate((docName, description) => true); });

修改配置:

services.AddSwaggerGen(options => { options.SwaggerDoc(“v1”, new Info { Title = “YjJob API”, Version = “v1” }); options.DocInclusionPredicate((docName, description) => true); options.AddSecurityDefinition(“Bearer”, new ApiKeyScheme { Description = “Authorization format : Bearer {token}”, Name = “Authorization”, In = “header”, Type = “apiKey” });//api界面新增authorize按钮 });

修改后我们可以看到生成的Swagger UI界面新增了一个“Authorize”按钮:

![img](https://gitee.com/Monika_Mannix/mannix/raw/master/img/202112312342738.png)

点击“Authorize”按钮弹出以下界面

![img](https://gitee.com/Monika_Mannix/mannix/raw/master/img/202112312342013.png)

在value文本框中输入"Bearer "+token(登陆接口返回的access_token),然后点击“Authorize”按钮,之后再调用需要权限验证的接口就可以正常调用。

#### 测试过程

应用系统存在Swagger-ui未授权访问,可获取系统的API接口方法。

```html
http://0.0.0.0:8888/mobile/swagger-resources
http://0.0.0.0:8888/mobile/swagger-resources/configuration/ui
http://0.0.0.0:8888/mobile/swagger-resources/configuration/security
http://0.0.0.0:8888/mobile/swagger-ui.html
http://0.0.0.0:8888/mobile/v2/api-docs
http://0.0.0.0:8888/mobile/swagger-ui.html

成功遍历到用户

image-20211225153614961
image-20211225153946195

复测情况

已修复

测试人员

南风向晚

原创文章,作者:mOon,如若转载,请注明出处:https://www.moonsec.com/4096.html

联系我们

400-800-8888

在线咨询:点击这里给我发消息

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息