Skip to content

Commit 4565de8

Browse files
authored
Merge pull request #561 from yungen-lu/lab8
[LAB8] 313551077
2 parents ddbe02e + 551c307 commit 4565de8

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

lab8/solve.py

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

3-
import angr,sys
3+
import angr
4+
import claripy
5+
import sys
6+
47

58
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
9+
# Create the project
10+
project = angr.Project("./chal")
11+
12+
# Create a symbolic bitvector for the 8-byte input
13+
input_size = 8
14+
sym_input = claripy.BVS("sym_input", input_size * 8)
15+
16+
# Create an initial state with symbolic stdin
17+
# The program reads from stdin using fgets
18+
initial_state = project.factory.entry_state(stdin=sym_input)
19+
20+
# Create a simulation manager
21+
simgr = project.factory.simulation_manager(initial_state)
22+
23+
simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))
24+
25+
if simgr.found:
26+
found_state = simgr.found[0]
27+
# Retrieve the symbolic stdin content
28+
solution_bytes = found_state.solver.eval(sym_input, cast_to=bytes)
29+
solution = solution_bytes[:input_size] # Ensure it's exactly 8 bytes
30+
else:
31+
print("No solution found!", file=sys.stderr)
32+
solution = b""
33+
34+
sys.stdout.buffer.write(solution)
835

936

10-
if __name__ == '__main__':
37+
if __name__ == "__main__":
1138
main()

0 commit comments

Comments
 (0)