File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import sys
22import angr
3-
4- def found_correct (state : angr .SimState ):
5- return b"Correct!" in state .posix .dumps (1 )
6-
7- def avoid_wrong (state : angr .SimState ):
8- return b"Wrong key!" in state .posix .dumps (1 )
3+ import claripy
94
105def main ():
11- angr .loggers .disable_root_logger ()
12-
136 proj = angr .Project ("./chal" , auto_load_libs = False )
14- state = proj .factory .entry_state (stdin = angr .SimFile )
7+ flag_bytes = [claripy .BVS (f'flag_{ i } ' , 8 ) for i in range (8 )]
8+ flag = claripy .Concat (* flag_bytes )
9+
10+ state = proj .factory .entry_state (stdin = flag )
1511
1612 simgr = proj .factory .simgr (state )
17- simgr .explore (find = found_correct , avoid = avoid_wrong )
13+ simgr .explore (
14+ find = lambda s : b"Correct!" in s .posix .dumps (1 ),
15+ avoid = lambda s : b"Wrong key!" in s .posix .dumps (1 )
16+ )
1817
1918 if simgr .found :
20- found_state = simgr .found [0 ]
21- solution = found_state . posix . dumps ( 0 )
19+ found = simgr .found [0 ]
20+ solution = found . solver . eval ( flag , cast_to = bytes )
2221 sys .stdout .buffer .write (solution )
2322 else :
24- print ("No solution found" , file = sys .stderr )
25- exit (1 )
23+ print ("No solution found! " , file = sys .stderr )
24+ sys . exit (1 )
2625
27- if __name__ == " __main__" :
26+ if __name__ == ' __main__' :
2827 main ()
You can’t perform that action at this time.
0 commit comments