# wonderland

## <img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FoB1xhAKKCjlq9YD3A1Kb%2Fimage.png?alt=media&#x26;token=45a7d56f-221c-4b53-9865-56dc81579f37" alt="" data-size="line">WONDERLAND WRITEUP

*By Jacvbtaylor*

```
       Used openvpn and Kali Linux 
                 https://tryhackme.com/room/wonderland
         completed Sep 13, 2022
```

The wonderland CTF claims to have 2 flags:

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FUuRXw7jA7CpB9X47tMBb%2Fimage.png?alt=media&#x26;token=2f8d2b69-5627-4a22-944d-cb3e96716290" alt=""><figcaption><p>flags</p></figcaption></figure>

Beginning with the IP address and an nmap scan, 2 open ports are discovered running services http and ssh. This tells me there is most likely a website up and running and sure enough:

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FWy37NbTnVDa4HSsOvY4Z%2Fimage.png?alt=media&#x26;token=9d6cfa56-45e0-4076-85e8-e7ea3f9c0928" alt=""><figcaption><p>wonderland site</p></figcaption></figure>

The first I did after finding this was read the source code. From here I could see there was an img directory. Viewing this in the URL allowed me to see 3 photos hosted on this site, only 1 of which was on the index page. Knowing this lead me to running a directory enumeration attack using gobuster:

`gobuster dir -u http://10.10.66.247/ -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt`

Shortly after starting this attack, I was able to see a poem and a r directory

<div><figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2F2XMc677itArjf4eqTrjR%2Fimage.png?alt=media&#x26;token=bfff868c-6c9e-4d2c-bd08-24c753b18e38" alt=""><figcaption><p>/r</p></figcaption></figure> <figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FZPd5nSqP4jywmS79WOJS%2Fimage.png?alt=media&#x26;token=4514f4a5-41c1-465f-a0b6-4f4166cfa617" alt=""><figcaption><p>/poem</p></figcaption></figure></div>

I wasn't getting any other promising results with my gobuster attack once those 2 directories were discovered. I figured there was still something I was missing so I ran a similar attack using dirb and the /usr/share/dirb/wordlists/common.txt list and also searched for .txt and .html files but still, nothing else to work off of from these results. Until I saw this:

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FfoeTdG03kXMToNpcdsIr%2Fimage.png?alt=media&#x26;token=90bc2b8d-aa30-4e5d-bf40-f0c448da4e7f" alt=""><figcaption><p>/r/a</p></figcaption></figure>

Dirb found another directory in the /r folder called /a. I followed this until I reached <http://10.10.66.247/r/a/b/b/i/t/>

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2F7O3k2ay3CtgvJ6IkicLY%2Fimage.png?alt=media&#x26;token=e4e35a35-9d04-4280-a809-02697641a432" alt=""><figcaption><p>/r/a/b/b/i/t</p></figcaption></figure>

I noticed the source code for this page had a note on line 15

```
<p style="display: none;">alice:HowDothTheLittleCrocodileImproveHisShiningTail</p>
```

This was the only index.html file I could find so far that had a message. It was formatted similarly to a shadow file hash, and knowing port 22 was open lead me the only direction I could go from here and to my surprise, I got in!\
&#x20;

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FuiMuBCqTKeqJBPp0uqTY%2Fimage.png?alt=media&#x26;token=3545dcf0-150a-483c-bf33-7356cb20cd71" alt=""><figcaption><p>ssh login</p></figcaption></figure>

This password was stupid long, which is great in regards to security, but not for me trying to snoop around. I changed the password to something a lot smaller and started seeing what I could do

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2F1YDRBHArDl67xBalIJUP%2Fimage.png?alt=media&#x26;token=e48cc34f-11c8-44e9-b2f4-76feafbd5e65" alt=""><figcaption><p>sudo -l</p></figcaption></figure>

Once I say I could use python, I quickly tried to escalate with this, but to no prevail. Not a problem.

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FUIZUscIjYplRTgLw8mVE%2Fimage.png?alt=media&#x26;token=89657607-5dca-47fd-9abc-7de36f7f72b2" alt=""><figcaption></figcaption></figure>

There wasn't a whole lot I could think to do from here. I can interact with this py file as if I am user Rabbit but I cannot enter Rabbit's home directory. I noticed the only module this file uses is the random module for python3.6. It seemed logical to be able to highjack this module using that file to elevate privileges.&#x20;

`cd /usr/lib/python3.6/`&#x20;

`locate random.py`&#x20;

`nano random.py`

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FZjRFuX6GLdEWnQfS7EtL%2Fimage.png?alt=media&#x26;token=33986b5f-39f9-4b40-bd95-226234bc498d" alt=""><figcaption><p>random.py</p></figcaption></figure>

I was able to add these lines to the file, went to save it and was hit with a roadblock. This file wasn't allowed to be modified by the Alice user. This left me pretty stumped. &#x20;

This was absolutely one of those moments where I need to step back because I must have overlooked something.&#x20;

Thinking back to what I found earlier, the /img folder had 3 photos and one of them wasn't used on the website as far as I could tell. Previously through my cybersecurity course I had learned about steganography and thought this may be worth trying, so I started with the first image:

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FMB7LarSy20ZyFvzM0ihY%2Fimage.png?alt=media&#x26;token=9a217dda-aba0-48b5-b0be-b9219a62d56c" alt=""><figcaption><p>hint</p></figcaption></figure>

I had already figured this out without finding this txt file but it's worth checking the rest of the images.&#x20;

`wget http://10.10.13.66/img/alice_door.jpg`

