Heap_Exploitation

Heap_Exploitation

Grissia Lv2

Heap

Intro

ELF sections
heap 是從低位高位
然後主要會用到:

  • malloc(size) 拿記憶體
  • free(ptr) 釋放記憶體

malloc 後拿到的 ptr 會指著 user_data 的地方 可以直接開始寫入
但實際上 ptr-0x10 有存一些這個 chunk 的資訊

Freed_Heap

free 掉之後會依照大小被分到不同的 bin

fast bin

  • size < 0x90 會被分到這
  • 裡面還有依大小分: 0x20, 0x30, 0x40 … 0x80
  • LIFO
  • 不會把 free 掉的 chunk P flag 設成 0

small bin

在 free 掉之後 chunk 會被寫入

  • fd
  • bk

如果是 unsorted bin 還會有

  • fd_nextsize
  • bk_nextsize

Chunk

第一次執行 malloc 會呼叫 sys_brk 或 sys_mmap
來拿記憶體 也就是 main arena

heap 有 ASLR 所以有時候會要 leak heap base
malloc 拿到的記憶體塊就是 chunk

  • Allocated Chunk
  • Free Chunk
  • Top Chunk

Size Alignment

chunk 的大小會對齊 0x10
如果 malloc 0x18 會拿到 0x20 的大小

Common Exploit

Use After Free

Double Free

Heap Hooks

Heap Exploitation

fastbin attack

tcache

and more

  • 標題: Heap_Exploitation
  • 作者: Grissia
  • 撰寫于 : 2024-11-27 19:10:33
  • 更新于 : 2024-11-27 21:34:38
  • 連結: https://grissia.github.io/2024/11/27/Heap-Exploitation/
  • 版權宣告: 本作品采用 CC BY-NC-SA 4.0 进行许可。