glibc 堆利用目标速查表
作者:Vesper Vei
3 分钟阅读
目录
glibc 堆利用目标速查表
速查表
| glibc 版本 | 主要特征 | 常见利用入口 | 常见目标 | 你该优先想到什么 |
|---|---|---|---|---|
| 2.23 | 没有 tcache | fastbin dup, unsorted bin leak, overlap, unlink 类老套路 | __malloc_hook, __realloc_hook, __free_hook | fastbin / fake chunk / hook 老打法 |
| 2.27 | 开始有 tcache,但很多题仍混合老套路 | tcache poisoning, unsorted leak | __free_hook, __malloc_hook | tcache 开始好用,但老思路还常见 |
| 2.29 ~ 2.31 | tcache 很成熟,还没有 safe-linking | UAF 改 tcache fd, double free, poisoning | __free_hook, __malloc_hook | 有 UAF 就先想 tcache poisoning → free_hook |
| 2.32 ~ 2.33 | 有 safe-linking | tcache/fastbin 仍可用,但 fd 要解保护 | __free_hook 仍在 | 先处理 safe-linking,再想 hook |
| 2.34+ | __malloc_hook/__free_hook被移除 | heap primitive 还在,但目标换了 | IO_FILE/FSOP, setcontext, exit handlers, fini_array 等 | 别再执着 hook,优先想新目标 |
你可以这样记
1)2.23:老派堆题时代
拿到 2.23,先想到的是:
- fastbin dup
- unsorted bin leak libc
- overlap / unlink
__malloc_hook - 0x23one_gadgetrealloc配合触发
这一代题目的手感就是:
更像在伪造 chunk、伪造 size、卡 allocator 检查。
所以你之前学的 __malloc_hook - 0x23 就很有代表性。
2)2.31:hook 时代最舒服的版本之一
2.31 很适合练“现代但还不算太难”的堆利用,因为:
- 有 tcache
- 没 safe-linking
__free_hook/__malloc_hook还在
所以如果你有:
- UAF
- double free
- 可控 edit-after-free
那通常优先想:
leak libc
→ tcache poisoning
→ __free_hook = system
→ free(“/bin/sh”)
这是非常典型的一条线。
所以你前面说:
2.31 有 UAF 时,打
__free_hook更容易?
对,通常是这样。
3)2.32+:开始不能无脑写 fd 了
2.32 开始,最关键的变化就是:
safe-linking
所以你不能再直接:
fd = target
而要处理类似:
fd = target ^ (heap_addr >> 12)
这会让 tcache poisoning 多一层门槛。
所以这类版本里,重点不是“目标选谁”,而是先想:
我能不能先解出 heap,能不能正确伪造保护后的 fd?
4)2.34+:hook 思路基本退出主舞台
2.34 开始,很多你熟悉的 hook 被移除了。
这时拿到题,你就要立刻切换脑回路:
不要先想:
__free_hook__malloc_hook
而要先想:
IO_FILE/ FSOP_IO_2_1_stderr_/_IO_2_1_stdout_setcontext- exit 触发链
- vtable / fini_array / rtld 相关目标
再给你一个“按 primitive 选目标”的版本
这个更适合比赛里现场判断。
如果你有 UAF + glibc 2.31
优先级通常是:
__free_hook -> system__malloc_hook -> one_gadget- 其他全局目标
原因:
- tcache poisoning 好打
free_hook触发简单system("/bin/sh")约束少
如果你有 fastbin primitive + glibc 2.23
优先级通常是:
__malloc_hook - 0x23__realloc_hook__free_hook- 其他 old-school 目标
原因:
- fake chunk 语义天然适配 fastbin 老套路
malloc_hook附近有成熟打法- 很多题就是这么出的
如果你有 arbitrary write,但 hook 不在了
优先级通常切成:
IO_FILE/ FSOPsetcontext + ROP- exit handlers
- vtable / function pointer 类目标
最后给你一个特别实用的“拿到题先问自己什么”
以后别先背“这个版本一定打什么”,而是按这个顺序想:
第一步:看版本
- 有没有 tcache?
- 有没有 safe-linking?
- hook 还在不在?
第二步:看 primitive
- UAF?
- double free?
- off-by-one?
- overlap?
- arbitrary write?
第三步:看目标
- 哪个目标最容易写到?
- 哪个目标最好触发?
- 哪个目标约束最少?
你现在可以这样粗记
入门到进阶阶段最常见的版本印象:
- 2.23:fastbin /
__malloc_hook - 2.31:tcache poisoning /
__free_hook - 2.32+:safe-linking
- 2.34+:FSOP / 新目标
对你当前阶段最重要的一句话
你现在已经学到:
- 2.23 老套路
- 2.31 hook 题
- 开始碰到
IO_FILE
这条路线其实非常对。
因为它刚好对应 glibc 堆利用发展的三层:
老 hook 时代 → tcache 时代 → 后 hook 时代