我是angr的新手,试图解决一个简单的可执行文件,它读取 3 个字符并与字符串“abc”进行比较。
#include <iostream>
using namespace std;
int main() {
char v[3];
scanf("%3s", v);
if(v[0] == 'a' && v[1] == 'b' && v[2] == 'c') { // should be 'abc'
printf("yes\n");
} else {
printf("no\n");
}
}
angr脚本:
import angr
import claripy
p = angr.Project("/e/c/1/kali/test")
main = p.loader.find_symbol('main')
# Question 1
# flag = claripy.BVS('flag', 3*8)
# or
# flag = claripy.BVS('flag', 4*8)
# Question 2
# flag_chars = [claripy.BVS('flag_%d' % i, 8) for i in range(3)]
# flag = claripy.Concat(*flag_chars + [claripy.BVV(b'\n')])
state = p.factory.blank_state(
addr=main.rebased_addr,
# stdin = flag, # uncomment this line when trying Question 1~3
)
sm = p.factory.simgr(state)
sm.explore(
find = lambda s: b'yes' in s.posix.dumps(1),
avoid = lambda s: b'no' in s.posix.dumps(1)
)
if sm.found:
res = sm.found[0]
print('found', res.posix.dumps(0))
else:
print('not found')
当我没有明确地为bland_state
. 但是当提供“stdin”时它显示“未找到”。