|
6 | 6 | def main(): |
7 | 7 | proj = angr.Project("./chal", auto_load_libs=False) |
8 | 8 |
|
9 | | - chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)] |
| 9 | + chars = [claripy.BVS(f'c{i}', 8) for i in range(8)] |
10 | 10 | null = claripy.BVV(0, 8) |
11 | 11 | input_bytes = claripy.Concat(*chars + [null]) |
12 | 12 |
|
13 | 13 | input_stream = angr.SimFileStream(name='stdin', content=input_bytes, has_end=False) |
14 | 14 |
|
15 | | - state = proj.factory.full_init_state( |
| 15 | + state = proj.factory.entry_state( |
16 | 16 | stdin=input_stream, |
17 | | - add_options={angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY} |
| 17 | + add_options={ |
| 18 | + angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY, |
| 19 | + angr.options.ZERO_FILL_UNCONSTRAINED_REGISTERS |
| 20 | + } |
18 | 21 | ) |
19 | 22 |
|
20 | 23 | for c in chars: |
21 | | - state.solver.add(c >= 0x20) |
22 | | - state.solver.add(c <= 0x7e) |
| 24 | + state.solver.add(c >= 0x20, c <= 0x7e) |
23 | 25 |
|
24 | 26 | simgr = proj.factory.simgr(state) |
25 | | - simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1)) |
| 27 | + simgr.explore( |
| 28 | + find=lambda s: b"CTF{" in s.posix.dumps(1), |
| 29 | + avoid=lambda s: b"Wrong key" in s.posix.dumps(1) |
| 30 | + ) |
26 | 31 |
|
27 | 32 | if simgr.found: |
28 | 33 | found = simgr.found[0] |
29 | 34 | result = found.solver.eval(claripy.Concat(*chars), cast_to=bytes) |
30 | | - sys.stdout.buffer.write(result) |
| 35 | + print(result.decode(), end='') |
31 | 36 | else: |
32 | | - print("No solution found.") |
| 37 | + print("No solution found.", end='') |
33 | 38 |
|
34 | 39 | if __name__ == '__main__': |
35 | 40 | main() |
0 commit comments