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