Skip to content

Commit 0d900eb

Browse files
NienTzuNienTzu
authored andcommitted
submit 5th
1 parent acb9b9f commit 0d900eb

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

lab8/solve.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
#!/usr/bin/env python3
2-
32
import sys
43
import angr
54
import claripy
65

76
def solve_with_angr():
87
project = angr.Project('./chal', auto_load_libs=False)
98

10-
input_len = 8
9+
input_len = 9
1110
input_chars = [claripy.BVS(f'input_{i}', 8) for i in range(input_len)]
1211
input_concat = claripy.Concat(*input_chars)
1312

14-
1513
state = project.factory.full_init_state(
1614
args=["./chal"],
1715
stdin=input_concat
1816
)
1917

20-
for c in input_chars:
18+
for c in input_chars[:-1]:
2119
state.solver.add(c >= 0x20)
2220
state.solver.add(c <= 0x7e)
23-
21+
state.solver.add(input_chars[-1] == 0x0a)
2422

2523
simgr = project.factory.simulation_manager(state)
2624

@@ -34,15 +32,10 @@ def should_abort(state):
3432

3533
if simgr.found:
3634
found = simgr.found[0]
37-
solution = found.solver.eval(input_concat, cast_to=bytes)
38-
# print("Solution: ", solution)
39-
return solution
35+
solution = found.solver.eval(claripy.Concat(*input_chars[:-1]), cast_to=bytes)
36+
sys.stdout.buffer.write(solution)
4037
else:
41-
# print("No solution!")
42-
return b""
43-
44-
def main():
45-
sys.stdout.buffer.write(solve_with_angr())
38+
sys.stdout.buffer.write(b"") # fallback or nothing
4639

4740
if __name__ == '__main__':
48-
main()
41+
solve_with_angr()

0 commit comments

Comments
 (0)