Skip to content

Commit fb31e03

Browse files
committed
done
1 parent 3aea800 commit fb31e03

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

lab8/solve.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
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+
proj = angr.Project('./chal')
8+
9+
10+
flag_chars = [claripy.BVS(f'flag_char_{i}', 8) for i in range(8)]
11+
flag = claripy.Concat(*flag_chars)
12+
13+
14+
stdin_stream = angr.SimFileStream('stdin', content=flag, has_end=True)
15+
16+
17+
state = proj.factory.entry_state(
18+
stdin=stdin_stream,
19+
add_options={angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY,
20+
angr.options.ZERO_FILL_UNCONSTRAINED_REGISTERS}
21+
)
22+
23+
24+
for c in flag_chars:
25+
state.solver.add(c >= 32)
26+
state.solver.add(c <= 126)
27+
28+
29+
simgr = proj.factory.simulation_manager(state)
30+
31+
32+
simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))
33+
34+
35+
if simgr.found:
36+
37+
solution_state = simgr.found[0]
38+
solution = solution_state.solver.eval(flag, cast_to=bytes)
39+
40+
sys.stdout.buffer.write(solution)
41+
else:
42+
print("No solution found!")
43+
secret_key = b""
44+
sys.stdout.buffer.write(secret_key)
845

946

1047
if __name__ == '__main__':

0 commit comments

Comments
 (0)