# Frosteau Busy with Vim

{% embed url="<https://tryhackme.com/room/busyvimfrosteau>" %}

All banner and comic images are courtesy of TryHackMe - <https://www.tryhackme.com>

<figure><img src="/files/hBOhiW1z84aJPzvj7r9O" alt=""><figcaption><p><a href="https://tryhackme.com/">https://tryhackme.com/</a></p></figcaption></figure>

The following post by 0xb0b is licensed under [CC BY 4.0<img src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt="" data-size="line"><img src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt="" data-size="line">](http://creativecommons.org/licenses/by/4.0/?ref=chooser-v1)&#x20;

## Getting to SQ3 - The QR Code

The QR Code to Side Quest 2 can be found in the Challenge `Task 17 [Day 11] **Active Directory** Jingle Bells, Shadow Spells`

We are already in the Evil-WinRM session with the hash from VanSprinkels. On the administrator's desktop, we find a folder `chatlog_files`.

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

In addition to the flag and the folder on the desktop, we also find a HTML file. This contains the chat between the Yeti and McGreedy.

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

The files can be easily transferred to our machine via Evil-WinRM.

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

McGreedy has accidentally shared a screenshot containing the key to the next challenge, but has deleted it. As a solution, he cropped the image with Snip & Sketch and shared it again. This clearly indicates that we will probably have to restore the image to get the key.

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

Snip & Sketch appears to be the Windows Snipping Tool.

{% embed url="<https://learn.microsoft.com/en-US/windows-insider/apps/snip-and-sketch>" %}

After searching for Snip & Sketch and crop recovery, we find the current `aCropolypse` vulnerability. This is a vulnerability related to `CVE 2023-21036`, about the tool Markup, a snipping tool on Google Pixel smartphones. Following aCropalypse's discovery there were more zero days found, affecting Snip & Sketch for Windows 10 and Snipping Tool for Windows 11. See:&#x20;

{% embed url="<https://en.wikipedia.org/wiki/ACropalypse>" %}

In the folder, we not only find the cropped image, but also a screenshot of the desktop without the key. However, this gives us an important indication of the size of the image.

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

Here is the cropped image:

<figure><img src="/files/4BGl3584FDUwchrsAWGx" alt=""><figcaption></figcaption></figure>

There are some tools to make use of this vulnerability. The following works in this case:

{% embed url="<https://github.com/frankthetank-music/Acropalypse-Multi-Tool>" %}

We download the project, install the requirements and start the tool directly.

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

We select restoring tool. Select our image to be restored, choose Windows 11 Snipping Tool and set the size to `2560x1080`.

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

## Frosteau's Laptop

OK, let's start with side quest number 3 and see what we have in front of us.

### Recon

We run a nmap scan and find 6 open ports, including two known ssh on 22 and HTTP on port 80, as well as 4 unknown ports. 8065, 8075, 8085 and 8095.

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

We run a second nmap scan on the found ports with a service and script scan. You can see here a shortened scan result, because the results and  banner grabs are hard to read and would just blow up the snippet. They do not lead to any sufficient results except for port 8075 running FTP and the others running Telnet.

```bash
┌──(0xb0b㉿kali)-[~/Documents/tryhackme/sidequest/quest3]
└─$ nmap -sT -sC -sV -p22,80,8065,8075,8085,8095 10.10.53.8
Starting Nmap 7.94SVN ( https://nmap.org ) at 2023-12-18 10:02 EST
Nmap scan report for localhost (10.10.53.8)
Host is up (0.039s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 8f:5e:47:aa:e9:26:ac:cc:ea:64:a9:b5:65:1b:7d:72 (RSA)
|   256 37:da:40:e4:61:1a:61:4c:1a:6f:ba:31:24:01:4c:12 (ECDSA)
|_  256 f3:7c:9e:92:e4:fd:d8:a1:78:4a:73:63:4a:6d:e9:ed (ED25519)
80/tcp   open  http    WebSockify Python/3.8.10
|_http-server-header: WebSockify Python/3.8.10
|_http-title: Error response
| fingerprint-strings: 
|   GetRequest: 
|     HTTP/1.1 405 Method Not Allowed
|     [...]
|   HTTPOptions: 
|     HTTP/1.1 501 Unsupported method ('OPTIONS')
|_    [...]
8065/tcp open  telnet  BusyBox telnetd 1.14.0 or later
| fingerprint-strings: 
|   GenericLines, GetRequest, Help, NCP, NULL, RPCCheck, SIPOptions, tn3270: 
|_    Ubuntu 22.04.3 LTS
8075/tcp open  ftp     BusyBox ftpd (D-Link DCS-932L IP-Cam camera)
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_Can't get directory listing: PASV IP 172.18.0.2 is not the same as 10.10.53.8
| ftp-syst: 
|   STAT: 
| Server status:
|  TYPE: BINARY
|_Ok
|_ftp-bounce: bounce working!
8085/tcp open  telnet
| fingerprint-strings: 
|   NULL: 
|     Ubuntu 22.04.3 LTS
|     [...]
|_ 
8095/tcp open  telnet
| fingerprint-strings: 
|   GenericLines: 
|     Ubuntu 22.04.3 LTS
|     [...]
|_  
Nmap done: 1 IP address (1 host up) scanned in 87.18 seconds
```

Ok, let's connect via Telnet to ports 8065, 8085 and 8095.

When connecting with 8065 we only get the info `Ubuntu 22.04.3 LTS`, after that the connection closes directly.

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

When connecting to port 8085, we are greeted with the Vim banner. Nice, we have a Vim instance, as already announced in the room description and title. This could be interesting. Vim can be used to spawn shells or to browse the file system using a convenient explorer.

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

When connecting to port 8095, we see that we are confronted with the text editor Nano. This can also be interesting. Nano can at least be used to browse the file system using a convenient explorer.

### What is the value of the first flag?

Let's first look at the FTP, we connect with FTP and can log in with the user `anonymous`, as the Nmap scan suggests. Here we find some files and pictures, and also the first two flags, apparently.

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

We download and inspect the file `flag-1-of-4.txt` and find the first flag.

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

### What is the value of the second flag?

The second fold is not directly revealed in the file. But we have a shell script here that outputs the environment variable `$FLAG2`.

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

We can execute simple commands in Vim, let's try that. Maybe the shell script is just a hint to take a closer look at the environment variable on the target. Let's connect to 8085 the target Vim instance.

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

First we try to spawn a shell directly via `:shell`, unfortunately this does not work. More on this later. Instead, we can use `:echo` to display the second flag.

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

After we have executed `:echo $FLAG2` we get the second flag, nice.

<figure><img src="/files/0eoYmpQrVHxjIcbqtG4D" alt=""><figcaption></figcaption></figure>

### What is the value of the third flag?

So far, so good. As already mentioned, we could not spawn a shell via `:shell`. Also, setting a new shell target via `:set shell` to the usual locations of a bash or sh binary did not work.

So let's take a look at the file system first, maybe we have overlooked a binary. Via `:Ex`, we can use the Explorer functionality in Vim to browse the file system via Vim.

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

Using Ex:

A little hint that I was confronted with. Here, my arrow keys for navigation did not work as expected and threw this error.

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

If you get that message using the arrow keys, you can try the following:

Enter `:q` or terminate, reconnect and run `:Ex` again. Then use the following keys to navigate.

**h, j, k, l:**

* **`h`**: Move left.
* **`j`**: Move down.
* **`k`**: Move up.
* **`l`**: Move right.

We have the folder `/ftp` in `/tmp`, i.e. where our files are located in `ftp`. The executable files `nano` and `vim`, which may be used within the Telnet sessions.

<figure><img src="/files/8yBPtdAgL99T036ZoZkk" alt=""><figcaption></figcaption></figure>

Next, let's take a look at the environment variable of the current process in `/proc/self/environ`. Here we find the second flag again, the busybox is set both in `/etc/busybox` as a variable and `/etc/file/busybox`. The hostname is busybusybox. There is a strange protector script in `/usr/special/protector.sh`, we find the ftpd banner and a SHELL variable in `/tmp/sh`, although there is none there.

OK, that's a lot of clues. Everything seems to revolve around the `busybox`. As a very brief digression: BusyBox is a software suite that provides a set of Unix utilities in a single executable file. It is designed to be lightweight and efficient, making it well-suited for embedded systems and resource-constrained environments. BusyBox combines several common command-line utilities, such as ls, cp, mv, and others, into a single binary.

This is easier to interpret now that the box has been solved than it actually was, but with `/tmp/sh` it seems to be a hint to crafter your own shell and in particular to use the busybox as we will see in a moment.

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

We can actually find the busybox in `/etc/file`.

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

If we look in `/usr/bin` there are no binaries, even if we get a shell later, we can't do anything with it. Here it becomes clear that we have to make use of busybox since we are quite constrained. We do not have the usual binaries available.

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

Strangely enough, we find a shell binary in `/usr/frosty/sh`.

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

But it is empty, another hint to get it on the system yourself.

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

We look at the protector script, but it seems to be just a decoy.

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

Ok, we have ftp access to get files onto the system and vim to get them to where we need them. So the idea is to upload a static binary bash (like  <https://github.com/robxu9/bash-static/releases/tag/5.2.015-1.2.3-2>) to the system via ftp and then write it to `/usr/frosty/sh` via vim, for example, to be able to spawn a shell in Vim.

{% hint style="info" %}
Before the patch /etc/file/busybox was executable by the user running the telnet / vim connection. So all that have to be done was to upload a static bash to the ftp, open that in vim, writes that content to /usr/frosty/sh set shell to /usr/frosty/sh, run shell, see you can’t run anything. Use /etc/file/busybox to run commands like whoami or ps aux to enumerate the machine further. This is not possible anymore, now we have to place our own busybox onto the machine.
{% endhint %}

Given that we have no other binaries on the system, we'll use the static binary busybox.

Since busybox is not accessible, we need to create our own copy of it. Please upload it via FTP and write its content to `/tmp/nano`. Subsequently, rename `/tmp/nano` to `/tmp/busybox` to recognize its applets.

{% embed url="<https://busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/>" %}

Upload busybox:

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

You don’t need `:Ex` here, but it is a very comfortable way to navigate.

To open files use the following:

`:e! path/to/your/file.txt`

To write its contents to another file:

`:w! path/to/your/file.txt`

Open the uploaded busybox.

`:e! /tmp/ftp/busybox`

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

Write `/tmp/ftp/busybox` contents to `/usr/frost/sh`

`:w! /usr/frosty/sh`

<figure><img src="/files/7YrzTn9owaI27tYcdMAi" alt=""><figcaption></figcaption></figure>

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

Set the shell to `/usr/frosty/sh` in via `:set shell`.

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

After getting a shell, we see, we cant run any commands, even the found `/etc/file/busybox` doesnt work. (This worked pre patch)

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

Exit the shell via CTRL+D and open the busybox in `/tmp/ftp` again.

`:e! /tmp/ftp/busybox`

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

Now write its content to `/tmp/nano`.

`:w! /tmp/nano`

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

After that you might have to set shell again, run the shell and see that it did not work just replacing the contents of nano.

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

Exit the shell via CTRL+D again

Now we make use of the Explorer in Vim again via `:Ex`

Navigate to `/tmp/nano` and press capitalized `R` to rename `/tmp/nano` to `/tmp/busybox`

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

After successfully renaming `/tmp/nano` to `/tmp/busybox`…

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

...We run our shell again, now we are able to use if to its fully potential.

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

When enumerating the acutely running processes via `ps aux`, we find that the script `/usr/frosty/sh` is executed with root rights on `8065`. Great, we had our root in front of us the whole time, but didn't see it. Fortunately, we have already filled this file with the content of the busybox.

<figure><img src="/files/6Wubrecv5F5cicApZDxa" alt=""><figcaption></figcaption></figure>

We connect via telnet with 8065 and have a shell session as root. Nice. Now we can either use our own `busybox` `/tmp/busybox` or the `/etc/file/busybox` already on the system to continue.

We change the directory to `/root` and can use `ls` and `cat` via `busybox`. We find the third flag.

<figure><img src="/files/76RiipZcduURDpYjI4AN" alt=""><figcaption></figcaption></figure>

### What is the value of the fourth flag?

When enumerating with the Vim explorer, `/dev/root` has already been noticed, but has not yet been mentioned because of the overview. As the room with its graphics suggests, it also seems to be about a docker escape. Looking around the system, we see that we are in a Docker container. `/dev/root` seems to be a mount point to the root directory of the host. It strongly reminds of the exploit with lxd/lxc right where you create a misconfigured container with a root mount to the host. But here it just seems to be there already. You can find more about this on hacktricks and in my dreaming writeup section `The Unintended (Bonus)` .&#x20;

{% embed url="<https://0xb0b.gitbook.io/writeups/tryhackme/2023/dreaming#the-unintended-bonus>" %}

{% embed url="<https://book.hacktricks.xyz/linux-hardening/privilege-escalation/interesting-groups-linux-pe/lxd-privilege-escalation>" %}

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

<figure><img src="/files/2YcyfiiisiD3Lq7Z9hhQ" alt=""><figcaption></figcaption></figure>

Ok, let's mount to `/dev/root` and see what happens. We are able to reach the root directory of the host. Damn, that was almost too easy.

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

From our mount directory, we reach to the home directory of the host's root. Here we find the fourth flag and the yeti key.

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

### What is the value of the third Yetikey that has been placed in the root directory to verify the compromise?

And in the same folder, we find the `yetikey3.txt`.

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

## Credits To My Team

{% embed url="<https://tryhackme.com/p/sumanrox>" %}
For working together on this challenge
{% endembed %}

Check out Sumanroy's writeups:   <https://sumanroy.gitbook.io/ctf-writeups/>

{% embed url="<https://tryhackme.com/p/Atul.R.V>" %}
For working together on this challenge
{% endembed %}

For fully automated exploits created by my teammates, visit their GitHub profiles:

{% embed url="<https://github.com/sumanrox/sidequest-exploits>" %}
Automated SideQuest Exploits
{% endembed %}

{% embed url="<https://github.com/47hxl-53r/sidequest2023-exploits>" %}
Automated SideQuest Exploits
{% endembed %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://0xb0b.gitbook.io/writeups/tryhackme/2023/advent-of-cyber-23-side-quest/frosteau-busy-with-vim.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
