Skip to content

Commit 9545c48

Browse files
committed
finished lab8
1 parent ade2cea commit 9545c48

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

lab8/solve.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,28 @@
33
import angr,sys
44

55
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
6+
project = angr.Project('./chal', auto_load_libs=False)
7+
8+
# Start the analysis at main
9+
state = project.factory.entry_state()
10+
11+
# Create a simulation manager
12+
simgr = project.factory.simulation_manager(state)
13+
14+
# Explore until we reach the "Correct!" message
15+
simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))
16+
17+
# Ensure we found a solution
18+
if simgr.found:
19+
solution_state = simgr.found[0]
20+
21+
# Extract the secret key from stdin
22+
secret_key = solution_state.posix.dumps(0).split(b"\n")[0]
23+
24+
# Output the secret key to stdout
25+
sys.stdout.buffer.write(secret_key + b"\n")
26+
else:
27+
print("Solution not found.")
828

929

1030
if __name__ == '__main__':

0 commit comments

Comments
 (0)