Upgrade to Pro — share decks privately, control downloads, hide ads and more …

不要亂 PWN 我@HackerSir 10th

YJK
August 31, 2024
0

不要亂 PWN 我@HackerSir 10th

YJK

August 31, 2024
Tweet

Transcript

  1. How to PWN ? • 尋找漏洞 ◦ 模糊測試 ◦ 原始碼

    ◦ 組合語言 Start Input Output aborted segmentation fault
  2. How to PWN ? • 尋找漏洞 ◦ 模糊測試 ◦ 原始碼

    ◦ 組合語言 • 利用漏洞 ◦ 控制執行流程 ◦ 覆蓋 return address ◦ 修改變數
  3. How to PWN ? • 尋找漏洞 ◦ 模糊測試 ◦ 原始碼

    ◦ 組合語言 • 利用漏洞 ◦ 控制執行流程 ◦ 覆蓋 return address ◦ 修改變數 ◦ Get Shell
  4. ELF • Executable and Linkable Format • 可執行檔 ◦ Windows:exe

    ◦ Linux:ELF • Section ◦ 執行時會映射到記憶體上 ◦ .text、.bss、.data、.rodata、.got、.plt…
  5. Session • .bss ◦ 存放未初始化的全域變數 • .data ◦ 存放初始化的全域變數 •

    .rodata ◦ 存放可讀不可寫資料 • .text ◦ 存放編譯後的程式碼
  6. Protections • PIE ◦ Position-Independent Executable • NX ◦ No-Execute

    • Stack Canary ◦ stack protector • RELRO ◦ Relocation Read-Only
  7. PIE • Position-Independent Executable • code & data section map

    到位址時隨機 • 開啟時,每次執行都不同,否則固定 0x400000
  8. PIE • Position-Independent Executable • code & data section map

    到位址時隨機 • 開啟時,每次執行都不同,否則固定 0x400000 • 關閉方式
  9. ASLR • Address Space Layout Randomization • 針對 Process 的防護機制

    • 動態載入位址隨機 ◦ library ◦ stack ◦ heap
  10. Stack Canary • Stack Protector • rbp 前塞 8 byte

    random 值,ret 驗證是否相同 • 1st byte 為 null byte • 每次執行的值不同 • 防範 buffer overflow
  11. Stack Canary • Stack Protector • rbp 前塞 8 byte

    random 值,ret 驗證是否相同 • 1st byte 為 null byte • 每次執行的值不同 • 防範 buffer overflow • 關閉方式
  12. RELRO • Relocation Read-Only • No / Partial / Full

    • 防範 Lazy Binding 問題 Link Map GOT No O O Partial X O Full X X
  13. Buffer Overflow • 記憶體狀況 low address int num1 int num2

    char buf[0x10] int num3 int num4 save rbp return address high address
  14. Buffer Overflow • 記憶體狀況 • gets(buf) • gets 不會檢查輸入長度 low

    address int num1 int num2 char buf[0x10] int num3 int num4 save rbp return address high address
  15. Buffer Overflow • 記憶體狀況 • gets(buf) • gets 不會檢查輸入長度 •

    正常輸入範圍 low address int num1 int num2 ‘A’ * 0x10 int num3 int num4 save rbp return address high address
  16. Buffer Overflow • 記憶體狀況 • gets(buf) • gets 不會檢查輸入長度 •

    Overflow!!!! low address int num1 int num2 AAAAAAAAAAAAAAAA AAAA AAAA save rbp return address high address
  17. Overwrite Variable • 透過 buffer Overflow 控制變數 • int num3

    = 0x12345678 • int num4 = 0x90abcdef low address int num1 int num2 AAAAAAAAAAAA 0x12345678 0x90abcdef save rbp return address high address
  18. How to debug ? • 透過 gdb.attach 到執行的 process •

    開啟一個視窗,可以執行 gdb 的各種操作
  19. Overwrite Return Address • 透過 Buffer Overflow 改變 return address

    • 可以改寫到任意 address • 必須關閉 PIE
  20. GOT • library 位址載入時才決定 • 編譯時無法得知 library function 位址 •

    GOT 儲存 library function 的指標陣列 • 一開始不會得之真實位置,而是填入位於 plt 的 code
  21. GOT Hijacking • 由於 Lazy Binding,GOT 可寫 • 如果可以覆蓋到 GOT

    的值,下次呼叫到 function 時即 可控制將要執行的 function pointer • Ex:陣列沒驗證輸入區域、記憶體