45

使用 MAT 查找 spring heapdump 中的密码明文

 4 years ago
source link: https://www.landgrey.me/blog/16/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

一. 前言

访问 /env 接口时,spring actuator 会将一些带有敏感关键词 (如 password、secret) 的属性名对应的属性值用 ****** 号替换,以达到脱敏的效果。

在目标既不出网, /jolokia 接口又没有合适的 MBean 或者不支持 POST 请求的情况下,很多获取被星号脱敏的密码的明文的方法就失效了。

这时候就可以利用 Eclipse Memory Analyzer 工具来分析 /heapdump/actuator/heapdump 接口下载的 jvm heap 信息,查找密码明文。

二. 查找方法

使用 Eclipse Memory Analyzer 直接打开下载的 heapdump 文件,点击 OQL 标签,在查询框中输入

select * from org.springframework.web.context.support.StandardServletEnvironment

然后点击红色感叹号执行查询。

  • 如下图, spring boot 1.x 版本 heapdump 查询结果,最终结果存储在 java.util.Hashtable$Entry 实例的键值对中:

yAFjUfn.png!web

所以也可以用

select * from java.util.Hashtable$Entry x WHERE (toString(x.key).contains("password"))

来查询。

  • 下图为 spring boot 2.x 版本 heapdump 查询结果,最终结果存储在 java.util.LinkedHashMap$Entry 实例的键值对中:

UfayamM.png!web

所以也可以用

select * from java.util.LinkedHashMap$Entry x WHERE (toString(x.key).contains("password"))

来查询。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK