Skip to content

Commit 04b26b8

Browse files
committed
tried solving it, still failed using validate script
1 parent aa48f94 commit 04b26b8

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

lab8/solve.py

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

3-
import angr,sys
3+
import angr
4+
import claripy
5+
import sys
46

57
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
8+
project = angr.Project('./chal', auto_load_libs=False)
9+
10+
input_len = 8
11+
input_chars = [claripy.BVS('', 8) for _ in range(input_len)]
12+
sym_input = claripy.Concat(*input_chars)
13+
14+
# Explicitly use SimFileStream with has_end=False
15+
stdin_stream = angr.SimFileStream(name='stdin', content=sym_input, has_end=False)
16+
17+
state = project.factory.full_init_state(stdin=stdin_stream)
18+
19+
20+
for c in input_chars:
21+
state.solver.add(c >= 0x20)
22+
state.solver.add(c <= 0x7e)
23+
24+
simgr = project.factory.simgr(state)
25+
26+
def is_successful(state):
27+
return b"Correct!" in state.posix.dumps(1)
28+
29+
simgr.explore(find=is_successful)
30+
31+
if simgr.found:
32+
found = simgr.found[0]
33+
result = found.solver.eval(sym_input, cast_to=bytes)
34+
sys.stdout.buffer.write(result)
835

936

1037
if __name__ == '__main__':
11-
main()
38+
main()

0 commit comments

Comments
 (0)