> 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/nanocherryctf.md).

# NanoCherryCTF

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

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 a Nmap scan and find only two open ports. Port 22 with SSH and port 80 with a web server.

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

We adapt our `/etc/hosts` file to the room description and find an ice cream online shop.

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

The first interesting page we discover is the content.php page. Here, we can retrieve facts for a specific user.

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

The subsequent directory scan yielded no further useful findings.

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

Since the room description requires a specific hostname, additional subdomains may be present. We scan for additional subdomains / vhost and find `nano.cherryontop.thm`.

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

We don't discover anything conspicuous here for the time being,...

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

except for a login for the admin portal. \
Here, the question about the room description led me astray, as I was asked about molly's dashboard. I thought a certain user had to be related to molly. I used `cewl`, `cupp` and `usernameanarchy` to create word lists, but got no positive results. Let's continue for now.

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

This time the directory scan returns something interesting, command.php, which is probably located behind the login. The first thought was command injection, but we can only check that later.

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

## Shell As notsus

According to the history of the room, there is already a backdoor that should be used as the start of the challenge. A user `notsus` exists, with which we can log in via ssh.<br>

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

We use the credentials for login via SSH.

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

We get the hint that we can escalate via this user on `bob-boba`.

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

## Shell As bob-boba

We upgrade the shell and enumerate the machine. We find a cronjob that downloads and executes a script from `cherryontop.tld` as `bob-boba`. Nice, if we can edit the `/etc/hosts` we can provide the script ourselves, which for example executes a reverse shell and allows us to connect as `bob-boba`.

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

We may write in `/etc/hosts`, we add for one with our IP for `cherryontop.tld`.

```bash
echo '10.8.211.1 cherryontop.tld' >> /etc/hosts
```

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

Then we set up the folder structure and a script that executes a `nc mkfifo` rever shell, which we have generated on `revshells.com`. Then we start the `http server` on port `8000` and a `listener` on `4445` to catch the reverse shell.

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

We get a connection back as `bob-boba`.

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

Here we find a message and `chads` third piece of his password.

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

From the `/etc/passwd` we can see that there are three other users, two of whom will probably have the remaining parts of `chad`'s password.

<figure><img src="/files/10L7C3yAcSwurp9MVePM" alt=""><figcaption></figcaption></figure>

As already described, we find the third part of the password here.

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

When enumerating the machine as user `bob-boba`, nothing else was found. I must have focused too much here and ignored the other findings from before. My focus was entirely on the lateral movement of `bob-boba`, which was not possible. It turns out that each user can be accessed individually. At least we now know the username of molly.

I should have noticed that `bob-boba` has the third password part, and the description explicitly states that the challenge can be solved independently.

## Shell As molly-milk

We go back to the login page of `nano.cherryontop.thm` and see that we can enumerate usernames. As mentioned at the beginning, I was initially too focused on generating and checking users in the context of the username `molly-milk`. Using the `xato username list` or `top-usernames-shortlist.txt` from `SecLists`, however, we can enumerate a user, since if we enter a wrong username, we get that message `"This user doesn't exist"`.

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

We can either use `FuFF`, `hydra` or any other fuzzer to enumerate the user by matching for the message `"This user doesn't exist"`.

```bash
hydra -L /usr/share/wordlists/SecLists/Usernames/xato-net-10-million-usernames.txt -p asdf nano.cherryontop.thm http-post-form "/login.php:username=^USER^&password=^PASS^&submit=:F=This user doesn't exist"
```

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

We find the user puppet, now we just need to brute force the password. If the password is entered incorrectly, we receive the message `"Bad password"` to which we only have to match.

```bash
hydra -l puppet -P /usr/share/wordlists/rockyou.txt nano.cherryontop.thm http-post-form "/login.php:username=^USER^&password=^PASS^&submit=:Bad password"
```

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

With the credentials found `puppet:<REDACTED>`, we can log in to the dashboard and find the molly dashboard flag.

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

If we scroll down a little further, we find the password for `molly`.

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

Since we already know the username of molly through `notsus`/ `bob-boba`, we can log in to the machine via SSH as `molly-milk`. Here we find the first part of chad-cherrys password.

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

## Shell As sam-sprinkles

At `molly-milk`, too, we can't find a way to extend our rights, so we go back and take a look at what we've found so far. We still have the `content.php` page on `cherryontop.thm`. Here we can see that facts can be viewed for a specific user and ID. The username is Base32 encoded. Using CyberChef we can see that it is the user `guest`. We can see four facts, but maybe there are more!

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

We create a list of 10000 IDs.

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

Next, we use FFuF to enumerate all possible IDs for the user `guest`.

```bash
ffuf -u "http://cherryontop.thm/content.php?facts=FUZZ&user=I52WK43U" -w ids.txt -mc all -fr "Error"
```

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

We find more valid IDs outside the selectable, but none of them give us a hint to extend our privileges. We may have to change the user. Since we have already escalated to `molly-milk` and `bob-boba`, we are left with `chad-cherry` and `sam-sprinkles`. We encode the username `sam-sprinkles` to `Base32` and use it this time to query the 10000 IDs.

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

We find the same IDs again, but maybe they have a different entry this time.

```bash
ffuf -u "http://cherryontop.thm/content.php?facts=FUZZ&user=ONQW2LLTOBZGS3TLNRSXG===" -w ids.txt -mc all -fr "Error"
```

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

For the ID `43` we find the credentials for `sam-sprinkles`.

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

We use the found credentials of `sam-sprinkles` to login via SSH. Here we find the second password part of `chad-cherry`.

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

## Shell As chad-cherry

We just have to merge the password parts of `molly-milk`+`sam-sprinkles`+`bob-boba`. This way, we can log in as `chad-cherry` via SSH. Here we find the flag of `chad-cherry` and a WAV file with the ominous name `rootPassword.wav`. There is also a note in `Hello.txt` that `rootPassword.wav` contains the root password.

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

## Shell As root

We download the `rootPassword.wav` file for further analysis. This seems to be a stego challenge at the end.

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

When viewing the audio file in Audacity, we discover a pattern in the spectrogram view that resembles a digital signal. There may be another file, text or image embedded here.

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

After a search we find the following article which has a continuation of a series of techniques for audio steganography.&#x20;

{% embed url="<https://sumit-arora.medium.com/audio-steganography-the-art-of-hiding-secrets-within-earshot-part-2-of-2-c76b1be719b3>" %}

It could be SSTV to add other data to the audio file. We find a script to decode at the following link:

{% embed url="<https://github.com/colaclanth/sstv>" %}

After we have set up the prerequisites, we can run the script and get an image out of the WAV file.

```bash
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/nanocherry]
└─$ git clone https://github.com/colaclanth/sstv.git
                                                                                                                                                                
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/nanocherry]
└─$ cd sstv      

┌──(0xb0b㉿kali)-[~/Documents/tryhackme/nanocherry/sstv]
└─$ python -m venv sstv_venv 
                                                                                                                                                                
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/nanocherry/sstv]
└─$ . ./sstv_venv/bin/activate 
                                                                                                                                                                
┌──(sstv_venv)─(0xb0b㉿kali)-[~/Documents/tryhackme/nanocherry/sstv]
└─$ python setup.py install

```

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

This shows us a picture of two cherries with a string underneath. Possibly the root password.

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

We use it to switch from user `chad-cherry` to `root` and are successful. We are able to switch to `root` and read the final flag in `/root/root-flag.txt`.

<figure><img src="/files/7aA35PJssby3KTZYfLrE" alt=""><figcaption></figcaption></figure>
