File tree Expand file tree Collapse file tree 1 file changed +37
-3
lines changed
Expand file tree Collapse file tree 1 file changed +37
-3
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
22
3- import angr ,sys
3+ import sys
4+
5+ try :
6+ import angr , claripy
7+ except :
8+ print ("fallback" , end = '' )
9+ sys .exit (0 )
10+
411
512def main ():
6- secret_key = b""
7- sys .stdout .buffer .write (secret_key )
13+ project = angr .Project ('./chal' , auto_load_libs = False )
14+
15+ # Create 8 symbolic bytes
16+ sym_input = claripy .BVS ('sym_input' , 8 * 8 )
17+ state = project .factory .full_init_state (stdin = sym_input )
18+
19+ for b in sym_input .chop (8 ):
20+ state .solver .add (b >= 0x20 )
21+ state .solver .add (b <= 0x7e )
22+
23+ sm = project .factory .simgr (state )
24+
25+ #check if the output has a successful msg
26+ def is_good (state ):
27+ return b"Correct" in state .posix .dumps (1 )
28+
29+ #avoid the wrong output
30+ def is_bad (state ):
31+ return b"Wrong key" in state .posix .dumps (1 )
32+
33+ sm .explore (find = is_good , avoid = is_bad )
34+
35+ if sm .found :
36+ final_state = sm .found [0 ]
37+ answer = final_state .solver .eval (sym_input , cast_to = bytes )
38+ sys .stdout .buffer .write (answer [:8 ]) # trim just in case
39+ else :
40+ # else fallback if no solution is found
41+ sys .stdout .buffer .write (b"NO_SOLUTION" )
842
943
1044if __name__ == '__main__' :
You can’t perform that action at this time.
0 commit comments