Skip to content

Commit de10488

Browse files
authored
Merge pull request #558 from Jimliu29/lab8
[LAB8] 110550078
2 parents 24cbf50 + cdaa3a9 commit de10488

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

lab8/solve.py

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

3-
import angr,sys
3+
import angr, sys
4+
import claripy
45

56
def main():
67
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
8+
9+
proj = angr.Project('./chal', auto_load_libs=False)
10+
input_key = [claripy.BVS(f'input_{i}', 8) for i in range(8)]
11+
inputs = claripy.Concat(*input_key)
12+
stdin = angr.SimFileStream(name='stdin', content=inputs, has_end=False) # avoid error 1
13+
# state = proj.factory.full_init_state(stdin=inputs)
14+
state = proj.factory.full_init_state(stdin=stdin)
15+
state.options.add(angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY) # avoid error 2
16+
for i in input_key:
17+
state.solver.add(i >= 0x20)
18+
state.solver.add(i <= 0x7e)
19+
20+
simgr = proj.factory.simgr(state)
21+
22+
def find_function(state):
23+
return b'Correct! The flag is: CTF{symbolic_execution_for_the_win}' in state.posix.dumps(1)
24+
def avoid_function(state):
25+
return b'Wrong key!' in state.posix.dumps(1)
26+
27+
simgr.explore(find=find_function, avoid=avoid_function)
28+
29+
if simgr.found:
30+
found = simgr.found[0]
31+
result = found.solver.eval(inputs, cast_to=bytes)
32+
33+
sys.stdout.buffer.write(result)
834

935

1036
if __name__ == '__main__':

0 commit comments

Comments
 (0)