前言
听说了angr这个神器,能帮我省下很多写简单题目的力气,所以打算好好学习一下
00_angr_find
最基础的题目,输入flag,简单加密然后判断。
project=angr.Project(path)#创建项目
initial_state=project.factory.entry_state()#设置入口点
simulation=project.factory.simgr(initial_state)#设置模拟器
simulation.explore(find=good_add)#设置目标地址
solution_state=simulation.found[0]
print(solution_state.posix.dump(sys.stdin.fileno()))#输出符号向量
这一题就是介绍angr最基础的使用方法
01_angr_avoid
这个题里面有太多分支,IDA反编译不出来,但是可以发现中间进入了好多的avoid_me函数
并且该函数里会把should_succeed变为0,也就是说一旦进入这个函数,flag就是错误的,所以可以用angr设置avoid,这样在进入这个函数以后,就不用运行完整个程序,可以大大加快angr运行的速度。
simulation.explore(find=print_good_addr,avoid=0x080485A8)
这一题简单介绍了avoid的功能
02_angr_find_condition
通过IDA可以发现有好几个地方都输出了goodjob,同时也有好几个地方输出了错误提示
不仔细分析情况下难以判断哪个是正确的输出地址,甚至有可能都有关联
所以可以通过判断输出内容检验是否是正确的flag
def good_job(state):
stdout_output = state.posix.dumps(sys.stdout.fileno())
return 'Good Job' in str(stdout_output)
def try_again(state):
stdout_output = state.posix.dumps(sys.stdout.fileno())
return 'Try again' in str(stdout_output)
simulation.explore(find=good_job,avoid=try_again)
通过判断输出内容而不是直接寻找地址,也能够使用angr破解
03_angr_symbolic_registers
这个题目总共有三个输入,然后输入完后会储存到eax,ebx,ecx里
所以需要对寄存器进行符号化
psd0 = claripy.BVS('psd0', 32)
psd1 = claripy.BVS('psd1', 32)
psd2 = claripy.BVS('psd2', 32)
initial_state.regs.eax = psd0
initial_state.regs.ebx = psd1
initial_state.regs.edx = psd2
simulation = project.factory.simgr(initial_state)
注意输出时也需要输出符号
solution0 = solution_state.se.eval(psd0)
solution1 = solution_state.se.eval(psd1)
solution2 = solution_state.se.eval(psd2)
solution = '%x %x %x' % (solution0, solution1, solution2)