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 sys
4+
5+ import angr
6+ import claripy
7+
8+ PROJECT_PATH = "./chal"
9+
10+
11+ def answer (key ):
12+ sys .stdout .buffer .write (key )
13+
14+
15+ def success (state ):
16+ return b"Correct" in state .posix .dumps (1 )
17+
18+
19+ def failure (state ):
20+ return b"Wrong" in state .posix .dumps (1 )
21+
422
523def main ():
6- secret_key = b""
7- sys .stdout .buffer .write (secret_key )
24+ project = angr .Project (PROJECT_PATH , auto_load_libs = False )
25+
26+ input = claripy .BVS ("input" , 64 ) # 8 bytes
27+
28+ state = project .factory .full_init_state (stdin = input )
29+
30+ for byte in input .chop (8 ):
31+ # answer should be printable ascii, 0x20 ~ 0x7E
32+ state .solver .add (byte >= 0x20 )
33+ state .solver .add (byte <= 0x7E )
34+
35+ simgr = project .factory .simgr (state )
36+
37+ simgr .explore (find = success , avoid = failure )
38+
39+ if simgr .found :
40+ found = simgr .found [0 ]
41+ solution = found .solver .eval (input , cast_to = bytes )
42+ answer (solution )
43+ else :
44+ raise Exception ("AnswerNotFoundError" )
845
946
10- if __name__ == ' __main__' :
47+ if __name__ == " __main__" :
1148 main ()
You can’t perform that action at this time.
0 commit comments