Skip to content

Commit a49a90f

Browse files
NienTzuNienTzu
authored andcommitted
submit lab8
1 parent 42b748a commit a49a90f

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

lab8/solve.py

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

3-
import angr,sys
3+
import angr,sys,claripy
44

55
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
6+
# secret_key = b""
7+
# sys.stdout.buffer.write(secret_key)
8+
project = angr.Project('./chal', auto_load_libs=False)
89

10+
input_len = 8
11+
input_chars = [claripy.BVS(f'input_{i}', 8) for i in range(input_len)]
12+
input_concat = claripy.Concat(*input_chars)
13+
14+
state = project.factory.full_init_state(args=["./chal"], stdin=input_concat)
15+
16+
for c in input_chars:
17+
state.solver.add(c >= 0x20)
18+
state.solver.add(c <= 0x7e)
19+
20+
21+
simgr = project.factory.simulation_manager(state)
22+
23+
24+
def is_successful(state):
25+
return b"Correct!" in state.posix.dumps(1)
26+
27+
def should_abort(state):
28+
return b"Wrong key!" in state.posix.dumps(1)
29+
30+
simgr.explore(find=is_successful, avoid=should_abort)
31+
32+
if simgr.found:
33+
found = simgr.found[0]
34+
solution = found.solver.eval(input_concat, cast_to=bytes)
35+
sys.stdout.buffer.write(solution)
36+
else:
37+
print("No solution found.")
938

1039
if __name__ == '__main__':
1140
main()

0 commit comments

Comments
 (0)