`wget http://10.10.13.66/img/alice_door.png`

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2F6ehV6HsigSL0dXg3eiAI%2Fimage.png?alt=media&#x26;token=3239573f-47ee-4beb-9029-fe17d17b44aa" alt=""><figcaption><p>steghide</p></figcaption></figure>

The jpg file seems promising, although I have no idea what the passcode could be. May be a dead end.

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FZJrsTt9VOS8Kpmid0asb%2Fimage.png?alt=media&#x26;token=669fdca3-42a6-462a-b89c-a8f0fe144916" alt=""><figcaption></figcaption></figure>

Thinking back to our sudo privilege `User alice may run the following commands on wonderland: (rabbit) /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py` makes me think if I was on the right track but need to try it differently. <br>

I used the same method I was trying earlier but made my own random.py module file inside a directory I had ownership of, started a netcat listener and ran `ufw allow from 10.10.13.66 proto tcp to any port 1337` before running the walrus\_and\_the\_carpenter.py file and it worked! But I was still stuck as the same user.&#x20;

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FlLvCRVayST1RChixZTIR%2Fssh.png?alt=media&#x26;token=80d60c27-bebf-4ddc-bade-54bd55a76843" alt=""><figcaption><p>ssh random.py</p></figcaption></figure>

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FGjCdCBqenoAHYKappYAW%2Fimage.png?alt=media&#x26;token=1d1c2b77-da3c-4556-b1d1-47bfee9a3389" alt=""><figcaption><p>reverse shell</p></figcaption></figure>

Since I didn't escalate privileges, I went back to my sudo privilege and did exactly what I was allowed to do

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FAeBmljxnVhDQprVFkt8n%2Fimage.png?alt=media&#x26;token=b97f70e8-cf69-451a-9b3b-1d136e80ac0b" alt=""><figcaption><p>sudo</p></figcaption></figure>

After changing my command, I was the rabbit user

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FFpmmu49se3XJ6w2cYxry%2Fimage.png?alt=media&#x26;token=22c253e8-fee9-42b1-90e2-d26acdb5b3b9" alt=""><figcaption><p>whoami rabbit</p></figcaption></figure>

I moved to rabbit's home directory to find a file called teaParty which held a whole lot of nonsense and a new clue:

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2F8kgH7x1DylNMUw9Hi4vt%2Fimage.png?alt=media&#x26;token=a248f0e9-78df-4996-a529-192239274109" alt=""><figcaption><p>hint2</p></figcaption></figure>

Before looking into this clue, I wanted to know what sudo privileges I may have from this user, but every time I ran `sudo -l` or any other command following `sudo`, I would be prompted for the sudo password, which I don't have. Having sudo privileges but not being able to use them is a whole new problem. So I opted to running the echo,

`$ echo -n 'Probably by ' && date --date='next hour' -R`&#x20;

`Probably by Wed, 14 Sep 2022 07:08:55 +0000`

After running `file` on teaParty, I was presented with some hefty information, non of which seemed helpful until researching what it all meant&#x20;

`teaParty: setuid, setgid ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=75a832557e341d3f65157c22fafd6d6ed7413474, not stripped`

ELF in Linux means ***Executable and Linkable Format**.* Sweet, an executable? I ran the file, was prompted for user input, but nothing was giving me a useful outcome. Reading the file again, I noticed date seemed off. `&& date --date='next hour'`

So I ran

`$ --date`\
`/bin/sh: 37: --date: not found`&#x20;

`$ date`\
`Wed Sep 14 07:04:24 UTC 2022 $`

date is a program called by the system to output the current date, but --date is suppose to be for the path.. and it's not set like echo was in the file. \
Maybe we can exploit this like the .py file from earlier?

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FmZBlICoG8q56DhP6dONJ%2Fimage.png?alt=media&#x26;token=00f5451d-1abb-446f-804e-50c4c1dde4b8" alt=""><figcaption><p>hatter</p></figcaption></figure>

By changing rabbit's path to his home directory and creating an executable file called date with bash inside it, the teaParty executable now called to my date file with /bin/bash specified, changing our user midway through the program. Nice!

I found a password file inside hatter's home directory, but quickly discovered he does not have sudo privileges, but the password worked with `sudo -l`

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FEheMwQp3uEACvD6zH6vw%2Fimage.png?alt=media&#x26;token=f6667d02-6949-46a7-89e8-29ac4fa0712e" alt=""><figcaption><p>hatter sudo</p></figcaption></figure>

Using the password, I switched my SSH login to hatter to make things a little easier not having the reverse shell limitations. Hatter was as tricky user to find an exploit for. For this, I had to look into Linux capabilities, which was new to me.&#x20;

\
&#x20;                         *"Linux divides the privileges traditionally associated with* \
&#x20;                               *superuser into distinct units, known as capabilities"*

I found a useful command for this called getcap. I first tried using it on the password file - no luck. Let's start from the beginning of the machine?

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FRS4KG3s41fmfwsgvbRBC%2Fimage.png?alt=media&#x26;token=c9344c09-ddd2-426f-aa7c-f23565e6fb8a" alt=""><figcaption><p>getcap</p></figcaption></figure>

Using getcap, I can see the perl program is set to cap\_setiud. After searching "linux capabilities vulnerability" I was able to find how to generate a shell to set my user id to  0 (root).&#x20;

<figure><img src="https://3130787646-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fhkeh1757ZWdDHF84BG7u%2Fuploads%2FdLJhpho55uSpjl3e2Odi%2Fimage.png?alt=media&#x26;token=14ad4233-d567-4b60-b89d-8c712168057f" alt=""><figcaption></figcaption></figure>
