I am presently using a python script to run a c executable like
os.system("./a.out \"%s\" " %p)
There are many binary instruction available to me (i1,i2,i3.... i10 to be exact). I am generating the permutations of these instructions (of length 1,2,3...10) using itertools in python. The string payload p (in snippet above) is one such permutation. I am measuring the time taken for each permutation as follows:
start = time.clock()
os.system("./a.out \"%s\" " %p)
print time.clock() - start
(This may not be best way to measure time. But that is a subject of another question.)
Now for some permutations I get segmentation fault and the python script proceeds to another permutation. But for some permutations, I get no response (like stuck in a infinite loop)like:
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.. )
After I press Ctrl + C, python script goes to next permutation. To put it more clearly
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
Now for longer length of permutation it becomes tedious to press Ctrl C for every bad payload. Is there any way by which I can automate killing/stopping the C program (which I was doing by pressing Ctrl C) which gets stuck due to bad payload and proceed to next permutation?