# Gallery

## Nmap

```
nmap 10.10.40.100 -p- -sS -sV

PORT     STATE    SERVICE VERSION
53/tcp   filtered domain
80/tcp   open     http    Apache httpd 2.4.29 ((Ubuntu))
8080/tcp open     http    Apache httpd 2.4.29 ((Ubuntu))
```

Starting out on port 80 we have the Apache2 Default Page.

![](/files/eb66u3TCYfIY9u02YU2L)

Running `feroxbuster` against the target web server and we see some results.

```
feroxbuster -u http://10.10.40.100 -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-big.txt
```

![](/files/JrL5EVfgOG9LyAHPKQNe)

Checking the gallery directory we are redirected to `/gallery/login.php`.

![](/files/j7Mp9TdxXY0bEv1IOAoq)

Attempting a login with a simple set of credentials, we check the request in ZAP web proxy and notice a SQL error code has been returned in response to the logon.

![](/files/CjTrp0Wj4GDF1iLXZbnd)

Knowing SQL is running on the back end we can try some simple SQL injection on the login page.

Logging in with the SQL injection `' OR 1=1 -- -` for the username and password proves successful.

![](/files/mmQdzjhtpXwsqZdpcSNv)

**Note:** We can also use `sqlmap` with the raw proxy request to enumerate the database and pull the admin hash.

```
sqlmap -r ~/Desktop/request.raw --batch -D gallery_db -T users --columns username,password --dump
```

![](/files/bOvC2uiYByFbeZHPvVBE)

Back to the logged in page we managed to bypass. We notice we are able to upload a new profile picture to our current administrative user.

![](/files/Syg1BfLOvSH0fz933KlW)

As we know PHP is running on the webserver we will ideally upload a PHP reverse shell as the avatar.

**RevShells:** <https://www.revshells.com/>

I opted for the PHP PentestMonkey shell.

After uploading the shell we find it triggers our `netcat` receiver instantly.

**Note:** If for anyone reason this does not trigger we can right click where the avatar is supposed to be in the top right and "Open image in a new tab" to trigger.

![](/files/EUtIwjP3v4Q3TgCZHpqX)

Looking through the /var/backups directory we find the directory "mike\_home\_backup".

![](/files/603o2Dl4zLLVhGEl3K78)

Within the contents we find that `.bash_history` is readable by us which, contains a potential password.

![](/files/B9HoLQiJmzUEpUIMxUWR)

Using the credentials (altered slightly due to a type in the history file) we are able to `su` over to *mike*.

![](/files/jgABBGEQsoDC2TkYbO5U)

Where we can then read the `user.txt` flag in Mike's home directory.

![](/files/ssjctWVYXoI7rVhfMMLM)

Running `sudo -l` we see mike is able to run bash on `/opt/rootkit.sh` as **root** without requiring a password.

![](/files/G2rsBLjHQ5UdaaygKm20)

Reading the contents of `/opt/rootkit.sh` we see we will be prompted for commands, read looks to be the most promising due to hit executing `nano`.

![](/files/9sAfdgZ9RH0Yqbf29M7O)

Looking at GTFOBins we see we are able to escape nano to run system commands.

**GTFOBins:** <https://gtfobins.github.io/gtfobins/nano/>

![](/files/94pAQzZ0vs9qrRwzuksM)

**Note:** I was unable to complete the privilege escalation initially as the `nc` shell I was currently using was not stable enough to even work over TTY. `Socat` is installed on the target system and is highly recommended to get a reverse shell with `Socat` as the user mike to complete the next steps.

When ready we execute /opt/rootkit.sh as root.

```
sudo -u root /bin/bash /opt/rootkit.sh
```

Then enter "read" into the interactive prompt where we will move over to a root `nano` session. Pressing `CTRL + R and CTRL + X` on the keyboard will prompt for a command to run in nano.

![](/files/eKCZFWuMD6QmOv4aMjA3)

Entering the command below will escape into a root shell and all us to grab the **root** flag.

```
reset; sh 1>&0 2>&0
```

![](/files/o19JJL6v9BUWxvsjCKFk)


---

# 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://viperone.gitbook.io/pentest-everything/writeups/tryhackme/linux/gallery.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.
