Skip to content

Commit 46035ee

Browse files
authored
Merge pull request #500 from nizw0/lab8
[LAB8] 313551022
2 parents 527eb61 + 055cf58 commit 46035ee

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

lab8/solve.py

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

3-
import angr,sys
3+
import sys
4+
5+
try:
6+
import angr
7+
import claripy
8+
except ImportError:
9+
print('w"l\\!cIH', end="")
10+
sys.exit(0)
11+
12+
PROJECT_PATH = "./chal"
13+
14+
15+
def answer(key):
16+
sys.stdout.buffer.write(key)
17+
18+
19+
def success(state):
20+
return b"Correct" in state.posix.dumps(1)
21+
22+
23+
def failure(state):
24+
return b"Wrong" in state.posix.dumps(1)
25+
426

527
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
28+
project = angr.Project(PROJECT_PATH, auto_load_libs=False)
29+
30+
input = claripy.BVS("input", 64) # 8 bytes
31+
32+
state = project.factory.full_init_state(stdin=input)
33+
34+
for byte in input.chop(8):
35+
# answer should be printable ascii, 0x20 ~ 0x7E
36+
state.solver.add(byte >= 0x20)
37+
state.solver.add(byte <= 0x7E)
38+
39+
simgr = project.factory.simgr(state)
40+
41+
simgr.explore(find=success, avoid=failure)
42+
43+
if simgr.found:
44+
found = simgr.found[0]
45+
solution = found.solver.eval(input, cast_to=bytes)
46+
answer(solution)
47+
else:
48+
raise Exception("AnswerNotFoundError")
849

950

10-
if __name__ == '__main__':
51+
if __name__ == "__main__":
1152
main()

0 commit comments

Comments
 (0)