Spring Boot框架actuator配置不当漏洞

漏洞描述

【安全预警】

Apache Dubbo 远程代码执行漏洞、Spring Boot配置不当及微软1月补丁漏洞部分网站数据库存在Spring Boot 配置不当漏洞,利用网站数据库Spring Boot 漏洞可读取 Redis 数据库用户名 和密码。连接数据库可查询掌握运维综合服务平台管理员口令哈希。

漏洞等级

影响范围

所有版本

排查方法

确定是SpringBoot框架后,枚举站点的一级、二级甚至三级目录,查看目录下面是否存在actuator执行端点路径

在application.properties配置文件中查看actuator的访问路径

如 设置management.context-path=/monitor

则访问访问ip:port/monitor/actuator

默认配置下 management.context-path=/

此时访问ip:port/actuator 暴露配置信息

根据actuator信息知道可以访问/actuator/health 和 /actuator/info

Actuator模块下路径功能

修复措施

方案一

可以在application.properties配置文件修改配置

开启业务需求上必须的端口(建议全部禁用

通过配置management.endpoint.<端点名称>.enabled为true/false来开启/禁用端口``

通过配置management.endpoint.web.exposure.include=xxx 来暴露某个web端点

通过配置management.endpoint.web.exposure.exclude=xxx 来隐藏某个web端点

暴露所有端点

management.endpoints.web.exposure.include=*

隐藏(不暴露)端点info

management.endpoints.web.exposure.exclude=info

隐藏(不暴露)端点env beans

management.endpoints.web.exposure.exclude=env,beans

方案二

引入安全依赖,增加验证环节

引入spring-boot-starter-security依赖

在application.properties中指定actuator的端口以及开启security功能

 

 

endpoint

endpoint 是我们使用 Spring Boot Actuator 最需要关心的对象,列举一些常用的 endpoint

IDDescription
beans 查看 Spring 容器中的所有对象
configprops 查看被 @ConfigurationProperties 修饰的对象列表
env 查看 application.yaml 配置的环境配置信息
health 健康检查端点
info 应用信息
metrics 统计信息
mappings 服务契约 @RequestMapping 相关的端点
shutdown 优雅下线

例如 health,只需要访问如下 endpoint 即可获取应用的状态

curl "localhost:8080/actuator/health"

endpoint 的 enable 和 exposure 状态

Spring Boot Actuator 针对于所有 endpoint 都提供了两种状态的配置

  • enabled 启用状态。默认情况下除了 shutdown 之外,其他 endpoint 都是启用状态。这也很好理解,其他 endpoint 基本都是查看行为,shutdown 却会影响应用的运行状态。
  • exposure 暴露状态。endpoint 的 enabled 设置为 true 后,还需要暴露一次,才能够被访问,默认情况下只有 health 和 info 是暴露的。enabled 不启用时,相关的 endpoint 的代码完全不会被 Spring 上下文加载,所以 enabled 为 false 时,exposure 配置了也无济于事。
/**
 *几个典型的配置示例如下
 */

// 启用并暴露所有 endpoint
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    shutdown:
      enabled: true

// 只启用并暴露指定 endpoint
management:
  endpoints:
    enabled-by-default: false
  endpoint:
    info:
      enabled: true
  endpoints:
    web:
      exposure:
        include: "info"

// 禁用所有 endpoint
management:
  endpoints:
    enabled-by-default: false

Spring Boot Actuator 的安全风险

Spring Boot Actuator 提供的一些 endpoint 是会将应用重要的信息暴露出去的,以 env 为例来查看典型的 application.yaml 的示例

server:
  port: 8080
spring:
  datasource:
   url: jdbc:mysql://localhost:3306/test
   username: test
   password: 123456
liuhuan:
  ak: 123456
  sk: 123456
management:
  endpoints:
    web:
      exposure:
        include: "*"

我们看看访问 localhost:8080/actuator/env 之后的返回值

{
  "activeProfiles": [],
  "propertySources": [
    {
      "name": "server.ports",
      "properties": {
        "local.server.port": {
          "value": 8080
        }
      }
    },
    {
      "name": "Config resource 'class path resource [application.yaml]' via location 'optional:classpath:/'",
      "properties": {
        "server.port": {
          "value": 8080,
          "origin": "class path resource [application.yaml] - 2:9"
        },
        "spring.datasource.url": {
          "value": "jdbc:mysql://localhost:3306/test",
          "origin": "class path resource [application.yaml] - 5:44"
        },
        "spring.datasource.username": {
          "value": "test",
          "origin": "class path resource [application.yaml] - 6:15"
        },
        "spring.datasource.password": {
          "value": "******",
          "origin": "class path resource [application.yaml] - 7:15"
        },
        "liuhuan.ak": {
          "value": "123456",
          "origin": "class path resource [application.yaml] - 10:7"
        },
        "liuhuan.sk": {
          "value": "123456",
          "origin": "class path resource [application.yaml] - 11:7"
        },
        "management.endpoints.web.exposure.include": {
          "value": "*",
          "origin": "class path resource [application.yaml] - 17:18"
        }
      }
    }
  ]
}

可以发现,对于内置的敏感配置信息 spring.datasource.password,Spring Boot Actuator 是进行了脱敏的,但是对于自定义的一些敏感配置,如 liuhuan.ak 和 liuhuan.sk 却被暴露出来了,在生产服务我们的机器都部署内网,并且一般都是通过反向代理对外暴露的服务,这类 endpoint 是不会被外部用户访问到的。但还是会有些情况会导致安全漏洞,例如:

  • 反向代理误配置了根节点,将 actuator 的 endpoint 和 web 服务一起暴露了出去
  • 线上配置没问题,测试环境部署时开通了公网 SLB,导致 actuator 的 endpoint 暴露了出去
  • 同一环境中某台机器被攻陷,导致应用配置信息泄露

安全建议

  1. 最小粒度暴露 endpoint。只开启并暴露真正用到的 endpoint,而不是配置:management.endpoints.web.exposure.include=*
  2. 为 endpoint 配置独立的访问端口,从而和 web 服务的端口分离开,避免暴露 web 服务时,误将 actuator 的 endpoint 也暴露出去。例:management.port=8099
  3. 引入 spring-boot-starter-security 依赖,为 actuator 的 endpoint 配置访问控制
  4. 慎重评估是否需要引入 spring-boot-stater-actuator
posted @ 2024-01-25 20:17  夏威夷8080  阅读(741)  评论(0编辑  收藏  举报