我目前使用python脚本来运行AC可执行类似杀死一个C程序由python脚本
os.system("./a.out \"%s\" " %p)
有很多可用的二进制指令,我(I1,I2,I3执行.... I10准确地说)。我使用python中的itertools生成这些指令(长度为1,2,3 ... 10)的排列组合。字符串有效载荷p(在上面的片断中)就是这样一种排列。我测量对各排列的时间如下:(这可能不是来测量时间最好的方法,但是这是另外一个问题一个问题。)
现在对于一些排列我得到分割故障并且python脚本继续到另一个排列。但对于一些置换,我没有得到任何响应(如卡在一个无限循环),如:
58 60 452 547 583 649 756 777 932 965
key Not found
(Nothing happens after this. This is due to bad combination
of instructions or bad payload.
I have to press ctrl C to proceed to next permutation)
^C---------------[9 8 ]------------
The gadget seq is [mov,ret xor eax,eax,ret ] and time taken is
0.000254 (this is the bad permutation of instructions)
(Next permutation..)
我按后按Ctrl + C,Python脚本去下一个排列。更清楚地说明
perm = itertools.permutations(gadget_list,2) #perm is list of all permutations of 2 instructions
for string in list(perm):
#generate the payload p from string which is one of the permutation
#feed it to c program and measure time
start = time.clock()
os.system("./a.out \"%s\" " %p)
print time.clock() - start
现在,对于更长的置换长度,对每个错误的有效载荷按Ctrl C变得单调乏味。有没有什么办法可以自动化杀死/停止C程序(我按Ctrl C),由于有效负载卡住了,并继续进行下一个排列?
那么,我要用上面的代码替换我的os.system()行?我应该在哪里写我的start = time.clock并打印time.clock() - 开始? – shane
'开始'''在Popen行之后,'''end'''在底部 –