Skip to content

Commit 6155765

Browse files
authored
Merge pull request #559 from hsuan881119/lab8
[LAB8] 313581030
2 parents cf6e6ef + 1958287 commit 6155765

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

lab8/solve.py

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

3-
import angr,sys
3+
import angr
4+
import claripy
5+
import sys
6+
7+
angr.loggers.disable_root_logger()
8+
9+
def is_flag_found(state):
10+
output = state.posix.dumps(1)
11+
return b"flag" in output
412

513
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
14+
project = angr.Project("./chal", auto_load_libs=False)
15+
16+
sym_chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
17+
sym_input = claripy.Concat(*sym_chars)
18+
19+
state = project.factory.full_init_state(
20+
stdin = angr.SimFileStream(name='stdin', content=sym_input, has_end=True)
21+
)
22+
23+
24+
simgr = project.factory.simgr(state)
25+
26+
simgr.explore(
27+
find = lambda s:b"Correct!" in s.posix.dumps(1)
28+
)
29+
30+
if simgr.found:
31+
found = simgr.found[0]
32+
secret_key = found.solver.eval(sym_input, cast_to=bytes)
33+
sys.stdout.buffer.write(secret_key)
34+
else:
35+
print("No solution found!")
36+
sys.exit(1)
837

938

1039
if __name__ == '__main__':

0 commit comments

Comments
 (0)