# Pwn class2 - Heap exploit ###### tags: note ## Pwngdb instruction * heap, vmmap : 可查看 heap 使用情況 * bin : 同上 * b n : 再 source code 第 n 行設立中斷點,搭配 "c" 可直接執行到該行 * ctx : 回到執行介面 * make `-g` -o exeName file.c : 可 patch .c程式在 pwndbg 中可視化 * p : print EX: p arena ## Heap 基礎知識 * chunk * 結構   * Heap 分配記憶體最小單位,最小為 0x20 bytes,且會對齊 0x10 bytes * allocated chunk : 正在使用中的記憶體 * freed chunk : 已被釋放的記憶體 * bin : 動態記憶體被釋放後會被放在回收區,後續有需求時在從此處取。 * bin * 共分為 5 種  * 在 tcachebin, fastbin, smallbin 中,每隔 0x10 大小會有 `sunbin`, EX: 0x20 為一群,0x30為一群... 原因為,若雜亂儲存很沒有效率 EX: 0x20 -> 0x50 -> 0x30 -> ... * Tcache * 存放 0x20 ~ 0x410 大小的 chunk * 給個 subbin 最多存放 7 個 chunk ,彼此採單向的 linked list 連結。根據優先順序存放,存滿了再往下 * `fd 指向 Header` * Fastbin * 存放 0x20 ~ 0x80 大小的 chunk * subbin 數量沒有限制 * `fd 指向 data`  * Smallbin * 存放 0x20 ~ 0x3f0 大小的 chunk * 其中 0x20 ~ 0x80 的部分與 Fastbin 重疊 * 直接 free 的 chunk 會存入 Fastbin * 從 unsorted bin 放入的會存到 Smallbin * 符合大小的 chunk 不會直接放入,而是透過 unsorted bin * `fd 指向 data` * Largebin * 存放 >= 0x400 大小的 chunk ##   ## arena * 位於 .data 中,存在 glibc
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up