Skip to content

Commit 3f1e335

Browse files
authored
Merge pull request #557 from skysoul1024/lab8
[LAB8] 313551109
2 parents 2949af2 + efb6dcf commit 3f1e335

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

lab8/solve.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
11
#!/usr/bin/env python3
22

3-
import angr,sys
3+
import sys
4+
import angr
5+
import claripy
46

57
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
8+
proj = angr.Project("./chal", auto_load_libs=False)
9+
flag_bytes = [claripy.BVS(f'flag_{i}', 8) for i in range(8)]
10+
flag = claripy.Concat(*flag_bytes)
811

12+
state = proj.factory.entry_state(stdin=flag)
13+
14+
simgr = proj.factory.simgr(state)
15+
simgr.explore(
16+
find=lambda s: b"Correct!" in s.posix.dumps(1),
17+
avoid=lambda s: b"Wrong key!" in s.posix.dumps(1)
18+
)
19+
20+
if simgr.found:
21+
found = simgr.found[0]
22+
solution = found.solver.eval(flag, cast_to=bytes)
23+
sys.stdout.buffer.write(solution)
24+
else:
25+
print("No solution found!", file=sys.stderr)
26+
sys.exit(1)
927

1028
if __name__ == '__main__':
1129
main()

0 commit comments

Comments
 (0)