File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
3- import angr ,sys
3+ import angr ,sys , claripy
44
55def main ():
6- secret_key = b""
7- sys .stdout .buffer .write (secret_key )
6+ # secret_key = b""
7+ # sys.stdout.buffer.write(secret_key)
8+ project = angr .Project ('./chal' , auto_load_libs = False )
89
10+ input_len = 8
11+ input_chars = [claripy .BVS (f'input_{ i } ' , 8 ) for i in range (input_len )]
12+ input_concat = claripy .Concat (* input_chars )
13+
14+ state = project .factory .full_init_state (args = ["./chal" ], stdin = input_concat )
15+
16+ for c in input_chars :
17+ state .solver .add (c >= 0x20 )
18+ state .solver .add (c <= 0x7e )
19+
20+
21+ simgr = project .factory .simulation_manager (state )
22+
23+
24+ def is_successful (state ):
25+ return b"Correct!" in state .posix .dumps (1 )
26+
27+ def should_abort (state ):
28+ return b"Wrong key!" in state .posix .dumps (1 )
29+
30+ simgr .explore (find = is_successful , avoid = should_abort )
31+
32+ if simgr .found :
33+ found = simgr .found [0 ]
34+ solution = found .solver .eval (input_concat , cast_to = bytes )
35+ sys .stdout .buffer .write (solution )
36+ else :
37+ print ("No solution found." )
938
1039if __name__ == '__main__' :
1140 main ()
You can’t perform that action at this time.
0 commit comments