Skip to content

Commit 515f517

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

1 file changed

Lines changed: 14 additions & 15 deletions

File tree

lab8/solve.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import sys
22
import angr
3-
4-
def found_correct(state: angr.SimState):
5-
return b"Correct!" in state.posix.dumps(1)
6-
7-
def avoid_wrong(state: angr.SimState):
8-
return b"Wrong key!" in state.posix.dumps(1)
3+
import claripy
94

105
def main():
11-
angr.loggers.disable_root_logger()
12-
136
proj = angr.Project("./chal", auto_load_libs=False)
14-
state = proj.factory.entry_state(stdin=angr.SimFile)
7+
flag_bytes = [claripy.BVS(f'flag_{i}', 8) for i in range(8)]
8+
flag = claripy.Concat(*flag_bytes)
9+
10+
state = proj.factory.entry_state(stdin=flag)
1511

1612
simgr = proj.factory.simgr(state)
17-
simgr.explore(find=found_correct, avoid=avoid_wrong)
13+
simgr.explore(
14+
find=lambda s: b"Correct!" in s.posix.dumps(1),
15+
avoid=lambda s: b"Wrong key!" in s.posix.dumps(1)
16+
)
1817

1918
if simgr.found:
20-
found_state = simgr.found[0]
21-
solution = found_state.posix.dumps(0)
19+
found = simgr.found[0]
20+
solution = found.solver.eval(flag, cast_to=bytes)
2221
sys.stdout.buffer.write(solution)
2322
else:
24-
print("No solution found", file=sys.stderr)
25-
exit(1)
23+
print("No solution found!", file=sys.stderr)
24+
sys.exit(1)
2625

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

0 commit comments

Comments
 (0)