defexcut(prog): process = subprocess.Popen(prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) out, _ = process.communicate() return out
start = 0x2060 lenth = 0x76a0
withopen('./chal', 'rb') as f: f.seek(start) for i inrange(8): data = f.read(lenth) withopen('filter_%d' % i, 'wb') as d: d.write(data) excut(f'sudo seccomp-tools disasm ./filter_{i} > dump_{i}') excut(f'rm ./filter_{i}')
data = '' for i inrange(8): withopen(f'dump_{i}', 'r') as f: data = f.read() data = data.replace('sys_number', '0x1337').replace('arch', '0xc000003e') withopen(f'dump_{i}', 'w') as f: f.write(data.split('=================================\n')[1])
s = Solver() A = 0 X = 0 mask = 0xFFFFFFFF mem = [0] * 0x10 # args = [BitVec(f'arg_{i}', 64) for i in range(6)] args = [BitVec(f'arg_{i}', 32) for i inrange(6 * 2)]
# vars = {} for i inrange(8): withopen(f'dump_{i}', 'r') as f: lines = f.readlines() for line in lines: code = line[34:-1] if code[0] == 'A'or code[0] == 'X'or code[0] == 'm': if'args'notin code: exec(code) iftype(A) == int: A &= mask iftype(X) == int: X &= mask else: res = re.match(r'A = args\[(\d+)\]', code) idx = res.group(1) if code[-5:] == '>> 32': A = args[int(idx) * 2 + 1] else: A = args[int(idx) * 2] elif code[0] == 'i': res = re.match(r'if \(A != (\d+)\) goto (\d+)', code) num = 0 if res: num = int(res.group(1)) else: try: res = re.match(r'if \(A == (\d+)\) goto (\d+)', code) num = int(res.group(1)) except: continue s.add(A == num) # vars[code[0]] = 1
# print(vars) if s.check() == sat: m = s.model() for i inrange(6 * 2): try: print(m[args[i]].as_long().to_bytes(4, 'little').decode(), end='') except: print('*' * 4, end='')