forked from vspandan/IFuzzer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGEInterpreterFuzzer.py
108 lines (96 loc) · 3.29 KB
/
GEInterpreterFuzzer.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python
from os import listdir, mkdir, makedirs,remove,stat,kill
from os.path import isfile, join, isdir, exists, abspath
from GECodeGenerator import GECodeGenerator
import sys
import ConfigParser
config = ConfigParser.RawConfigParser()
config.read('ConfigFile.properties')
testsuite=config.get('Testsuite', 'TESTSUITE').split(',')
FILE_TYPE = config.get('Interpreter', 'FILE_TYPE')
LIB_FILE = config.get('Interpreter', 'LIB_FILE')
FILELISTFILE= config.get('TargetDir', 'FILELIST')
ESCAPELIST = config.get('Interpreter', 'ESCAPEFILELIST').split(",")
INCLUDE_NT = config.get('Interpreter', 'SELECTEDNT').split(",")
INCLUDE_NT1 = None
fileList = []
libfiLes=[]
shellfileOption = []
shell=config.get('Interpreter', 'SHELL_PATH').split(',')
options=(config.get('Interpreter', 'SHELL_OPTIONS').split(','))
returnCodes=[]
for code in config.get('Interpreter', 'SHELL_RETURN_CODES').split(','):
returnCodes.append(int(code))
fileOptionSpecifier=config.get('Interpreter', 'SHELL_FILE_SPECIFIER').strip()
"""
Lists all the directories and makes a call to list the files
"""
def listAllTestCases(testCasesDir):
if(isinstance(testCasesDir,list)):
for dir in testCasesDir:
listAllTestCasesDir(dir)
else:
listAllTestCasesDir(testCasesDir)
"""
Lists all the files in a directory
"""
def listAllTestCasesDir(testCaseDir):
for f in listdir(testCaseDir):
fi=join(testCaseDir,f)
if not isfile(fi):
listAllTestCasesDir(fi)
else:
if fi.endswith(FILE_TYPE):
statinfo=stat(abspath(fi))
if statinfo.st_size == 0 or statinfo.st_size >= 10000 :
continue
for escFile in ESCAPELIST:
if fi.endswith(escFile):
continue
fileList.append(abspath(fi))
if fi.endswith(LIB_FILE):
libfiLes.append(abspath(fi))
def run_cmd(fi,l,option,shellNum):
try:
cmd=[]
cmd.append(shell[shellNum].strip())
cmd=cmd+option.split()
if len(shellfileOption)>0:
cmd=cmd+shellfileOption[shellNum]
cmd.append(fi)
p = Popen(cmd, stdout=PIPE,stderr=PIPE)
l[0]=p
out, err = p.communicate()
l[1]=(out,err,p.returncode)
sys.stdout.flush()
sys.stderr.flush()
except Exception as e:
print e
pass
"""
Driver function
"""
if __name__ == "__main__":
args = sys.argv[1:]
sys.setrecursionlimit(300000)
listAllTestCases(testsuite)
g=GECodeGenerator()
# f=open("shell.js","a")
for a in range(len(shell)):
shellfileoption=[]
for shellfile in libfiLes:
# f1=open(shellfile,"r")
# f.write("\n")
# f.write(f1.read());
# f1.close()
shellfileoption.append(shellfile)
if len(fileOptionSpecifier)>0:
shellfileoption.append(fileOptionSpecifier)
shellfileOption.append(shellfileoption)
# f.close()
# raw_input(abspath("shellfull.js"))
if not exists(abspath(FILELISTFILE)):
g.collectFiles(fileList,FILELISTFILE)
if args[0]=="0":
g.genFragPool()
g.runFuzzer(shell,options,returnCodes,INCLUDE_NT,shellfileOption)