# Capture The Flag CTF 入門體驗 ###### 投影片連結:https://hackmd.io/@Sean64/sec ---- ## 講者介紹 - 資工大四 Sean 韋詠祥 - SITCON 2022 議程組長 - 系計中 Net 組、Web 組助教 - 資訊之芽 Python 講師 - 行政院技服中心 網路攻擊手 - 教育部竹苗區網 資安檢測員 ---- ## Welcome to CTF 請開啟 https://ctf.sean.cat/ 第一題 Flag 格式為 `FLAG{Print@b1e}` --- ## Capture the Flag (CTF) 分為... - Attack and Defense 攻防賽 - King of the Hill 爭霸戰 - Jeopardy 解謎賽 ---- ## Attack and Defense (A&D) - 主辦單位提供機器/服務 - 自行研究漏洞 - 幫服務上 patch(補丁) ---- ## HITCON DEFENSE ![](https://i.imgur.com/oB8oYOf.jpg) ---- ## King of the Hill (KoH) - 主辦單位提供幾個服務 - 看誰程式最短、撐得久、速度快、最接近完美 - 通常沒有標準解 ---- ## KoH 題目舉例 - 用最少步數解出 Wordle - 執行任何指令,讓自己程式存活最久 - 植入後門,讓首頁出現自家隊伍名稱 ---- ## Jeopardy - 大家解同一套題組 - 通常各題分數與難度相關 - 最常見的競賽類型 - 找到長得像 `FLAG{printable}` 的字串 ---- ## Jeopardy 常見形式 - CTFd ![](https://i.imgur.com/zeL82yw.png) --- # Jeopardy 基本分類 - Reverse 逆向工程 - Binary 執行檔滲透 - Web 網頁安全 - Crypto 密碼學 - Forensic 數位鑑識 - Misc 其他雜類 ---- ## Reverse 逆向工程 - 給一個執行檔,回推原始碼 - 先備知識:看得懂組合語言、熟悉各語言特性 ---- ## Binary 執行檔滲透 - 看懂程式碼後,找出漏洞並破解 - 通常需要 RCE 執行特定程式碼 - 先備知識:Reverse、系統架構 ---- ## Web 網頁安全 - 通常會是一個有資安漏洞的網站 - Flag 可能藏在原始碼、設定檔、資料庫等 - 先備知識:了解常見開發問題 ---- ## Broken Access Control - 第二題 https://ctf.sean.cat/bac - 只在登入頁面驗證身份 - 看一下原始碼 ---- ## Crypto 密碼學 - 通常會給加密用腳本、密文 - 自己找出實作瑕疵、可逆函式 - 先備知識:比較吃數學基礎 ---- ## Forensic 數位鑑識 - 提供數位檔案,從蛛絲馬跡找出答案 - 例如被駭侵的電腦映像檔 - 先備知識:工具使用、系統架構 ---- ## Misc 其他雜類 - 所有天馬行空、無法被歸類的題目 - 先備知識:通靈 --- # Web 經典漏洞 ---- ## Command Injection - 第三題 https://ctf.sean.cat/cmdi - 未過濾使用者輸入 - 通常會用 `id` 看身份、`ls` 及 `cat` 看檔案 ---- ## Path Traversal - 忘記限制存取權限 - 常見 `../%2e%2e/.%2e/etc/passwd` 字樣 ---- ## XSS - 第四題 https://ctf.sean.cat/xss - 未過濾使用者輸入 - 通常以 `<script>alert(1);</script>` 驗證 --- # Crypto 經典玩法 ---- ## Caesar Cipher 凱薩密碼 - 第五題 https://ctf.sean.cat/caesar - 以前以為很安全,但現在全世界都知道了 ---- ## Ecoji - 用 Emoji 做編碼 --- # Forensic 經典玩法 ---- ## Memory Dump 記憶體傾印 - 模擬鑑識中毒的電腦 - 需要特定工具處理、了解程式記憶體架構 ---- ## Steganography 隱寫術 - 第六題 https://ctf.sean.cat/stego - 在圖片、音訊、影片中隱藏資料 - 需要知道用哪種技術、金鑰 --- # Misc 經典題型 ---- ## QR code 修復 ![](https://i.imgur.com/AjHW2wi.png) --- # 學習資源 ---- ## PicoCTF - 初學入門題目合集 https://play.picoctf.org/ ---- ## CTFtime - 每週都有大大小小的比賽 https://ctftime.org/ ---- ## AIS3 新型態資安暑期課程 - 每年暑假課程 四月報名、五月測驗、七月上課 https://ais3.org/ ---- {%youtube nHOyRa7zPZE %} --- # Q&A 投影片連結:https://hackmd.io/@Sean64/sec <!-- .element: class="r-fit-text" --> <br> [![CC-BY 4.0](https://mirrors.creativecommons.org/presskit/buttons/88x31/png/by.png)](https://creativecommons.org/licenses/by/4.0/deed.zh_TW) ###### 這份投影片以 [創用 CC - 姓名標示](https://creativecommons.org/licenses/by/4.0/deed.zh_TW) 授權公眾使用,原始碼及講稿請見 [此連結](https://hackmd.io/@Sean64/sec/edit)。 ---- ## 延伸閱讀 / 參考資料 - [CTF 的三十道陰影](https://ithelp.ithome.com.tw/users/20121059/ironman/2810) - dada, iThome 鐵人賽 - [關於 CTF 的那些事](https://sitcon.org/2021/agenda/7a88857e-7d50-4d9c-a656-2d99feef6198) - LYS, SITCON 2022 - [Got Your PW](https://gotyour.pw/resources.html) - 專供資安人的資源與工具整理 - 簡報:[建功資研社課](https://hackmd.io/@Sean64/sec-cksh)、[SQLab Web CVE 課程](https://hackmd.io/@Sean64/SQLab-Web) ---- ## 補充:Web CVE Exploit 後面是 3 個最基本的 Path Traversal 漏洞 以及 1 個 unzip 的特殊用法 如果正課講完有時間就帶大家玩玩看 --- # Grafana Path Traversal / CVE-2021-43798 CVSS Score: 7.5 (High) ![](https://i.imgur.com/uIvmsm6.png) ---- ## Fix Commit 請參考 "`grafana/grafana@c798c0e9`" ![](https://i.imgur.com/Fj9nrPC.png) ---- ## Why? 用 "`filepath.Join()`" 處理使用者輸入會出問題 ![](https://i.imgur.com/Hh7WU42.png) ---- ## What is "`Rel()`"? ```go func Rel(basepath, targpath) /* Join(basepath, Rel(basepath, targpath)) == targpath */ ``` 回傳一個當 `basepath` 與結果 `Join()` 時, 會等價於 `targpath` 的相對路徑 當 `targpath` 無法轉換為相對於 `basepath` 的相對路徑時,會回傳錯誤 ---- ## How to fix it? 在 `Join()` 前,先用 `Rel()` 排除相對路徑 ![](https://i.imgur.com/Fj9nrPC.png) ---- ## Try it! - 第七題 https://ctf.sean.cat:43798 /public/plugins/alertlist/../../sdk.ts Hint: 請用 "`curl --path-as-is`",否則 "`../`" 會被瀏覽器吃掉 --- # Apache 2.4.49 Path Traversal / CVE-2021-41773 CVSS Score: 7.5 (High) ![](https://i.imgur.com/Gsipgl7.png) ---- ## Fix Commit ![](https://i.imgur.com/3HgZkNi.png) ---- ## Looks familar? 他叫我們不要用 "`%2e`" 或 "`%2E`" ![](https://i.imgur.com/w5Dk8Hc.png) ---- ## Try it! - 第八題 https://ctf.sean.cat:41773 /icons/.%2e/conf/httpd.conf 這題同樣只有特定目錄才有漏洞 ---- # Apache 2.4.50 <small>(Hum?)</small> Path Traversal / CVE-2021-42013 CVSS Score: 9.8 (Critical) ![](https://i.imgur.com/R1OpDHX.png) ---- ## Why? 讓我們再看一次之前的 patch ![](https://i.imgur.com/3HgZkNi.png) ---- ## Fix Commit 現在 "`%`" 後面只能接兩個 "`[0-9a-f]`" 字元了 ![](https://i.imgur.com/aPYhoQm.png) ---- ## Try it! - 第九題 https://ctf.sean.cat:42013 /icons/.%%32%65/conf/httpd.conf 使用 "`%%32%65`" 來做 double encoding ![](https://i.imgur.com/w5Dk8Hc.png) --- # elFinder (zip) Command Injection / CVE-2021-32682 CVSS Score: 9.8 (Critical) ---- ## How to use `zip` command ```shell $ zip -r9 -q 'target.zip' './source.txt' ``` ```text -q, --quiet Quiet mode; eliminate informational messages and comment prompts. (Useful, for example, in shell scripts and background tasks). ``` ```text -r, --recurse-paths Travel the directory structure recursively; for example: `zip -r archive.zip folder/` ``` ```text -# (-0, -1, -2, -3, -4, -5, -6, -7, -8, -9) The speed of compression. -0 means no compression. -1 indicates the fastest compression speed. -9 uses the optimal compression. ``` ---- ## There are more options... ```text -v, --verbose Verbose mode or print diagnostic version info. ``` ```text -T, --test Test the integrity of the new zip file. ``` ```text -TT, --unzip-command Use custom command to test an archive when the -T option is used. ``` ---- ## Fix Commit 對檔名加上 `./` 前綴 ![](https://i.imgur.com/vCoid7K.png) ---- ## How to run arbitrary code? 我們可以善用 `zip -TT` 選項 ```shell $ zip -T -TT 'echo' file.zip ``` ---- ## Try it! - 隱藏題 https://ctf.sean.cat:32682 <small>(不在計分系統上)</small> Hint: 檔名可以用 "`-v hello.zip`" 試試看
{"type":"slide","tags":"presentation","title":"CTF 入門體驗 - 交大 BambooFox","description":"Sean 韋詠祥 / 2022-11-09 18:30 / Jeopardy 基本分類 / Reverse 逆向工程、Binary 執行檔滲透、Web 網頁安全、Crypto 密碼學、Forensic 數位鑑識、Misc 其他雜類 / 學習資源 / Web CVE Exploit / Path Traversal"}
    1046 views