> For the complete documentation index, see [llms.txt](https://meitoka.gitbook.io/stash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://meitoka.gitbook.io/stash/tryhackme-stuffs/challenges-ctf/wonderland.md).

# Wonderland

Writeup by FzF\_StormZ

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FEKfy5KIStMa6l25puqiw%2Ffdba6eaf85513262b2a9b12875b0f342.jpeg?alt=media&amp;token=931c1a3c-f74f-4754-8cd3-c6703a39b3ba" alt="" width="375"><figcaption><p>Wonderland challenge</p></figcaption></figure>

## Enumeration

First of all, we will launch a complet **Nmap** scan to try to discover possible services:

```bash
nmap -sT -sC -sV -Pn <IP victim> -v
```

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2F115EPmaxrda285jQDgb7%2Fimage.png?alt=media&amp;token=28a8af98-c1df-4a8c-a2b6-6ec17b4d6a12" alt=""><figcaption></figcaption></figure>

As you can see, we have 2 open ports (22 and 80). The SSH port can be interesting if we find credentials to have a legit shell with the machine. But, for now, we will focus on the 80 port.

When I have a website during a challenge, i like to run 2 commands:

```bash
gobuster dir -u http://<IP victim> -x php,txt,html \
-w /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-small.txt
```

```bash
nikto -host http://<IP victim>
```

With `gobuster` , we find the repository `/r/` .If we continue recursively, we have:&#x20;

`http://<IP victim>/r/a/b/b/i/t/` . This seems a rabbit hole :smile:

So, I continued to search around, but there was not possible paths than the first one. I analysed the multiple images but found nothing. Here we go again, I tried to analyse every page source of the different repository and at the last one, you have the credentials for the user alice :&#x20;

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FH9bWo4ES1ucYdjV1E7Y8%2Fimage.png?alt=media&amp;token=d23085b6-c264-4563-89be-203d5d34b796" alt=""><figcaption></figcaption></figure>

Creds found !!: `alice:HowDothTheLittleCrocodileImproveHisShiningTail`&#x20;

With this credentials, we can try to connect through SSH with the `alice` user.

<mark style="color:red;">BINGO !</mark>

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FlX3Rn4fesNGOSCuPdfJl%2Fimage.png?alt=media&amp;token=619fc78e-a265-4050-b939-f50a47c27886" alt=""><figcaption><p>Get the user Alice !</p></figcaption></figure>

## Lateral movement

Now, I will upload an automatique script to enumerate possible privilege escalation which are possible with the web user. I can also try to have the control to the think user which can have more privileges to reach the root user.

After running linpeas.sh, I have this crucial information:

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2F2QYWEpM1RduGgh9OekNf%2Fimage.png?alt=media&amp;token=9c0a928e-71e5-469f-ad0e-ea41d6be0525" alt=""><figcaption></figcaption></figure>

But, if i want to exploit these capabilities to perform a privilege escalation, I need to be the `hatter` user.

So, we have some files in our home directory. A python script with the `random` module. And, when we execute the command `sudo -l` , we can see that we can run a specific command with the user `rabbit` .&#x20;

The next step will be just to perform a Hijacking python module. I wrote my own `random` module to do a lateral movement on the user `rabbit:`

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2Fr2NYf9GkqQRYYKPYlyAZ%2Fimage.png?alt=media&amp;token=7ca0a7d9-0115-4fdb-847c-04a456e4e2e3" alt=""><figcaption></figcaption></figure>

Now, we have a binary `teaParty` with SUID. This is the same technique with the Python module. WE can see inside the binary the call to the `date` command in relative path. So, we can create our own `date` command and change the PATH env variable. After execution, we are now the user `harper` .

Inside his home directory, we have this file:

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FihAq8XCtYFpAj75hO4ce%2Fimage.png?alt=media&amp;token=2d0b10f4-d313-47f5-9110-cbe65082587c" alt=""><figcaption></figcaption></figure>

This is useful to connect through ssh to the user `harper` to have the gid and groups for `harper`

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FCym5Pi9yPjpDuoAJAMkS%2Fimage.png?alt=media&amp;token=baae7468-81c2-49cf-90e8-8c5b131be805" alt=""><figcaption><p>If we continue without the SSH ...</p></figcaption></figure>

Now, we can go back to the capabilities and just perform what we can find on GTFOBins:

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FcC6fj8Jx6YXqU7zLNj9x%2Fimage.png?alt=media&amp;token=78e879da-3652-4f08-9949-070ba799802e" alt=""><figcaption></figcaption></figure>

We are now `root` !!!!!

<figure><img src="https://1205247251-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FKPO62FppgTaVmwp5axJJ%2Fuploads%2FiANcrip8xz2OErpvetUx%2Fimage.png?alt=media&amp;token=7589533b-4c5a-4e35-b07e-a99bb90c0c54" alt=""><figcaption></figcaption></figure>

I really enjoy this room to perfome Hijacking skill with Python and the PATH env variable!
