Skip to content

Commit b816da8

Browse files
committed
lab8 finish
1 parent 7209ef8 commit b816da8

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

lab8/solve.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,35 @@
11
#!/usr/bin/env python3
2-
3-
import angr,sys
2+
import angr
3+
import claripy
4+
import sys
45

56
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
7+
proj = angr.Project("./chal", auto_load_libs=False)
8+
9+
chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
10+
null = claripy.BVV(0, 8)
11+
input_bytes = claripy.Concat(*chars + [null])
12+
13+
input_stream = angr.SimFileStream(name='stdin', content=input_bytes, has_end=False)
14+
15+
state = proj.factory.full_init_state(
16+
stdin=input_stream,
17+
add_options={angr.options.ZERO_FILL_UNCONSTRAINED_MEMORY}
18+
)
19+
20+
for c in chars:
21+
state.solver.add(c >= 0x20)
22+
state.solver.add(c <= 0x7e)
23+
24+
simgr = proj.factory.simgr(state)
25+
simgr.explore(find=lambda s: b"Correct!" in s.posix.dumps(1))
826

27+
if simgr.found:
28+
found = simgr.found[0]
29+
result = found.solver.eval(claripy.Concat(*chars), cast_to=bytes)
30+
sys.stdout.buffer.write(result)
31+
else:
32+
print("No solution found.")
933

1034
if __name__ == '__main__':
1135
main()

0 commit comments

Comments
 (0)