{
"type": "note",
"title": "Spring Boot Dump文件转储利用",
"tags": [
"post",
"渗透测试"
],
"summary": "日常测试或攻防演练中像shiro,fastjson等漏洞已经越来越少了,但是随着spring boot框架的广泛使用,spring boot带来的安全问题也越来越多,本文仅介绍未授权现在heapdump获取数据库口令,达到连接数据库的目的。其他spring…",
"sources": [
"xlog"
],
"external_urls": [
"https://s4u2self.cc/Spring-Boot-Dump-wen-jian-zhuan-chu-li-yong-.md"
],
"date_published": "2023-03-22T13:28:24.908Z",
"content": "---\n\n## \n# **一、spring boot**\n日常测试或攻防演练中像shiro,fastjson等漏洞已经越来越少了,但是随着spring boot框架的广泛使用,spring boot带来的安全问题也越来越多,本文仅介绍未授权现在heapdump获取数据库口令,达到连接数据库的目的。其他spring boot安全漏洞请参考[https://xz.aliyun.com/t/7811](https://xz.aliyun.com/t/7811)\nHeap Dump也叫堆转储文件,是一个Java进程在某个时间点上的内存快照。Heap Dump是有着多种类型的。不过总体上heap dump在触发快照的时候都保存了java对象和类的信息。通常在写heap dump文件前会触发一次FullGC,所以heap dump文件中保存的是FullGC后留下的对象信息。具体参考:[https://blog.csdn.net/hehmxy/article/details/89114116](https://blog.csdn.net/hehmxy/article/details/89114116)\n# **二、未授权访问**\nspring boot未授权访问产生的安全问题还是比较严重的,env泄露等问题甚至可造成RCE。\n在某次测试过程中扫描目录发现heapdump文件可下载,通过mat工具对heapdump文件进行分析,可获取内存中保存的敏感信息。\n\n![](https://cdn.nlark.com/yuque/0/2023/png/21847644/1679491557485-26debff3-37cb-488e-984c-6bc6ea618150.png#averageHue=%23393c31&id=npjVi&originHeight=512&originWidth=904&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)\n访问该文件后即可下载\n![](https://cdn.nlark.com/yuque/0/2023/png/21847644/1679491557610-2b8d1458-32ec-448e-9bfc-17d6fc2d82fa.png#averageHue=%23fefefe&id=ckGmX&originHeight=84&originWidth=404&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)\n# **三、相关工具及语法**\nEclipse Memory Analyzer是一种快速且功能丰富的Java堆分析器,可进行查找内存泄漏并减少内存消耗。\n下载链接如下:[https://www.eclipse.org/mat/](https://www.eclipse.org/mat/)\n# **四、OQL**\nOQL是用于查询Java堆的类SQL查询语言。OQL允许过滤/选择从Java堆中获取的信息。虽然HAT已经支持预定义的查询,例如“显示类X的所有实例”,但OQL增加了更多的灵活性。OQL基于JavaScript表达式语言。\n# **五、分析heapdump**\n将heapdump文件拖入mat,mat对文件进行分析后,应该是这个样子的\n![](https://cdn.nlark.com/yuque/0/2023/png/21847644/1679491557683-979e5d3e-fb07-4b3b-8839-ebc769795b16.png#averageHue=%23fafafa&id=DskcI&originHeight=844&originWidth=1918&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)\n但是此处要注意一个坑,dump文件建议解压在一个不用的目录里,要不然会分析一堆文件回来。\n\n![](https://cdn.nlark.com/yuque/0/2023/png/21847644/1679491557774-77f23818-ea8d-4fa9-aa9f-fb1d6bef6929.png#averageHue=%23fcfbfa&id=nCmGC&originHeight=568&originWidth=794&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)\n使用此处的OOL按钮进行查询\n\n![](https://cdn.nlark.com/yuque/0/2023/png/21847644/1679491557856-6d87ff71-8d7d-49dd-9f0f-b2b43c8cbf9f.png#averageHue=%2393c19f&id=TMTKX&originHeight=113&originWidth=668&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)\n\n语法:\n```sql\nselect * from java.util.Hashtable$Entry x WHERE (toString(x.key).contains(\"password\"))\n```\n或者:\n```sql\nselect * from java.util.Hashtable$Entry x WHERE (toString(x.key).contains(\"想查询属性所带的关键字\")) //1.x\nselect * from java.util.LinkedHashMap$Entry x WHERE (toString(x.key).contains(\"password\")) //2.x\n```\n![](https://cdn.nlark.com/yuque/0/2023/png/21847644/1679491557933-12a270bf-51b0-4181-9607-fa1e50276072.png#averageHue=%23f9f8f6&id=q0UuO&originHeight=556&originWidth=1029&originalType=binary&ratio=1&rotation=0&showTitle=false&status=done&style=none&title=)\n即可查询出内存文件里所包含的数据库账号密码,如果IP地址运行外联即可利用。\n\n部分GitHub工具已经支持跑shiro key之类的了,故此文章细节有限。",
"attributes": [
{
"value": "Spring-Boot-Dump-wen-jian-zhuan-chu-li-yong-.md",
"trait_type": "xlog_slug"
}
]
}