第39天:安全开发-JavaEE应用&SpringBoot框架&Actuator监控泄漏&Swagger自动化
本文发布于541天前,本文最后更新于541 天前,其中的信息可能已经过时,如有错误请留言或评论。

知识点

  1. JavaEE-SpringBoot-监控系统-Actuator
  2. JavaEE-SpringBoot-接口系统-Swagger
  3. JavaEE-SpringBoot-监控&接口&安全问题

SpringBoot-演示案例

创建Spring项目,和之前的一样,自行选择依赖即可。

监控系统-Actuator

了解

  • SpringBoot Actuator模块提供了生产级别的功能,比如健康检查,审计,指标收集,HTTP跟踪等,
    帮助我们监控和管理Spring Boot应用。
  • Actuator端点图

开发使用

  1. 创建spring项目,依赖选择Web中的Spring Web,Ops中的Spring Boot Actuator
  2.  引入依赖
    • 当创建项目时未选择actuator依赖时,可在配置文件pom.xml中自行引入
      <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
      </dependency>
  3. 配置监控
    • 在application.properties进行如下配置
      # 这个配置项是用于指定要暴露的web端点。*表示暴露所有端点。
      management.endpoints.web.exposure.include=*
      # 这个配置项用于指定是否显示健康检查的详细信息。always表示总是显示详细信息。
      management.endpoint.health.show-details=always
  4. 图像化Server&Client端界面
    • Server:
      • 创建项目选择Ops中的codecentric's Spring Boot Admin (Server)
        或在pom.xml中引入Actuator-Server依赖-开启(@EnableAdminServer)
      • 在启动文件的@SpringBootApplication前添加@EnableAdminServer即可
    • Client:
      • 创建项目选择Ops中的codecentric's Spring Boot Admin (Client)
        或在pom.xml中引入Actuator-Client依赖
      • 在application.properties中配置(连接目标,显示配置等)
        # 连接目标,这是Spring Boot Admin服务器的URL,用于客户端连接和注册。
        spring.boot.admin.client.url=http://127.0.0.1:8888
        # 这个配置项是用于指定要暴露的web端点。*表示暴露所有端点。 
        management.endpoints.web.exposure.include=* 
        # 这个配置项用于指定是否显示健康检查的详细信息。always表示总是显示详细信息。 
        management.endpoint.health.show-details=always
    • 然后启动这两个springboot项目,访问Server设定的端口就能看到Actuator的ui界面
  5. 安全配置:
    • 在application.properties进行如下配置,关闭某些端点的启用,防止敏感信息泄露
      management.endpoint.env.enabled=false
      management.endpoint.heapdump.enabled=false

安全问题

heapdump泄漏

这个泄露不算漏洞,只是获取泄露出来的信息进行利用,从而发现漏洞

可以访问开启Actuator的spring网站下面的url获取heapdump文件,然后利用下面的工具进行分析

http://xxx.xxx.xxx:xxxx/actuator/heapdump
  • jvisualvm分析器
    • 安装jdk自带,文件搜索获取
      如:D:\jdk1.8.0_112\bin\jvisualvm.exe
  • JDumpSpider提取器
    • 下载地址:https://github.com/whwlsfb/JDumpSpider/releases
    • 分析提取出敏感信息(配置帐号密码,接口信息 数据库 短信 云应用等配置)
    • 使用方式
      java -jar .\JDumpSpider-1.1-SNAPSHOT-full.jar .\heapdump

其他利用

见下文:https://blog.csdn.net/drnrrwfs/article/details/125242990
分析得到有一些组件(不安全的组件,如log4j)

接口系统-Swagger

了解

  • Swagger是当下比较流行的实时接口文文档生成工具。接口文档是当前前后端分离项目中必不可少的工具,在前后端开发之前,后端要先出接口文档,前端根据接口文档来进行项目的开发,双方开发结束后在进行联调测试。
  • 参考:https://blog.csdn.net/lsqingfeng/article/details/123678701

开发使用

  1. 引入依赖
    • 这个的话IDEA里面创建spring项目的时候依赖里面是没有的,所以需要自己引入一下
    • 在pom.xml中的dependencies标签中添加下面内容
    • 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>
  2. 配置访问
    在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
    3.X访问路径:http://ip:port/swagger-ui/index.html

安全问题

自动化测试:Postman
泄漏应用接口:用户登录,信息显示,上传文件等
可用于对未授权访问,信息泄漏,文件上传等安全漏洞的测试.

参考

学习内容均来自小迪安全系列课程:http://xiaodi8.com/

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