Skip to content

Commit 97331b3

Browse files
authored
Merge pull request #562 from SapphireLinXu/lab8
[LAB8] 312553027
2 parents f5ccb02 + a047149 commit 97331b3

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lab8/solve.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
11
#!/usr/bin/env python3
22

33
import angr,sys
4+
import claripy
45

56
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
7+
binary = "./chal"
8+
project = angr.Project(binary, auto_load_libs=False)
9+
10+
symbolic_input = [claripy.BVS(f'char_{i}', 8) for i in range(8)]
11+
flag_input = claripy.Concat(*symbolic_input)
12+
13+
initial_state = project.factory.entry_state(stdin=flag_input)
14+
15+
simulation = project.factory.simgr(initial_state)
16+
simulation.explore(
17+
find=lambda state: b"Correct!" in state.posix.dumps(1),
18+
avoid=lambda state: b"Wrong key!" in state.posix.dumps(1)
19+
)
20+
21+
if simulation.found:
22+
winning_state = simulation.found[0]
23+
correct_flag = winning_state.solver.eval(flag_input, cast_to=bytes)
24+
sys.stdout.buffer.write(correct_flag)
25+
else:
26+
print("Unable to find the correct input.", file=sys.stderr)
27+
sys.exit(1)
28+
829

930

1031
if __name__ == '__main__':

0 commit comments

Comments
 (0)