如何将字符串输入添加到Angr程序的开头?

2024-09-22 16:23:28 发布

您现在位置:Python中文网/ 问答频道 /正文

很抱歉,这个问题很可能没有意义。我刚接触Angr,遇到了一个小问题。假设我有一个二进制程序“mybinary”,我在其中输入一些东西,它会进行一些操作,并根据这些操作进行检查,以找到一个标志。(正常的crackme风格。)

但是,程序第一次运行时需要一个字符串tid输入。我有tid,它只是一个32位的字母和数字字符串

因此,为了运行它,我必须执行“/mybinary‘tid字符串’”,而不是“/mybinary”

在将文件加载到Angr项目中的上下文中,我如何做到这一点

比如,如果我的angr代码是这样的:

import angr
import claripy

#Whatever variables.

base_addr = #Whatever the base address is.

proj = angr.Project("./mybinary", main_opts={'base_addr': base_addr}) 

#Some code for defining flag characters.

state = proj.factory.full_init_state(
        args=['./mybinary'],
        add_options=angr.options.unicorn,
    stdin=flag,
)

#Some code to create and run simulation with success and failure.

我如何编辑它,使其运行“/mybinary”而不是“/mybinary”

谢谢你的帮助


Tags: 字符串import程序basecodesomeflagaddr
1条回答
网友
1楼 · 发布于 2024-09-22 16:23:28

以下是您应该如何实例化状态以满足您的需要:

state = proj.factory.entry_state(
    args=['./mybinary', 'the tid string'],
    add_options=angr.options.unicorn,
    stdin=flag,
)

根据documentation的规定:

If you're executing in an environment that can take command line arguments or an environment, you can pass a list of arguments through args and a dictionary of environment variables through env into entry_state and full_init_state.

此外,在您的案例中似乎不需要full_init_stateentry_state应该足够(same documentation):

.entry_state() constructs a state ready to execute at the main binary's entry point.

相关问题 更多 >