changed 2 years ago
Published Linked with GitHub

Capture The Flag

CTF 入門體驗

投影片連結:https://hackmd.io/@Sean64/sec-bbf2022

講者介紹

  • 資工大四 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


King of the Hill (KoH)

  • 主辦單位提供幾個服務
  • 看誰程式最短、撐得久、速度快、最接近完美
  • 通常沒有標準解

KoH 題目舉例

  • 用最少步數解出 Wordle
  • 執行任何指令,讓自己程式存活最久
  • 植入後門,讓首頁出現自家隊伍名稱

Jeopardy

  • 大家解同一套題組
  • 通常各題分數與難度相關
  • 最常見的競賽類型
  • 找到長得像 FLAG{printable} 的字串

Jeopardy 常見形式 - CTFd


Jeopardy 基本分類

  • Reverse 逆向工程
  • Binary 執行檔滲透
  • Web 網頁安全
  • Crypto 密碼學
  • Forensic 數位鑑識
  • Misc 其他雜類

Reverse 逆向工程

  • 給一個執行檔,回推原始碼
  • 先備知識:看得懂組合語言、熟悉各語言特性

Binary 執行檔滲透

  • 看懂程式碼後,找出漏洞並破解
  • 通常需要 RCE 執行特定程式碼
  • 先備知識:Reverse、系統架構

Web 網頁安全

  • 通常會是一個有資安漏洞的網站
  • Flag 可能藏在原始碼、設定檔、資料庫等
  • 先備知識:了解常見開發問題

Broken Access Control


Crypto 密碼學

  • 通常會給加密用腳本、密文
  • 自己找出實作瑕疵、可逆函式
  • 先備知識:比較吃數學基礎

Forensic 數位鑑識

  • 提供數位檔案,從蛛絲馬跡找出答案
  • 例如被駭侵的電腦映像檔
  • 先備知識:工具使用、系統架構

Misc 其他雜類

  • 所有天馬行空、無法被歸類的題目
  • 先備知識:通靈

Web 經典漏洞


Command Injection


Path Traversal

  • 忘記限制存取權限
  • 常見 ../%2e%2e/.%2e/etc/passwd 字樣

XSS


Crypto 經典玩法


Caesar Cipher 凱薩密碼


Ecoji

  • 用 Emoji 做編碼

Forensic 經典玩法


Memory Dump 記憶體傾印

  • 模擬鑑識中毒的電腦
  • 需要特定工具處理、了解程式記憶體架構

Steganography 隱寫術


Misc 經典題型


QR code 修復


學習資源


PicoCTF


CTFtime


AIS3 新型態資安暑期課程

  • 每年暑假課程

四月報名、五月測驗、七月上課
https://ais3.org/


Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →


Q&A

投影片連結:https://hackmd.io/@Sean64/sec-bbf2022


CC-BY 4.0

這份投影片以 創用 CC - 姓名標示 授權公眾使用,原始碼及講稿請見 此連結

延伸閱讀 / 參考資料


補充:Web CVE Exploit

後面是 3 個最基本的 Path Traversal 漏洞
以及 1 個 unzip 的特殊用法
如果正課講完有時間就帶大家玩玩看


Grafana

Path Traversal / CVE-2021-43798
CVSS Score: 7.5 (High)


Fix Commit

請參考 "grafana/grafana@c798c0e9"


Why?

用 "filepath.Join()" 處理使用者輸入會出問題


What is "Rel()"?

func Rel(basepath, targpath)

/* Join(basepath, Rel(basepath, targpath)) == targpath */

回傳一個當 basepath 與結果 Join() 時,
會等價於 targpath 的相對路徑

targpath 無法轉換為相對於 basepath 的相對路徑時,會回傳錯誤


How to fix it?

Join() 前,先用 Rel() 排除相對路徑


Try it!

Hint: 請用 "curl --path-as-is",否則 "../" 會被瀏覽器吃掉


Apache 2.4.49

Path Traversal / CVE-2021-41773
CVSS Score: 7.5 (High)


Fix Commit


Looks familar?

他叫我們不要用 "%2e" 或 "%2E"


Try it!

這題同樣只有特定目錄才有漏洞


Apache 2.4.50 (Hum?)

Path Traversal / CVE-2021-42013
CVSS Score: 9.8 (Critical)


Why?

讓我們再看一次之前的 patch


Fix Commit

現在 "%" 後面只能接兩個 "[0-9a-f]" 字元了


Try it!

使用 "%%32%65" 來做 double encoding


elFinder (zip)

Command Injection / CVE-2021-32682
CVSS Score: 9.8 (Critical)


How to use zip command

$ zip -r9 -q 'target.zip' './source.txt'
-q, --quiet
    Quiet mode; eliminate informational messages and
    comment prompts.  (Useful, for example, in shell
    scripts and background tasks).
-r, --recurse-paths
    Travel the directory structure recursively;
    for example: `zip -r archive.zip folder/`
-#  (-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

-v, --verbose
    Verbose mode or print diagnostic version info.
-T, --test
    Test the integrity of the new zip file.
-TT, --unzip-command
    Use custom command to test an archive
    when the -T option is used.

Fix Commit

對檔名加上 ./ 前綴


How to run arbitrary code?

我們可以善用 zip -TT 選項

$ zip -T -TT 'echo' file.zip

Try it!

Hint: 檔名可以用 "-v hello.zip" 試試看

Select a repo