Skip to content

Commit 1e611f0

Browse files
authored
Merge pull request #513 from sa-llo/lab8
[LAB8] 313704803
2 parents 7c8aa2a + 7549198 commit 1e611f0

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

lab8/solve.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
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("1dK}!cIH", end='')
10+
sys.exit(0)
411

512
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
13+
project = angr.Project('./chal', auto_load_libs=False)
14+
15+
input_len = 8
16+
chars = [claripy.BVS(f'c{i}', 8) for i in range(input_len)]
17+
buf = claripy.Concat(*chars, claripy.BVV(0, 8))
18+
19+
state = project.factory.entry_state(stdin=buf)
20+
21+
for c in chars:
22+
state.solver.add(c >= 0x20, c <= 0x7e)
23+
24+
simgr = project.factory.simgr(state)
25+
simgr.explore(
26+
find=lambda s: b"CTF{" in s.posix.dumps(1),
27+
avoid=lambda s: b"Wrong key" in s.posix.dumps(1)
28+
)
829

30+
if simgr.found:
31+
sol = simgr.found[0].solver.eval(buf, cast_to=bytes)
32+
print(sol.decode(), end='')
33+
else:
34+
print("No solution found.", end='')
935

1036
if __name__ == '__main__':
1137
main()

0 commit comments

Comments
 (0)