angr对输入进行限制

Author Avatar
Xzhah 7月 08, 2017
  • 在其它设备中阅读本文章

##angr对输入加以限制。

*如果是对gets(),read()之类输入的字符串。

这里参考官方例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
p = angr.Project('wyvern')

st = p.factory.full_init_state(args=['./wyvern'])

# Constrain the first 28 bytes to be non-null and non-newline:
for _ in xrange(28):
k = st.posix.files[0].read_from(1)
st.se.add(k != 0)
st.se.add(k != 10)

# Constrain the last byte to be a newline
k = st.posix.files[0].read_from(1)
st.se.add(k == 10)

# Reset the symbolic stdin's properties and set its length.
st.posix.files[0].seek(0)
st.posix.files[0].length = 29

*如果是对命令行参数输入加以限制。

自己写了一个小程序来验证。
angr脚本如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import angr



import simuvex



input_size = 21

argv1 = angr.claripy.BVS('flag', 8 * input_size)



proj = angr.Project('./a.out', load_options={'auto_load_libs': False})

state = proj.factory.entry_state(args=["./a.out", argv1], add_options={simuvex.o.LAZY_SOLVES})

state.libc.buf_symbolic_bytes=input_size + 1

for byte in argv1.chop(8):



state.add_constraints(byte != '\x00')



state.add_constraints(byte >= ' ')



state.add_constraints(byte <= '~')

state.add_constraints(argv1.chop(8)[0] == 'f')

state.add_constraints(argv1.chop(8)[1] == 'l')

state.add_constraints(argv1.chop(8)[2] == 'a')

state.add_constraints(argv1.chop(8)[3] == 'g')

state.add_constraints(argv1.chop(8)[4] == '{')

path = proj.factory.path(state)

pg = proj.factory.path_group(state)



pg.explore(find=(0x400629,), avoid=(0x400635,))

f = pg.found[0]



print f.state.se.any_str(argv1)

结果如下