Skip to content

Commit 8886979

Browse files
authored
Merge pull request #538 from cfmc30/lab8
[LAB8] 313552023
2 parents e8ae1ce + 714a95f commit 8886979

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

lab8/solve.py

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

3-
import angr,sys
3+
import angr,sys,claripy
4+
5+
def is_successful(state):
6+
stdout = state.posix.dumps(sys.stdout.fileno())
7+
print(stdout)
8+
if b"CTF" in stdout:
9+
return True
10+
return False
11+
12+
def should_abort(state):
13+
stdout = state.posix.dumps(sys.stdout.fileno())
14+
if b"Wrong" in stdout:
15+
return True
16+
return False
17+
418

519
def main():
6-
secret_key = b""
20+
proj = angr.Project("chal", auto_load_libs=False)
21+
22+
23+
# add_options = {
24+
# angr.options.SYMBOL_FILL_UNCONSTRAINED_MEMORY,
25+
# angr.options.SYMBOL_FILL_UNCONSTRAINED_REGISTERS
26+
# }
27+
# )
28+
# inp_ ch = [claripy.BVS('inp_%d', % i, 8) for i in range(9)]
29+
# inp = claripy.Concat(*inp_ch + [charipy.BVV(b'\n')])
30+
# for k in inp_ch:
31+
# state.solver.add(i >= 32)
32+
# state.solver.add(i <= 126)
33+
34+
inp = [claripy.BVS(f'c{i}', 8) for i in range(8)]
35+
sym_input = claripy.Concat(*inp + [claripy.BVV(b'\n')])
36+
37+
state = proj.factory.entry_state(
38+
stdin=sym_input,
39+
add_options = {
40+
angr.options.SYMBOL_FILL_UNCONSTRAINED_MEMORY,
41+
angr.options.SYMBOL_FILL_UNCONSTRAINED_REGISTERS
42+
}
43+
)
44+
45+
for i in inp:
46+
state.solver.add(i >= 32)
47+
state.solver.add(i <= 126)
48+
49+
50+
simgr = proj.factory.simgr()
51+
simgr.explore(find=is_successful, avoid=should_abort)
52+
53+
secret_key = simgr.found[0].posix.dumps(0)
54+
755
sys.stdout.buffer.write(secret_key)
8-
56+
957

1058
if __name__ == '__main__':
1159
main()

0 commit comments

Comments
 (0)