Sorry, your browser cannot access this site
This page requires browser support (enable) JavaScript
Learn more >

0x01 堆常见泄露方式

首先main_arena是一个存在于libc上的结构体,上面维护了一些指针,如下图(以64位为例):

heap

  • 黄色的部分是 fastbins 单链表,每个链表存储特定大小的 chunk , LIFO后进先出
  • 绿色的部分是 topchunk ,存储着 topchunk 的 chunk 首地址
  • 紫色的部分是 last_remainder ,存储着 melloc 时切割剩余的部分
  • 深蓝的部分是 unsortedbin 双链表,存储的 chunk 大小无序,(当释放一个不属于 fastbins 的 chunk 时,如果该 chunk 不和 topchunk 紧邻,该 chunk 会被首先放到 unsortedbin 中)
  • 浅蓝的部分是 smallbins 双链表,每个链表存储特定大小的 chunk , FIFO先进先出
  • 橙色的部分是 largebins 双链表,每个链表存储的 chunk 大小在某个范围内(并不一定大小相同)

unsorted bin leak

当 unsorted bin 中存在一个 chunk 时,链表结构如下:

unsorted bin fd -> bin1 ->unsorted bin fd

unsorted bin bk <- bin1 <-unsorted bin bk

所以通过打印bin1即可泄露 unsorted bin fd/bk 的地址,又 unsorted bin fd/bk 是一个 main_arena 上的地址,而 main_arena 关于 libc_base 的偏移是固定的,如此一来即可泄露libc

0x02 Tcache Poisoning

泄露libc之后,通过覆盖 tcache 中的 next,不需要伪造任何 chunk 结构即可实现 malloc 到任何地址

接下来常用的手法是 molloc 到某个 hook 处,如 malloc_hook , realloc_hook , free_hook

1
tips:在pwndbg中,使用p &__malloc_hook 即可打印 hook 地址

暂时先写这么多,剩下的慢慢补