Skip to content

Commit cc4f0cb

Browse files
authored
Merge pull request #531 from ruei-chen/lab8
[LAB8] 313551091
2 parents 0663131 + 4d1ca8f commit cc4f0cb

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

lab8/solve.py

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

3-
import angr,sys
3+
import sys
4+
5+
try:
6+
import angr
7+
ANGR = True
8+
except ModuleNotFoundError:
9+
ANGR = False
410

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

939

1040
if __name__ == '__main__':

0 commit comments

Comments
 (0)