Skip to content

Commit 1232b79

Browse files
authored
Update solve.py
1 parent fa49d15 commit 1232b79

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

lab8/solve.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import angr
21
import sys
3-
import claripy
2+
import angr
3+
4+
def found_correct(state: angr.SimState):
5+
return b"Correct!" in state.posix.dumps(1)
46

5-
angr.loggers.disable_root_logger()
7+
def avoid_wrong(state: angr.SimState):
8+
return b"Wrong key!" in state.posix.dumps(1)
69

710
def main():
8-
proj = angr.Project("chal", auto_load_libs=False)
9-
flag_bytes = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
10-
flag = claripy.Concat(*flag_bytes)
11+
angr.loggers.disable_root_logger()
1112

12-
state = proj.factory.full_init_state(
13-
stdin = angr.SimFileStream(name='stdin', content=flag, has_end=True)
14-
)
13+
proj = angr.Project("./chal", auto_load_libs=False)
14+
state = proj.factory.entry_state(stdin=angr.SimFile)
1515

16-
simgr = proj.factory.simulation_manager(state)
17-
18-
simgr.explore(find=lambda s: b"flag" in s.posix.dumps(1))
16+
simgr = proj.factory.simgr(state)
17+
simgr.explore(find=found_correct, avoid=avoid_wrong)
1918

20-
if len(simgr.found) > 0:
19+
if simgr.found:
2120
found_state = simgr.found[0]
22-
solution = found_state.solver.eval(flag, cast_to=bytes)
21+
solution = found_state.posix.dumps(0)
2322
sys.stdout.buffer.write(solution)
2423
else:
25-
print("No solution found")
24+
print("No solution found", file=sys.stderr)
25+
exit(1)
2626

27-
if __name__ == '__main__':
27+
if __name__ == "__main__":
2828
main()

0 commit comments

Comments
 (0)