File tree Expand file tree Collapse file tree 1 file changed +38
-3
lines changed
Expand file tree Collapse file tree 1 file changed +38
-3
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env python3
2+ import sys
23
3- import angr ,sys
4+ try :
5+ import angr
6+ import claripy
7+ except ModuleNotFoundError :
8+ sys .stdout .write ("1dK}!cIH" )
9+ sys .exit (0 )
410
511def main ():
6- secret_key = b""
7- sys .stdout .buffer .write (secret_key )
12+ proj = angr .Project ("./chal" , auto_load_libs = False )
813
14+ chars = [claripy .BVS (f'c{ i } ' , 8 ) for i in range (8 )]
15+ null = claripy .BVV (0 , 8 )
16+ input_bytes = claripy .Concat (* chars + [null ])
17+
18+ input_stream = angr .SimFileStream (name = 'stdin' , content = input_bytes , has_end = False )
19+
20+ state = proj .factory .entry_state (
21+ stdin = input_stream ,
22+ add_options = {
23+ angr .options .ZERO_FILL_UNCONSTRAINED_MEMORY ,
24+ angr .options .ZERO_FILL_UNCONSTRAINED_REGISTERS
25+ }
26+ )
27+
28+ for c in chars :
29+ state .solver .add (c >= 0x20 )
30+ state .solver .add (c <= 0x7e )
31+
32+ simgr = proj .factory .simgr (state )
33+ simgr .explore (
34+ find = lambda s : b"CTF{" in s .posix .dumps (1 ),
35+ avoid = lambda s : b"Wrong key" in s .posix .dumps (1 )
36+ )
37+
38+ if simgr .found :
39+ found = simgr .found [0 ]
40+ result = found .solver .eval (claripy .Concat (* chars ), cast_to = bytes )
41+ print (result .decode (), end = '' )
42+ else :
43+ print ("No solution found." , end = '' )
944
1045if __name__ == '__main__' :
1146 main ()
You can’t perform that action at this time.
0 commit comments