Skip to content

Commit b23f47a

Browse files
rootroot
authored andcommitted
lab8-ver1
1 parent 22438de commit b23f47a

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lab8/solve.py

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

33
import angr,sys
4+
import claripy
45

56
def main():
6-
secret_key = b""
7+
# secret_key = b""
8+
# sys.stdout.buffer.write(secret_key)
9+
proj = angr.Project("./chal", auto_load_libs=False)
10+
input_size = 8
11+
sym_input = claripy.BVS("sym_input", 8 * input_size)
12+
13+
state = proj.factory.full_init_state(
14+
args=["./chal"],
15+
stdin=sym_input
16+
)
17+
18+
for i in range(input_size):
19+
byte = sym_input.get_byte(i)
20+
state.solver.add(byte >= 0x20)
21+
state.solver.add(byte <= 0x7e)
22+
23+
simgr = proj.factory.simgr(state)
24+
25+
def is_successful(s):
26+
return b"Correct!" in s.posix.dumps(1)
27+
28+
simgr.explore(find=is_successful)
29+
30+
if simgr.found:
31+
found = simgr.found[0]
32+
secret_key = found.solver.eval(sym_input, cast_to=bytes)
33+
else:
34+
secret_key = b""
35+
736
sys.stdout.buffer.write(secret_key)
837

938

39+
1040
if __name__ == '__main__':
1141
main()

0 commit comments

Comments
 (0)