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
4+ import claripy
5+ import sys
46
57def main ():
6- secret_key = b""
7- sys .stdout .buffer .write (secret_key )
8+ # Define the input length and create symbolic variables
9+ input_len = 8
10+ chars = [claripy .BVS (f'char_{ i } ' , 8 ) for i in range (input_len )]
11+ sym_input = claripy .Concat (* chars )
812
13+ # Create initial program state with symbolic stdin
14+ project = angr .Project ("./chal" , auto_load_libs = False )
15+ state = project .factory .full_init_state (
16+ stdin = angr .SimFileStream (name = 'stdin' , content = sym_input , has_end = True )
17+ )
18+
19+ # Constrain characters to be printable ASCII (optional but good practice)
20+ for c in chars :
21+ state .solver .add (c >= 0x20 )
22+ state .solver .add (c <= 0x7e )
23+
24+ # Setup simulation manager
25+ simgr = project .factory .simgr (state )
26+
27+ # Explore only until we see the success message
28+ simgr .explore (find = lambda s : b"Correct!" in s .posix .dumps (1 ),
29+ avoid = lambda s : b"Wrong key!" in s .posix .dumps (1 ))
30+
31+ # Extract solution
32+ if simgr .found :
33+ found = simgr .found [0 ]
34+ result = found .solver .eval (sym_input , cast_to = bytes )
35+ sys .stdout .buffer .write (result + b"\n " )
36+ else :
37+ print ("No solution found" , file = sys .stderr )
38+ sys .exit (1 )
939
1040if __name__ == '__main__' :
1141 main ()
You can’t perform that action at this time.
0 commit comments