@@ -8,32 +8,27 @@ def main():
88 project = angr .Project ('./chal' , auto_load_libs = False )
99
1010 input_len = 8
11- input_chars = [claripy .BVS ('' , 8 ) for _ in range (input_len )]
12- sym_input = claripy .Concat (* input_chars , claripy .BVV (0 , 8 ))
11+ chars = [claripy .BVS ('' , 8 ) for _ in range (input_len )]
12+ buf = claripy .Concat (* chars , claripy .BVV (0 , 8 )) # Add null terminator!
1313
14- # Explicitly use SimFileStream with has_end=False
15- stdin_stream = angr .SimFileStream (name = 'stdin' , content = sym_input , has_end = False )
14+ state = project .factory .entry_state (stdin = buf )
1615
17- state = project .factory .entry_state (stdin = stdin_stream )
18-
19-
20- for c in input_chars :
21- state .solver .add (c >= 0x20 )
22- state .solver .add (c <= 0x7e )
16+ for c in chars :
17+ state .solver .add (c >= 0x20 )
18+ state .solver .add (c <= 0x7e )
2319
2420 simgr = project .factory .simgr (state )
2521
26- def is_successful ( state ):
27- return b"Correct!" in state .posix .dumps (1 )
28-
29- simgr . explore ( find = is_successful )
22+ simgr . explore (
23+ find = lambda s : b"Correct!" in s .posix .dumps (1 ),
24+ avoid = lambda s : b"Wrong key" in s . posix . dumps ( 1 )
25+ )
3026
3127 if simgr .found :
32- sol = simgr .found [0 ].solver .eval (claripy . Concat ( * input_chars ) , cast_to = bytes )
33- print (sol .decode (), end = '' )
28+ sol = simgr .found [0 ].solver .eval (buf , cast_to = bytes )
29+ print (sol .decode (), end = '' ) # Print cleanly
3430 else :
3531 print ("[-] No solution found." , end = '' )
3632
37-
3833if __name__ == '__main__' :
39- main ()
34+ main ()
0 commit comments