中文简介添加链接描述
但是官方github上的pdf文档介绍的更详细。
测试了一下中文简介的内容大概就这些,只是测试加上个人理解,不一定正确不喜勿喷
#coding=utf-8
import angr
b=angr.Project("./level2")
print (hex(b.entry)) #程序的载入地址
print hex(b.loader.min_addr), hex(b.loader.max_addr) #程序的最小
print b.filename #加载项目全名
print b.loader #装载器
print b.loader.shared_objects #装载的库名称和内存用于操作共享库
print
print b.loader.memory[0x8048350] #输出制定内存地址处的值
print b.loader.main_object #二进制对象(输出主二进制模块的开始和结束地址)
print b.loader.find_object_containing(0x8048350) #找到一个内存地址属于哪个函数(也可能是模块)
print b.loader.find_symbol_got_entry('__libc_start_main') #获取指定符号的got表条目
print b.loader.main_object.deps #得到dynmic section的
print b.loader.main_object.memory #是关于主二进制对象的内存内容的dict
print b.loader.shared_objects['libc.so.6'].imports #这是一个装载的libc所需的导入条目的dict
print b.loader.main_object.imports #这是一个主二进制对象所需的导入条目的dict(name->ELFRelocation),其地址通常是0
在github上众多栗子中找了个合适的
#!/usr/bin/env python
'''
ais3_crackme has been developed by Tyler Nighswander (tylerni7) for ais3.
It is an easy crackme challenge. It checks the command line argument.
'''
import angr
import claripy
def main():
project = angr.Project("./ais3_crackme")
#create an initial state with a symbolic bit vector as argv1
argv1 = claripy.BVS("argv1",100*8) #since we do not the length now, we just put 100 bytes
initial_state = project.factory.entry_state(args=["./crackme1",argv1])
#create a path group using the created initial state
sm = project.factory.simulation_manager(initial_state)
#symbolically execute the program until we reach the wanted value of the instruction pointer
sm.explore(find=0x400602) #at this instruction the binary will print(the "correct" message)
found = sm.found[0]
#ask to the symbolic solver to get the value of argv1 in the reached state as a string
solution = found.solver.eval(argv1, cast_to=bytes)
print(repr(solution))
solution = solution[:solution.find(b"\x00")]
print(solution)
return solution
def test():
res = main()
assert res == b"ais3{I_tak3_g00d_n0t3s}"
if __name__ == '__main__':
print(repr(main()))
手动测试了一下,输出了一些内容,加上了一些注解
# coding=utf-8
import angr
import claripy
def main():
project=angr.Project("./ais3_crackme")
argv1=claripy.BVS("angv1",100*8)#打包
print (argv1)
print(hex(project.entry))#显示正常加载的地址,可以验证跟下一句返回值相同
initial_state=project.factory.entry_state(args=["./crackme1",argv1]) #返回一个程序载入地址,是复制了一份原本的程序,但是命令行参数是args
print (initial_state)
sm=project.factory.simulation_manager(initial_state)#用初始化的状态创建一个路径组
sm.explore(find=0x400602)#使用符号执行一直执行知道访问了0x400602地址处的值
print ("sm=",sm)
found=sm.found[0] #一组路径里符合条件(访问了0x400602这个地址的一条路径)
print ("found=",found)
solution=found.solver.eval(argv1,cast_to=bytes)#得到argv1的值类型是byte形式
print (repr(solution))
solution=solution[:solution.find(b"\x00")]
print(repr(solution))
return solution
if __name__=='__main__':
print (repr(main()))
总结:这里的核心是
project.factory.entry_state(args=["./crackme1",argv1]) #路径名并不是真的,是赋值了一份原本程序传进去一些参数。
sm.explore(find=0x400602)符号执行进行大量数据测试直到访问了find的值内存处的内容。