# Expose

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

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

Scanning our target with Nmap we can discover five open ports, of which on each of them runs a different service. On Port 21 FTP, on 22 SSH, on 53 DNS, on 1337 a web server, and on 1883 a MQTT broker.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FhUkMR5S6762snTP0A24Z%2Fgrafik.png?alt=media&#x26;token=4b2da6da-b3f0-4691-aca2-c07b476744b9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FxxXX7NAc1gy0YelUlh1S%2Fgrafik.png?alt=media&#x26;token=58685dc0-addc-4bdb-90bd-847ec7acba57" alt=""><figcaption></figcaption></figure>

While enumerating the different services, we were not able to find anything of interest regarding ports 53 and 1883. Running a directory scan via Gobuster on the web server at port 1337 gives us some interesting directories. We have two admin login portals, of which one might be the correct one, and a PhpMyAdmin page.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FAvAzIZeophJovY20YI8S%2Fgrafik.png?alt=media&#x26;token=745f0945-fef4-4628-942f-0e8ec3119fd4" alt=""><figcaption></figcaption></figure>

Running a second directory scan on `/admin_101` reveals more interesting directories than on `/admin`. Given this fact and the fact that the username field is prefilled, it indicates to us that this might be the correct login portal. A brute force attack was run with the given username `hacker@root.thm,` but did not lead to any results. Instead, an SQL injection vulnerability might be present.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F5BKRVtCJmugYLYEFAzuX%2Fgrafik.png?alt=media&#x26;token=da4030e2-86d7-4f8c-b164-babd6d58bfb9" alt=""><figcaption></figcaption></figure>

## User Flag

For a quick check, we capture the HTTP request while trying to log in and reuse it in SQLMap.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F9Vz9IRn5EetNsM6y5NmV%2Fgrafik.png?alt=media&#x26;token=306fe469-8a19-43f3-a149-078750027af3" alt=""><figcaption></figcaption></figure>

By running SQLMap with the captured request, we are able to dump the database.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmxCfpk6X69XD39xRFXd6%2Fgrafik.png?alt=media&#x26;token=b0086f7f-713c-4ac6-a879-ea0759dab07e" alt=""><figcaption></figcaption></figure>

We were able to retrieve some interesting information. For the user `hacker@root.thm`, we get a password in clear text. Using it on the admin portal does not lead to anything of interest. Beside the credentials are two URLs in the config table stored, which we were not able to discover via Gobuster and a password or password hint to be able to access those URLs.

For `/file1010111/index.php` we get a simple MD5 hash, which might be crackable. For the page `/upload-cv00101011/index.php` we just get a hint that the password is the username of the machine starting with the letter Z.<br>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FF2zcAZcalH8dENA6tpKK%2Fgrafik.png?alt=media&#x26;token=46d60f79-4a39-42c3-acd0-adedb4a2cb13" alt=""><figcaption></figcaption></figure>

Using crackstation we are able to crack the hash easily and get a password.

