iT邦幫忙

2025 iThome 鐵人賽

DAY 21
0
Security

現在是pwn的天下!系列 第 21

【Day-21】Fastbin attack

  • 分享至 

  • xImage
  •  

Fastbin Attack

前言

Fastbin Attack 是一種 Heap Exploitation 技術,主要針對 小型 chunk(≤0x80, x86_64)
透過操控 fastbin freelist,可以實現 任意地址寫入,進而覆蓋函數指標、GOT entry 或 hook,達到遠程程式控制(RCE)。


漏洞來源

  • 小 chunk 被 free 後會加入 fastbin freelist
  • Freed chunk 的 fd 可以被 UAF 或 buffer overflow 修改
  • 下一次 malloc 將返回 fd 指向的任意地址,形成任意寫漏洞

利用流程

Step 1:準備 fastbin chunk

  • 分配多個小 chunk(≤0x80)
  • 刪除它們,使其進入 fastbin freelist

Step 2:操控 fastbin fd

  • 透過 UAFbuffer overflow 將 freed chunk 的 fd 改為 目標地址(如 GOT entry 或 hook)

Step 3:malloc → 任意寫

  • 下一次 malloc 返回 目標地址
  • 可以寫入任意內容,覆蓋重要函數指標或 GOT entry

Step 4:觸發覆寫

  • 執行被覆寫的函數(例如 free、puts)
  • 執行 payload,例如 system("/bin/sh"),取得 shell

Chunk / Fastbin 對應

Index Chunk Size Status 所在位置 備註
0 0x30 freed fastbin 用於 fastbin attack
1 0x30 freed fastbin fd 改寫成目標地址
2 0x30 allocated malloc → target 任意寫入地址
3 0x30 allocated malloc → payload 寫入 system 或 ROP gadget

Fastbin 狀態示意:

Before fd overwrite:
fastbin[0x30]: chunk1 -> chunk0 -> NULL

After fd overwrite (fd → target):
fastbin[0x30]: target -> chunk0 -> NULL

malloc(0x30) → returns target
malloc(0x30) → returns chunk0

攻擊核心

  1. Fastbin freelist manipulation → 任意地址寫入
  2. malloc returning controlled pointer → 覆蓋重要指標
  3. 觸發被覆寫函數 → 執行 payload

利用技術摘要

  1. Heap exploitation
  2. UAF / buffer overflow → fd overwrite
  3. Fastbin attack → arbitrary write
  4. Function pointer / GOT hijacking → RCE

上一篇
【Day-20】進階UAF
下一篇
【Day-22】one-gadget用法及介紹 (內附Lab)
系列文
現在是pwn的天下!30
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言