# Lookup

## Lookup - Writeup

**Date**: 23/01/2025

**Difficulty**: Easy

**CTF**: <https://tryhackme.com/r/room/lookup>

Test your enumeration skills on this boot-to-root machine.

***

## Discovery

Let’s start by testing the connection to the target machine using **ping**:

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

We receive a packet back, and the TTL shows a value of 63, which means that we are probably facing a Linux Machine.

Let’s use **nmap** tool to search for open TCP ports on the target machine:

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

The scan discovered two open TCP ports: 22 (SSH) and 80 (HTTP). Let’s do a further scan to check the services and their versions:

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

* 22: OpenSSH 8.2p1
* 80: Apache 2.4.41 (redirection to <http://lookup.thm>)

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

According to **Launchpad**, the version of OpenSSH corresponds to a package of Ubuntu Focal (20.04) distribution.

Let’s use **whatweb** to take a quick look at the HTTP content:

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

It displays an error saying that the server is trying to redirect us to lookup.thm, so let’s edit **/etc/hosts** to include the domain:

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

Let’s use whatweb again:

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

There isn’t much information apart from the version of Apache (2.4.41)

Let’s take a look at the website using the web browser:

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

A login screen… let’s check the source code:

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

Nothing really useful there, let’s try to login using random credentials:

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

In parallel I’ll launch gobuster to try to discover directories and files:

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

Let’s try if the form is vulnerable to SQL Injection:

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

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

I tried the most common payloads to test SQLi without success. Let’s try to login using common credentials:

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

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

So… admin seems to be a valid username. Maybe we can bruteforce the password using **hydra**…

This is the POST request:

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

Let’s build the command, using the **rockyou.txt** dictionary:

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

Gobuster didn’t find any useful directory or file, so meanwhile the hydra is working, let’s launch **ffuf** for subdomain enumeration:

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

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

It didn’t find subdomains… and hydra didn’t find a valid password for **admin** user.

As the website displays different messages when you are using a valid username or not, let’s try to find other valid usernames using hydra again:

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

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

It found **admin**…

<figure><img src="/files/1Xy9cP0fgiSb3IbmoOiL" alt=""><figcaption></figcaption></figure>

And after a while it also found a user named **jose**. Let’s see if we have more luck trying to discover his password. This time I’ll use a shorter password dictionary:

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

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

It found valid credentials! Let’s try to log in.

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

The website now tries to redirect us to **files.lookup.thm:**

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

Let’s add it to **/etc/hosts:**

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

Now when we log in, it redirects us to something that looks like a web file manager.

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

It displays some text files, that we can read.

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

Most of them have random words in their content, but the content of **credentials.txt** makes me think that there is a user called **think.** And maybe the credentials are: `think:nopassword`:

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

The file **thislogin.txt** contains the credentials of the user **jose:**

<figure><img src="/files/26VpkpqZ14XlBGYHPswT" alt=""><figcaption></figcaption></figure>

I tried to use the credentials of **think** to log in in the webpage form without success.

Let’s extract some info from this web file manager clicking the About button:

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

## Exploitation

The name of this software is **elFinder** and its version is 2.1.47. Let’s use **searchsploit** to check for possible vulnerabilities of it:

<figure><img src="/files/1Uu7obmI1WpzjR1qSHJy" alt=""><figcaption></figcaption></figure>

The vulnerability [CVE-2019-9194](https://blog.hackmetrix.com/desencadenamiento-y-explotacion-de-vulnerabilidad-1-day/) allows command injection! Let’s try it:

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

We are inside the target machine! Let’s find the user flag:

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

The **user.txt** is not readable by the current user.

Also, the reverse shell we obtained is not very interactive… So let’s see if we can transfer a PHP file to obtain a better reverse shell:

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

After the transfer, we can go to <http://files.lookup.thm/elFinder/php/minirevshell.php> to execute it and obtain the reverse shell:

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

Much better, now we have to search for a way to log in as **root** or **think** user. Let’s take a look at the **login.php** file:

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

Nothing new. Let’s see if there are more users on this machine:

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

Nah, the only ones that have a bash are **root** and **think**.

Let’s search for SUID files:

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

I didn’t see anything I can use… Let’s transfer LinPeas to do an intensive scan:

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

After executing LinPeas, it detects an Unknown SGID binary named `/usr/sbin/pwm` . I have previously missed that file in the SUID search...

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

**SGID** (Set Group ID) means that this binary can be executed with the permissions of the group that owns the file. In this case the owner is root and the group is also root. Let’s try to execute it:

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

Let’s use **strings** to see if we can see anything useful:

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

Apparently, the binary is trying to read/execute the file “**/home/user/.password**” but, since we are executing it as the user **www-data** it doesn’t find the file **/home/www-data/.password** because it doesn’t exist.

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

I thought about creating it, but as www-data user we have no permissions to do that.

The binary is executing the command **id**, if the binary is not being called using the absolute reference but just calling it as `id user`, maybe we have a chance if we manage to create a binary called **id** somewhere else in the PATH.

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

Mmm… It looks like we have no write permissions in any of the directories of the PATH.

Can we modify the PATH?

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

Oh! Yes, we can! I added the /tmp directory at the beginning of PATH, so if we create a binary called **id** there it may do the trick!

After some tries, I realized that the pwm binary is using id to determine the user that is executing the binary and then, using his name to fill the command that uses the line `/home/%s/.passwords`.

So, knowing that, I created an executable called `id` in **/tmp** folder that executes `/usr/bin/id think` to fool the pwm binary.

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

Now, a list of passwords appears in the console. Let’s copy it into our local machine as passwords.txt and let’s try them all using Hydra to connect via SSH as the user **think**.

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

Yeah, we found valid credentials to log in via SSH

<figure><img src="/files/5fIYBxh9Y0JhcEPzOjaZ" alt=""><figcaption></figcaption></figure>

And here we have the user flag!

## Privilege Escalation

Let’s see the sudo permissions of this user:

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

According to [GTFO Bins](https://gtfobins.github.io/gtfobins/look/), we can use **look** to read files, and since we can execute it as root, we may read the root flag:

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

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


---

# 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/2025/lookup.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.
