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
4+ import claripy
45
56def main ():
67 secret_key = b""
7- sys .stdout .buffer .write (secret_key )
8+
9+ proj = angr .Project ('./chal' , auto_load_libs = False )
10+ input_key = [claripy .BVS (f'input_{ i } ' , 8 ) for i in range (8 )]
11+ inputs = claripy .Concat (* input_key )
12+ stdin = angr .SimFileStream (name = 'stdin' , content = inputs , has_end = False ) # avoid error 1
13+ # state = proj.factory.full_init_state(stdin=inputs)
14+ state = proj .factory .full_init_state (stdin = stdin )
15+ state .options .add (angr .options .ZERO_FILL_UNCONSTRAINED_MEMORY ) # avoid error 2
16+ for i in input_key :
17+ state .solver .add (i >= 0x20 )
18+ state .solver .add (i <= 0x7e )
19+
20+ simgr = proj .factory .simgr (state )
21+
22+ def find_function (state ):
23+ return b'Correct! The flag is: CTF{symbolic_execution_for_the_win}' in state .posix .dumps (1 )
24+ def avoid_function (state ):
25+ return b'Wrong key!' in state .posix .dumps (1 )
26+
27+ simgr .explore (find = find_function , avoid = avoid_function )
28+
29+ if simgr .found :
30+ found = simgr .found [0 ]
31+ result = found .solver .eval (inputs , cast_to = bytes )
32+
33+ sys .stdout .buffer .write (result )
834
935
1036if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments