import angr import sys defsolver(): bin_path = './00_angr_find' proj = angr.Project(bin_path) # load the binary file init_state = proj.factory.entry_state() # create an empty context simgr = proj.factory.simgr(init_state) # create a simulator_manager obj_path_addr = 0x80492F3# the path we'd like to explore simgr.explore(find = obj_path_addr) # start to explore
if simgr.found : solution_state = simgr.found[0] # print the input that solve the constraint print(solution_state.posix.dumps(sys.stdin.fileno()).decode()) else : raise Exception('Could not find the solution') if __name__ == '__main__': solver()
1 2 3 4 5 6 7
ubuntu@ubuntu:~/Desktop/angr_ctf/00_angr_find$ python exp.py ......(一堆warning) XCKLIPYK ubuntu@ubuntu:~/Desktop/angr_ctf/00_angr_find$ vim exp.py ubuntu@ubuntu:~/Desktop/angr_ctf/00_angr_find$ ./00_angr_find Enter the password: XCKLIPYK Good Job.
01 避免路径爆炸
main函数太大ida搞不出来图模式和c代码(第一次见🐖
直接找到提示输入的字符串,然后往下看,发现好多叫avoid me的函数,以及一个may be good 函数,may be good 函数里是一个分支,一边succ,一边try again。
defsolver(): bin_path = './03' proj = angr.Project(bin_path) # blank_state() means creating an empty state and set the current PC to specific addr start_addr = 0x8049502 init_state = proj.factory.blank_state(addr = start_addr)
if simgr.found: solution_state = simgr.found[0] # we use state.solver.eval(BVS) to get the answer value there solution_0 = solution_state.solver.eval(password_0) solution_1 = solution_state.solver.eval(password_1) solution_2 = solution_state.solver.eval(password_2)
print('password_0: {}'.format(hex(solution_0))) print('password_1: {}'.format(hex(solution_1))) print('password_2: {}'.format(hex(solution_2))) else: raise Exception('Could not find the solution!')
if __name__ == "__main__": solver()
1 2 3 4 5 6 7
password_0: 0x1426e459 password_1: 0x864b10e7 password_2: 0x3ea9ca89 ubuntu@ubuntu:~/Desktop/angr_ctf/03_angr_symbolic_registers$ python exp.py ^C ubuntu@ubuntu:~/Desktop/angr_ctf/03_angr_symbolic_registers$ ./03 Enter the password: 0x1426e459 0x864b10e7 0x3ea9ca89 Good Job.
# set the context init_state.regs.ebp = init_state.regs.esp ## first val is on [ebp - 0xC], so we need to `sub esp` so that we can push properly init_state.regs.esp -= 0x8 ## these two variables are continuous on the stack init_state.stack_push(password_0) init_state.stack_push(password_1) ## the relative position of esp when return from scanf() ## seems that it's okay to not do it? init_state.regs.esp -= 12
# now to solve! simgr = proj.factory.simgr(init_state) simgr.explore(find = 0x804943C, avoid = 0x804942A)