Day 18
Day 18|File Upload 修補建議:驗證檔案類型與內容
昨日複習
Day 17|File Upload Vulnerability 檔案上傳弱點
Attackers may upload a malicious file and execute it on the server.
正確答案 C. File Upload Vulnerability
這句在描述:File Upload Vulnerability(檔案上傳弱點)
看完整 Day 17 →今日句子
The application should validate the file type, file extension, and file content before accepting uploads.
中文意思
應用程式在接受上傳之前,應該驗證檔案類型、副檔名與檔案內容。
這句在說什麼資安問題
File Upload Vulnerability — Remediation(檔案上傳弱點修補建議)
這句出現在弱點報告的修補建議(Remediation)段落。光檢查副檔名是不夠的,攻擊者可以把 .php 改名成 .jpg 繞過;正確的做法是同時驗證 MIME type、檔案內容的 magic bytes,並限制允許的檔案類型與大小。
- 只檢查副檔名:攻擊者把 shell.php 改成 shell.jpg 就能繞過
- 同時檢查 MIME type 與 magic bytes,才能有效防止偽裝的惡意檔案
- 限制可上傳的副檔名白名單(allowlist),拒絕所有不在清單內的類型
- 將上傳的檔案存放在網站根目錄外,並透過程式讀取後再回傳,防止直接執行
重點單字
| 英文 | 中文 |
|---|---|
| should validate | 應該驗證 |
| file type | 檔案類型 |
| file extension | 副檔名 |
| file content | 檔案內容 |
| before accepting uploads | 在接受上傳之前 |
練習題
Store uploaded files outside the web root and prevent direct execution.
💡 outside the web root(網站根目錄外)代表檔案無法被瀏覽器直接存取;prevent direct execution(防止直接執行)則確保即使檔案被上傳,也無法被伺服器執行。這是 File Upload 弱點中最重要的防禦措施之一。