{% embed url="<https://crackstation.net/>" %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F52PNRdO0Jf6pRSnBzeAc%2Fgrafik.png?alt=media&#x26;token=26625d69-dbc7-4240-a233-2d2603ad6c70" alt=""><figcaption></figcaption></figure>

Next, we visit `/file1010111/index.php`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FmUSDbcMWQryVmdd493rY%2Fgrafik.png?alt=media&#x26;token=1e334736-371c-4b50-b485-6b68fabf0e66" alt=""><figcaption></figcaption></figure>

By providing the password, we get a hint to fuzz for parameters. Without checking anything more, we visit `/upload-cv00101011/index.php.`

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FkUW89U52ugozwmrMzB3f%2Fgrafik.png?alt=media&#x26;token=b83fdd88-5f5c-49a2-ba39-0d1b82e7567c" alt=""><figcaption></figcaption></figure>

The page `/upload-cv00101011/index.php` also gives us a hint about the password being the name of the machine user starting with the letter Z. An attempt was made by using Burp Suite to brute force the usernames. While the brute force is running, we check out `/file1010111/index.php` again.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FuZsVU7SxB1Ff0NmmQbyr%2Fgrafik.png?alt=media&#x26;token=6e8c9ecb-be9e-4ffb-8b54-8c0c6d1c8ede" alt=""><figcaption></figcaption></figure>

On checking out the source page of `/file1010111/index.php` we get another hint to try `file` or `view` as GET parameters. On a closer look at the URL, this might be a page to view files on the system, and a local file inclusion vulnerability might be present.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FP9jypZgq3DkQrY3eCPxN%2Fgrafik.png?alt=media&#x26;token=7993df8c-b16d-4933-bb78-83fbbaa1be24" alt=""><figcaption></figcaption></figure>

For a simple check, we use `?file=index.php` to check for local file inclusion. Upon calling `http://10.10.118.26:1337/file1010111/index.php?file=index.php` and providing the cracked password, we see that the page has now been loaded multiple times. An LFI is present.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Few4T2LQYnycOmIUFrlfM%2Fgrafik.png?alt=media&#x26;token=6ddc9d9a-fa3e-4a12-a937-076565e4c35f" alt=""><figcaption></figcaption></figure>

Due to the fact that we need to know the username of the machine to access the other page, we try to check out the `/etc/passwd` file on the system. By providing the URL `http://10.10.118.26:1337/file1010111/index.php?file=../../../../etc/passwd` we are able to enumerate the user `zeamkish`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F4isunOJu5VoCMFZFhMFW%2Fgrafik.png?alt=media&#x26;token=13968cde-fd8b-48f4-ad67-2024442ec507" alt=""><figcaption></figcaption></figure>

We directly head up to `/upload-cv00101011/` and provide the found user.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FhzT71GTNSF6H8ca3Xryb%2Fgrafik.png?alt=media&#x26;token=d0ce951e-6187-4915-ae39-771fc9f19792" alt=""><figcaption></figcaption></figure>

We are greeted with a file upload page.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FLqB6MtKmqHtzwE5Jgz9j%2Fgrafik.png?alt=media&#x26;token=660d7a4c-145a-48a7-98a7-bbe9c153cbe2" alt=""><figcaption><p>To uploada file click on the Upload text</p></figcaption></figure>

Looking at the source of the page, we see a simple local upload filter in javascript checking for file endings. Only JPG or PNG files are allowed.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FpWFXEgzPW5QgpcirDqKH%2Fgrafik.png?alt=media&#x26;token=c11b562c-6aa3-4820-8c62-fdbac181e3b7" alt=""><figcaption></figcaption></figure>

For a simple test, we upload a picture of a cute cat and get the hint to look into the source code to see the path. The first thought was about to check the correct .php file via the LFI page, but first we checked out the source of the page.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F1YdliZ7vGidC6SmdQ2IJ%2Fgrafik.png?alt=media&#x26;token=c955eaae-78bd-4282-afa3-863fea4da9d6" alt=""><figcaption></figcaption></figure>

And the files are stored at the `/upload_thm_1001` folder.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FjEGAVDwQfR4SeplKOjgi%2Fgrafik.png?alt=media&#x26;token=bb2e7fa4-0edd-4700-8ca7-0d4dfbf08ce5" alt=""><figcaption></figcaption></figure>

Here we are able to see our cat picture.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FsEJpzQZKAfFHH6ISb2Rj%2Fgrafik.png?alt=media&#x26;token=d04893c0-d31e-46e3-9e68-7c093faeb329" alt=""><figcaption></figcaption></figure>

Next, me make use of pentestmonkey PHP reverse shell provided by revshells.com

{% embed url="<https://www.revshells.com/>" %}

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FOedAtNQgQdSRX6WyCs7X%2Fgrafik.png?alt=media&#x26;token=27e0553b-a3e7-4dfd-bc57-c07411647b41" alt=""><figcaption></figcaption></figure>

For a simple bypass, we name our shell as `evilcat.phpD.jpg`. We capture our upload request in Burp Suite and change the letter D to a null byte. Alternatively, a breakpoint in the JavaScript can be set, a .php file be uploaded and the variable `fileExtension` be changed in the console to contain 'jpg' instead of 'php'.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FKioVkXSxwgGbaWhIDhPV%2Fgrafik.png?alt=media&#x26;token=29d68a28-d4b0-4e6b-b53b-5a36ddb26f89" alt=""><figcaption><p>Breakpoint for bypass</p></figcaption></figure>

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FopuXXRjBZPPQFOAWchhg%2Fgrafik.png?alt=media&#x26;token=55d2d345-0633-446a-b383-c6152416bb99" alt=""><figcaption></figcaption></figure>

We change the byte in Burp and forward the request.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F2qWr6H3hC5xXFVi7r85W%2Fgrafik.png?alt=media&#x26;token=b048d3c5-9cf3-4f74-83f3-6498693b5ee5" alt=""><figcaption></figcaption></figure>

Next, we head to `/upload-cv00101011/upload_thm_1001/` and set up a listener, and we see that our bypass was successful.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2Fh3HqBcwCPpH3Cd2qXgA0%2Fgrafik.png?alt=media&#x26;token=f46eb1ad-e6f1-4f4b-a5a3-34b34438ca35" alt=""><figcaption></figcaption></figure>

Upon calling our reverse shell PHP script our shell connects. We are `www-data`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FGKOakO7eIGjPyIPhkwvL%2Fgrafik.png?alt=media&#x26;token=7edff0fa-bcc7-43c3-ac87-230d72dfcd1b" alt=""><figcaption></figcaption></figure>

For convenience, we upgrade our shell.

{% embed url="<https://0xffsec.com/handbook/shells/full-tty/>" %}

```sh
SHELL=/bin/bash script -q /dev/null
```

```bash
STRG+Z
```

```sh
stty raw -echo && fg
```

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FtDRO2140wYopfwF4ZcfR%2Fgrafik.png?alt=media&#x26;token=6a5aa3e5-219b-4c93-99af-d6f4da7aea12" alt=""><figcaption><p>upgraded shell</p></figcaption></figure>

While enumerating for the usual suspects like `sudo -l` or SUID binaries, nothing could be found. We were not allowed to use Find. That is odd; it might be a big hint to prevent us from finding SUID binaries. But taking a look at `zeamkish's` home directory, we see the flag that we are not allowed to access, but the credentials stored for the user in `ssh_cred.txt`.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FLwX17qyt2FsqazsOJtck%2Fgrafik.png?alt=media&#x26;token=201d23d8-d1a4-47ab-ba58-731da9fa68e2" alt=""><figcaption></figcaption></figure>

We use the credentials to log in to the system as the user `zeamkish` using SSH. We are in the home directory of zeamkish and are able to read the user's flag.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FwtCCLXIZYpVFNmG9JCmI%2Fgrafik.png?alt=media&#x26;token=bf0cf506-6046-43b0-a0ce-8dadb6c5ae96" alt=""><figcaption></figcaption></figure>

## Root Flag

Upon checking for interesting SUID binaries as the user zeamkish we get an interesting hit.&#x20;

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FliKCOklsROQ4AyxpzPny%2Fgrafik.png?alt=media&#x26;token=a985f62f-a389-40f5-b04b-8db1ddf94756" alt=""><figcaption></figcaption></figure>

The editor Nano has a SUID bit set. With that, we are able to read and write files outside of our rights as root. For a fast but harmful privilege escalation, we change the `/etc/shadow` file and edit the password of the user root.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FYbbeCyEBqSXsZeJyFl0n%2Fgrafik.png?alt=media&#x26;token=0cabeb47-eae4-42a4-871e-4cfccccb1210" alt=""><figcaption></figcaption></figure>

With the use of `openssl` we generate our new password.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FXhQKPnbowYLkZ2UUIElD%2Fgrafik.png?alt=media&#x26;token=16575007-478e-4010-921e-54b79933ecae" alt=""><figcaption></figcaption></figure>

Next we just open `/etc/shadow` using `/usr/bin/nano` and insert our custom password hash.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2F59PlmCaWcaVArUSrJZe1%2Fgrafik.png?alt=media&#x26;token=66c96b34-cbee-4ec5-b7ee-0b2c25aeafa8" alt=""><figcaption></figcaption></figure>

After editing the password of root, we are able to change the user to root using `su` and providing our chosen password. Next, we find the flag in the home directory of root.

<figure><img src="https://2148487935-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoqaFccsCrwKo1CHmLRKW%2Fuploads%2FqnB2sPP0izYx3G0a7Pt6%2Fgrafik.png?alt=media&#x26;token=c924cd85-8339-49d7-9f6f-f68b45ec40bd" alt=""><figcaption></figcaption></figure>
