Skip to content

Commit 71cbfbd

Browse files
authored
Merge pull request #532 from sss28072637/lab8
[LAB8] 313560007
2 parents 9868a0c + e32e98f commit 71cbfbd

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

lab8/solve.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
#!/usr/bin/env python3
2-
3-
import angr,sys
2+
import sys
3+
import angr
4+
import claripy
45

56
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
8-
7+
proj = angr.Project('./chal', auto_load_libs=False)
8+
9+
input_size = 8
10+
sym_chars = [claripy.BVS(f'char_{i}', 8) for i in range(input_size)]
11+
sym_input = claripy.Concat(*sym_chars)
12+
13+
state = proj.factory.entry_state(stdin=sym_input)
14+
15+
for char in sym_chars:
16+
state.solver.add(char >= 0x20) # 可列印字元
17+
state.solver.add(char <= 0x7e)
18+
19+
simgr = proj.factory.simulation_manager(state)
20+
21+
simgr.explore(
22+
find=lambda s: b"Correct!" in s.posix.dumps(1),
23+
avoid=lambda s: b"Wrong key!" in s.posix.dumps(1)
24+
)
25+
26+
if len(simgr.found) > 0:
27+
solution = simgr.found[0].solver.eval(sym_input, cast_to=bytes)
28+
sys.stdout.buffer.write(solution)
29+
else:
30+
print("No solution found", file=sys.stderr)
31+
sys.exit(1)
932

1033
if __name__ == '__main__':
11-
main()
34+
main()

0 commit comments

Comments
 (0)