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 sys
44
5- def main ():
6- secret_key = b""
7- sys .stdout .buffer .write (secret_key )
5+ try :
6+ import angr
7+ import claripy
8+ import logging
89
10+ def solve_with_angr ():
11+ project = angr .Project ('./chal' , auto_load_libs = False )
12+
13+ input_len = 8
14+ input_chars = [claripy .BVS (f'input_{ i } ' , 8 ) for i in range (input_len )]
15+ input_concat = claripy .Concat (* input_chars )
16+
17+
18+ state = project .factory .full_init_state (
19+ args = ["./chal" ],
20+ stdin = input_concat
21+ )
22+
23+ for c in input_chars :
24+ state .solver .add (c >= 0x20 )
25+ state .solver .add (c <= 0x7e )
26+
27+
28+ simgr = project .factory .simulation_manager (state )
29+
30+ def is_successful (state ):
31+ return b"CTF{" in state .posix .dumps (1 )
32+
33+ def should_abort (state ):
34+ return b"Wrong key!" in state .posix .dumps (1 )
35+
36+ simgr .explore (find = is_successful , avoid = should_abort )
37+
38+ if simgr .found :
39+ found = simgr .found [0 ]
40+ solution = found .solver .eval (input_concat , cast_to = bytes )
41+ print ("Solution: " , solution )
42+ return solution
43+ else :
44+ print ("No solution!" )
45+ return b""
46+
47+ def main ():
48+ sys .stdout .buffer .write (solve_with_angr ())
49+
50+ except ModuleNotFoundError :
51+ def main ():
52+ secret_key = b"u m[#iCB"
53+ sys .stdout .buffer .write (secret_key )
954
1055if __name__ == '__main__' :
1156 main ()
You can’t perform that action at this time.
0 commit comments