> 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/2023/cat-pictures-2.md).

# Cat Pictures 2

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

## Recon

Scanning our target with Nmap we can discover five open ports, of which three are running a web server and two are an ssh server.&#x20;

We have a web server on ports 80, 8080, and 3000.  On Port 22 and 222 an SSH server.&#x20;

On the web server on port 80 a photo management application called Lychee is running.&#x20;

The application running on the web server on port 3000 is the software development platform Gitea, recognizable by the set cookie `i_like_gitea`.

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

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

Visiting the web servers, we are able to see, that on port 80 a Lychee instance is running with  version `3.1.1`.

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

On 8080 just nginx.

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

On Port 3000 as mentioned Gitea with version `1.17.3`, and there is also already a user present, `samarium`.

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

## Flag 1 - Metadata and Repositories

For the first flag, we are inspecting the contents of the web server on port 80. Here are some cat pictures in an album.

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

In the album itself, there are seven cute pictures of different cats. Each picture has some basic information.

<figure><img src="/files/9Izhe7Olgo0aYxlSOHGt" alt=""><figcaption></figcaption></figure>

But the first picture has a description that states "note to self; strip metadata". So maybe we can find some hints or information about the first flag in the metadata of this picture or the other ones.

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

Downloading the image and running Exiftool on that to retrieve the metadata of it does not reveal anything of interest.&#x20;

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

Just by running Strings on the picture to print any printable characters in the file and looking at the first elements, we are able to receive the first hint.

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

On the webserver on port 8080 is a cryptic named text file hidden.

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

There we see a note from the dev himself, putting a password there to not forget it. In his perception of security, it is probably enough to have valuable things like user credentials that are hard to find. Besides the credentials, there is a second hint: that there is an Ansible runner - olivetin - running on port 1337.

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

With the found credentials we log in to the Gitea application.&#x20;

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

From there, we are able to see a repository called Ansible in which the first flag is viewable.

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

Looking a the source of flag1 we are able to read it.

<figure><img src="/files/rPehpJNK7anxc3bmiIx4" alt=""><figcaption><p>Flag 1</p></figcaption></figure>

## Flag 2 - Ansible and Playbooks

In the Ansible repository, a `playbook.yaml` is present. Which runs the `whoami` command as the user `bismuth`. As we remember, there is an Ansible runner present on port 1337.

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

Visiting the runner on port 1337 with a browser, we are able to run Ansible Playbooks.

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

And see the results in the logs.&#x20;

<figure><img src="/files/8kbAhBG21KLWq8QTIV53" alt=""><figcaption></figcaption></figure>

Hitting the panel `Run Ansible Playbook` the playbook in the repository gets executed, and in the logs, we can see the results of `whoami`

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

Knowing this, we are able to execute OS commands by editing the playbook, running the playbook, and viewing the results in the logs.&#x20;

<figure><img src="/files/9PzhX4CGxmMQ1D2CmAg3" alt=""><figcaption></figcaption></figure>

To retrieve the second flag, we use the commands `ls -lah` to check where we are. And see, we might be in the home directory of the user `bismuth` with the `flag2.txt` being there.

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

Editing the playbook to be able to retrieve the second flag.

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

And we are able to retrieve the second flag.

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

## &#x20;Flag 3 - The Obvious and the Easy

While browsing the home directory using Ansible, we could see that there was also a `.ssh` directory there. Using Ansible we look into it and find a private SSH key `id_rsa` of the user `bismuth`. Via `cat` we get the key and edit it with the help of Cyberchef to restore it.

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

Get the private key of user `bismuth`.

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

Edit the key via Cyberchef, removing `"`,`,` and the spaces.

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

Next, add the correct permissions to the key and use it  to log in as the user `bismuth`using SSH.

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

From there, we are able to enumerate the machine. Neither are we able to run any commands as sudo without providing a password, nor are there any suid binaries to escalate privileges. Via SCP we get our tools like Linpeas and pspy to the target and make them executable.

<figure><img src="/files/h4GOfYtkHMPnJHIRZp0z" alt=""><figcaption><p>Getting the tools via ssh</p></figcaption></figure>

<figure><img src="/files/ZTClxusqAqQiFuSw1OMA" alt=""><figcaption><p>Applying execution permissions</p></figcaption></figure>

Running Linpeas, we see that the PATH variable is set to a writeable location and stated as a 95% PE vector by Linpeas. A `bin` folder and `.local/bin` folder in the home directory of the user `bismuth`. That was my rabbit hole, which I want to briefly explain at the end. But there is also the version of the tool sudo marked.&#x20;

<figure><img src="/files/hzIkDGvaGIOXzhjq0pNv" alt=""><figcaption><p>Linpeas extract</p></figcaption></figure>

Looking for an exploit, we directly get a hit. CVE-2021-3156 a Heap-Based Buffer Overflow in Sudo (Baron Samedit).

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

Next, we need an exploit that gives us a root shell to abuse this vulnerability. CptGibbon has a PoC exactly doing it.

{% embed url="<https://github.com/CptGibbon/CVE-2021-3156>" %}

For the exploit we have to get the files from his repository to the victim machine and compile the exploit via make, resulting in the exploit. Running it gives us a root shell, and we are able to retrieve the third flag.

Via SCP we transfer the source files from CptGibbon to the target machine.

<figure><img src="/files/1OWdG9YoJlChUYF4ZEZ1" alt=""><figcaption><p>Getting the exploit to the victim</p></figcaption></figure>

There, we compile the result via `make`.

<figure><img src="/files/VnahBRYHBrcUFTm1tX37" alt=""><figcaption><p>Make the exploit</p></figcaption></figure>

Running the exploit, we are able to get a root shell and retrieve the third flag.

<figure><img src="/files/vVlCK00cTLoJPAcXLRqb" alt=""><figcaption><p>Run the exploit and getting the thrid flag</p></figcaption></figure>

## My rabbit hole

From the Linpeas output with the 95% PE vector, I was highly distracted, didn't keep in mind possible other vulnerabilities, and just wanted to find a way to exploit the writable path.&#x20;

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

So I thought that maybe placing a script at `/home/bismuth/bin` containing a reverse shell gets somehow called by the root user, by using a binary without an absolute path and the root user shares the same path variable - why not?

Checking cronjobs and running processes via `pspy64` nothing was found. Then I had the idea, that executing the playbook might have some interactions with the root users. And it had. But it was not abuseable. Maybe this can be used in another CTF.&#x20;

So keep this in mind; don't just get distracted by the most flashy and obvious things.
