File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
2-
32import sys
43import angr
54import claripy
65
76def 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
4740if __name__ == '__main__' :
48- main ()
41+ solve_with_angr ()
You can’t perform that action at this time.
0 commit comments