Week 6. Crafty
TL;DR
This is a gaming Windows Server 2019 running Minecraft 1.16.5, which is known to be affected by the Log4Shell vulnerability (CVE-2021-44228). There are several Log4Shell PoCs in GitHub to get a foothold in the server. The administrator password is found in a JAR file found in the file system.
KEYWORDS
Minecraft, Log4Shell, CVE-2021-44228, Java decompiler, RunasCS.
REFERENCES
https://www.cvedetails.com/cve/CVE-2021-44228/
https://github.com/kozmer/log4j-shell-poc
https://www.youtube.com/watch?v=7qoPDq41xhQ
https://mirrors.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
https://github.com/antonioCoco/RunasCs
ENUMERATION
Port scan.
Enumerate the open ports.
Update the /etc/hosts
file and enumerate the site with Firefox. We see information about a Minecraft server running at play.crafty.htb
. There are no more interaction points with the backend in the website.
In summary, we have found a Minecraft server v1.16.5 running on port 25565.
USER
Searching for Minecraft 1.16.5 vulnerabilities in the web, we find out that versions from 1.8.8 to 1.18.1 are affected by Log4Shell vulnerability, a critical bug in the Apache log4j java logging library (https://www.cvedetails.com/cve/CVE-2021-44228/).
If you search in GitHub you will find several PoCs for Log4Shell exploitation, and there are also tutorials in Youtube, such as this: https://www.youtube.com/watch?v=7qoPDq41xhQ
We will use this one: https://github.com/kozmer/log4j-shell-poc. Note that the poc.py
cannot be used off-the-self, if you inspect carefully the source code you will see 2 modifications are needed.
First, the PoC is designed to be used in Linux, but since crafty.htb
is a Windows machine, a first modification is needed to adapt the exploit part to the Windows systems (just replace /etc/sh
with cmd
).
Next, according to the author you need to copy your version of Java in the repository root directory. The author provides a link to Oracle but, since registration is required, another one was used: https://mirrors.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
Follow the author instructions: unpack the Java package in the repository root folder and rename the directory as ./jdk1.8.0_20
, to match the Java path used in the source code. Alternatively, you can leave the directory named as you want and modify the source code accordingly.
Once finished, verify Java is successfully installed.
Now run the exploit.
The PoC automatically starts an LDAP server on ports 1389 and also generates a payload called Exploit.class
which will be served on an HTTP server running on port 8000.
You also need to start a listener on port 1919 (this port can be modified with the –lport
option).
The PoC provides the payload we need to inject in the Minecraft chat.
Next step is to join a game in the Minecraft server. For this, download a Minecraft client such as this: https://tlauncher.org/en/download_1/minecraft-1-16-5_12582.html. Choose the version that suits your platform, in this case we will use the .jar
Linux version available here: https://tlauncher.org/jar
Unzip and run the client.
Once the client start, make sure you install the Minecraft version 1.65.5, which is the one that matches the one running in the server.
When the installation is completed, click on "Enter the game". In the startup screen click on "Multiplayer" and add a new server play.crafty.htb
. Join the server and as soon as the game starts press "T" to open the chat and enter the payload.
When the payload is entered in the chat, a reverse shell is received on port 1919.
Which can be used to retrieve the user flag.
SYSTEM
Start from the user shell and take the opportunity to enumerate the system.
Locate the file c:\Users\svc_minecraft\server\plugins\playercounter-1.0-SNAPSHOT.jar
in the file system. Inspect the file and extract the class /htb/crafty/playercounter/Playercounter.class
Decompile using whatever method you like, for example, using an online decompiler: https://www.decompiler.com/
Looks like credential s67u84zKq8IXw
is used to connect to an internal service running on 27015 for management purposes.
Generate an EXE payload with msfvenom
, transfer the shell.exe
payload and runascs.exe
(https://github.com/antonioCoco/RunasCs) to the victim and run them.
A reverse shell is received on the listener.
You are root.
Last updated