安装使用Angr符号执行来求解CTF逆向题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xiangshangbashaonian/article/details/82825488

angr是什么   我的理解就是  可以用它来帮我们从众多的路中找到最正确的那条(太复杂的话就不行了 执行效率是个问题)

类似与z3来解方程似的(不清楚的话可以看这个怎样在win10上安装并食用Z3库来解CTF方程)

angr 安装与简单使用请看https://blog.csdn.net/whym1/article/details/78838026

下面有两道CTF逆向题   

0x01:交互式输入

0x02:输入作为参数运行

先占个坑   以后慢慢分析

0x01:

可以先file一下看看  看到是ELF  x64

再载入IDA x64 

In [2]: import angr
WARNING | 2018-09-23 23:00:21,741 | angr.analyses.disassembly_utils | Your version of capstone does not support MIPS instruction groups.

In [3]: proj = angr.Project("./r100",auto_load_libs=False) #貌似这个只能在根目录下  要不然最后无法输出

In [4]: state = proj.factory.entry_state() #这个我理解的就是保存入口状态

In [5]: simgr = proj.factory.simgr(state) 

In [6]: simgr.explore(find=0x400844,avoid=0x400855) #find就是正确的那条路 avoid错误的
Out[6]: <SimulationManager with 1 found, 2 active, 12 avoid> #找到了一条路径

In [7]: simgr.found[0].posix.dumps(0) #Code_Talkers就是flag
Out[7]: 'Code_Talkers\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\xf5\x00'

这道题目的正常做法可以看看这个

【WhaleCTF逆向题】第二期入门语言【初级】writeup

0x02:

可以先file一下看看  看到是ELF  x64

再载入IDA x64 

(angr) root@kali:/# python
Python 2.7.15+ (default, Aug 31 2018, 11:56:52) 
[GCC 8.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import angr   #导入angr
WARNING | 2018-09-24 02:00:03,499 | angr.analyses.disassembly_utils | Your version of capstone does not support MIPS instruction groups.
>>> import claripy    #导入claripy
>>> proj = angr.Project("./ais3_crackme")    #载入文件
>>> argv1 = claripy.BVS('argv1',50*8)    #B是bit 1字节=8bit  猜测输入不多于50字节 就是50*8
>>> state = proj.factory.entry_state(args=['./ais3_crackme',argv1])
>>> simgr = proj.factory.simgr(state)
>>> simgr.explore(find=0x400602,avoid=0x40060E)    #成功位置及失败位置
<SimulationManager with 1 found, 4 active, 46 avoid>
>>> print simgr.found[0].solver.eval(argv1)    #转成ascll码输出
982585559591575985374705575567592960052976734226750479530958626821257185859104971082646494321404975234050832525462339584
>>> print simgr.found[0].solver.eval(argv1,cast_to=str)    #直接输出字符
ais3{I_tak3_g00d_n0t3s}
>>> 

可以看看:http://www.freebuf.com/sectool/143056.html

http://www.360doc.com/content/18/0307/21/31784658_735232878.shtml

猜你喜欢

转载自blog.csdn.net/xiangshangbashaonian/article/details/82825488