第50天:Web开发-JavaEE应用SpringBoot栈ActuatorSwaggerHeapDump提取自动化
1、安全开发-JavaEE-常见依赖-Actuator&Swagger
2、安全开发-JavaEE-安全问题-配置安全&接口测试
#开发框架-SpringBoot
参考:https://springdoc.cn/spring-boot/
一、SpringBoot-监控依赖-Actuator
SpringBoot Actuator模块提供了生产级别的功能,比如健康检查,审计,指标收集,HTTP跟踪等,帮助我们监控和管理Spring Boot应用。
1、开发使用:
①引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
②配置监控
#暴露
暴露基于->application.properties文件
management.endpoints.web.exposure.include=* ->所有的都暴露
暴露基于->application.yml文件(该文件和上面的application.properties文件效果一样,看具体的项目里面是哪一个文件用来进行actuator进行监控配置)
management:
endpoints:
web:
exposure:
include: '*'
#安全配置: ->配置后,可以使上面的暴露的文件被有效控制住,不会所有的都暴露
安全配置基于->application.propertie文件
management.endpoints.jmx.exposure.include=health management.endpoints.web.exposure.include=health
management.endpoint.env.enabled=false ->env不暴露
management.endpoint.heapdump.enabled=false ->headdump不暴露
安全配置基于->application.yml文件
management:
endpoint:
heapdump:
enabled: false #启用接口关闭
env:
enabled: false #启用接口关闭
2、 图像化Server&Client端界面
Server:引入Server依赖-开启(@EnableAdminServer)
引入Server依赖-开启(@EnableAdminServer)
Client:引入Client依赖-配置(连接目标,显示配置等)
引入Client依赖-配置(连接目标,显示配置等)
启动客户端+服务端并访问
点击上面的lan:8080即可显示客户端的actuator
3、安全问题
/actuator/heapdump文件泄漏
①JDumpSpider提取器:https://github.com/whwlsfb/JDumpSpider ->用来提取headdump文件中的泄露信息
②heapdump_tool提取器:https://github.com/wyzxxz/heapdump_tool->用来提取headdump文件中的泄露信息->分析提取出敏感信息(配置帐号密码,接口信息 数据库 短信 云应用等配置)
实战案例:
https://mp.weixin.qq.com/s/IP8BHeZaroJpJBvmF64vAw
4、额外安全:
https://github.com/LandGrey/SpringBootVulExploit
https://github.com/wh1t3zer/SpringBootVul-GUI
例子:SpringCloud Gateway RCE(CVE-2022-22947)
->创建SpringCloud Gateway+Actuator项目
->更改项目版本及漏洞Gateway依赖版本
<spring-boot.version>2.5.2</spring-boot.version>
<spring-cloud.version>2020.0.3</spring-cloud.version>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
<version>3.1.0</version>
</dependency>
->启动项目进行测试
参考:https://www.cnblogs.com/qgg4588/p/18104875
漏洞复现要成功->需先修改yml文件中的内容
二、SpringBoot-接口依赖-Swagger
Swagger是当下比较流行的实时接口文文档生成工具。接口文档是当前前后端分离项目中必不可少的工具,在前后端开发之前,后端要先出接口文档,前端根据接口文档来进行项目的开发,双方开发结束后可通过swagger的API接口进行联调测试。
参考:https://blog.csdn.net/lsqingfeng/article/details/123678701
1、开发使用
①引入依赖
<--2.9.2版本-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
<--3.0.0版本-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
②配置访问
#application.properties
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
#application.yml
spring
mvc:
pathmatch:
matching-strategy: ant_path_matcher
2.X版本启动需要注释@EnableSwagger2
3.X版本不需注释,写的话是@EnableOpenApi
2.X访问路径:http://ip:port/swagger-ui.html
再此访问http://ip:port/swagger-ui.html
3.X版本访问路径:http://ip:port/swagger-ui/index.html
③安全问题
自动化测试:Apifox Reqable Postman
泄漏应用接口:用户登录,信息显示,上传文件等(swagger泄露的接口很多,无法一一测试,需要根据泄露的api接口名字,有针对性的去测试)
Apifox->是一款自动化测试接口的工具->可用其来测swagger的接口
可用于对未授权访问,信息泄漏,文件上传等安全漏洞的测试.