我正在尝试使用angr二进制分析库(http://angr.io/)编写python脚本。我编写了代码,通过使用传递给项目构造函数的ElfCore后端(http://angr.io/api-doc/cle.html#cle.backends.elf.elfcore.ELFCore)成功地加载了我想要使用的进程的核心转储,执行如下操作:
ap = angr.Project("corefile", main_opts={'backend': 'elfcore'})我想知道的是,当我试图使用上面的项目创建一个时,我现在该如何从内核转储定义的状态(寄存器和内存)中“运行”程序:
ss = angr.sim_state.SimState(project=ap)
ss.regs.rip我得到了未初始化的rip (它肯定是在核心转储/生成核心转储时初始化的)。
提前感谢您的帮助!
发布于 2019-11-22 19:23:51
好了!我想出来了。作为一个完全的Angrn00b,这可能不是最好的方法,但是由于没有人提供更好的方法,这就是我想出来的。
首先..。
ap = angr.Project("corefile", main_opts={'backend': 'elfcore'}, rebase_granularity=0x1000)
ss = angr.factory.AngrObjectFactory(ap).blank_state()之所以需要rebase_granularity,是因为我的核心文件将堆栈映射到较高的地址范围,并且angr拒绝映射主二进制文件(本例中是我的核心文件)之上的内容。
通过检查angr源(并在Python终端上播放),我发现在这一点上,上面的状态将全部映射出核心文件定义它的方式,但是寄存器还没有被正确地定义。因此,我需要着手:
# Get the elfcore_object
elfcore_object = None
for o in ap.loader.all_objects:
if type(o) == cle.backends.elf.elfcore.ELFCore:
elfcore_object = o
break
if elfcore_object is None:
error
# Set the reg values from the elfcore_object to the sim state, realizing that not all
# of the registers will be supported (particularly some segment registers)
for regval in elfcore_object.initial_register_values():
try:
setattr(ss.regs, regval[0], regval[1])
except Exception:
warn
# get a simgr
simgr = ap.factory.simgr(ss)现在,我可以使用内核转储定义的状态作为我的起点。
for ins in ap.factory.block(simgr.active[0].addr).capstone.insns:
print(ins)
simgr.step()
...repeathttps://stackoverflow.com/questions/58983441
复制相似问题