-
Notifications
You must be signed in to change notification settings - Fork 5
/
aisa-set-settings.py
301 lines (261 loc) · 10.1 KB
/
aisa-set-settings.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) DevOpsHQ, 2021
import sys
import os
import re
import argparse
import platform
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--projectname",
action="store",
help="The name of project",
required=True)
parser.add_argument("--language",
action="store",
help="Programming language to find in project",
required=True)
parser.add_argument("--path",
action="store",
help="Path to project for scan",
default="./",
required=False)
parser.add_argument("--exclude-formats",
action="store",
help="Whether to exclude non-sources files from scanning (True or False)",
default="True",
required=False)
parser.add_argument("--excluded-paths",
action="store",
nargs="+",
help="Exclude certain files and folders from scan. "
"Use single \\ with apostrophes and double \\ with quotes "
"(e.g. '\\devops-tools' "
'"\\\\.git\\\\")',
required=False)
arguments = parser.parse_args()
return arguments
def check_platform(os_type):
if os_type == 'Windows':
return "Windows"
else:
return "Linux"
def check_args(projectname, language, languages, path_to_folder):
if "{projectname}.aiproj".format(**locals()) in os.listdir("."):
print("-" * 50)
print("[WARNING]: File {projectname}.aiproj exists".format(**locals()))
print(" Try to overwrite")
print("-" * 50)
if language in map(lambda x: x.lower(), languages):
print("[INFO]: Arguments is correct")
else:
sys.stderr.write("[ERROR]: Unknown language\n")
sys.exit(1)
def create_json(projectname, language, exclude_formats, excluded_paths_list):
config = r'''{
"ProjectName": "$ProjectName",
"ProgrammingLanguage": "$LANG",
"ScanAppType": "Configuration, Fingerprint, PmTaint, DependencyCheck, $COND",
"ThreadCount": 2,
"Site": "http://localhost",
"IsDownloadDependencies": true,
"IsUsePublicAnalysisMethod": true,
"IsUseEntryAnalysisPoint": true,
"ScanUnitTimeout": 360,
"PreprocessingTimeout": 60,
"CustomParameters": $CUSTOM,
"SkipFileFormats": $EXCLUDED_FILE_FORMATS,
"SkipFilesFolders": ["\\devops-tools", "\\.git\\", "\\.gitignore", "\\.gitmodules", "\\.gitattributes", "\\$tf\\", "\\$BuildProcessTemplate\\", "\\.tfignore"$EXCLUDED_FILES_FOLDERS],
"DisabledPatterns": ["145", "146", "148", "149"],
"DisabledTypes": [],
"UseIncrementalScan": true,
"FullRescanOnNewFilesAdded": true,
"ConsiderPreviousScan": true,
"HideSuspectedVulnerabilities": false,
"UseIssueTrackerIntegration": false,
"IsUnpackUserPackages": false,
"JavaParameters": null,
"JavaVersion": 0,
"UseJavaNormalizeVersionPattern": "true",
"JavaNormalizeVersionPattern": "-\\d+(\\.\\d+)*",
"JavaScriptProjectFile": null,
"JavaScriptProjectFolder": null,
"UseTaintAnalysis": true,
"UsePmAnalysis": true,
"DisableInterpretCores": false,
"UseDefaultFingerprints": true,
"UseCustomYaraRules": false,
"CustomHeaders": [["", ""]],
"Authentication": {
"auth_item": {
"domain": null,
"credentials": {
"cookie": null,
"type": 2,
"login": {
"name": null,
"value": null,
"regexp": null,
"is_regexp": false
},
"password": {
"name": null,
"value": null,
"regexp": null,
"is_regexp": false
}
},
"test_url": null,
"form_url": null,
"form_xpath": ".//form",
"regexp_of_success": null
}
},
"ProxySettings": {
"IsEnabled": false,
"Host": null,
"Port": null,
"Type": 0,
"Username": null,
"Password": null
},
"RunAutocheckAfterScan": false,
"AutocheckSite": "http://localhost",
"AutocheckCustomHeaders": [["", ""]],
"AutocheckAuthentication": {
"auth_item": {
"domain": null,
"credentials": {
"cookie": null,
"cookies": null,
"type": 2,
"login": {
"name": null,
"value": null,
"regexp": null,
"is_regexp": false
},
"password": {
"name": null,
"value": null,
"regexp": null,
"is_regexp": false
}
},
"test_url": null,
"form_url": null,
"form_xpath": ".//form",
"regexp_of_success": null
}
},
"AutocheckProxySettings": {
"IsEnabled": false,
"Host": null,
"Port": null,
"Type": 0,
"Username": null,
"Password": null
},
"SendEmailWithReportsAfterScan": false,
"CompressReport": false,
"EmailSettings": null,
"ReportParameters": {
"SaveAsPath": null,
"UseElectronicSignature": false,
"CertificatePath": null,
"Password": null,
"ShowSignatureTime": false,
"SignatureReason": null,
"Location": null,
"DoSignatureVisible": false,
"IncludeDiscardedVulnerabilities": false,
"IncludeSuppressedVulnerabilities": true,
"IncludeSuspectedVulnerabilities": false,
"IncludeGlossary": false,
"ConverHtmlToPdf": false,
"RemoveHtml": false,
"CreatePdfPrintVersion": false,
"MakeAFReport": false,
"IncludeDFD": false
}
}
''' # noqa
json = re.sub(r"\$ProjectName", projectname, config, 1)
json = re.sub(r"\$LANG", language, json, 1)
if language == "php":
json = re.sub(r", \$COND", ", Php", json, 1)
elif language == "java":
json = re.sub(r", \$COND", ", Java", json, 1)
elif language == "javascript":
json = re.sub(r", \$COND", ", JavaScript", json, 1)
elif language == "csharp" or language == "vb":
json = re.sub(r", \$COND", ", CSharp", json, 1)
else:
json = re.sub(r", \$COND", "", json, 1)
if language == "python":
json = re.sub(r"\$CUSTOM", r'"--multifile"', json, 1)
else:
json = re.sub(r"\$CUSTOM", "null", json, 1)
excluded_formats_list = '["*.7z", "*.bmp", "*.dib", "*.dll", "*.doc", "*.docx", "*.exe", "*.gif", "*.ico", ' \
'"*.jfif", "*.jpe", "*.jpe6", "*.jpeg", "*.jpg", "*.odt", "*.pdb", "*.pdf", "*.png", ' \
'"*.rar", "*.swf", "*.tif", "*.tiff", "*.zip"]'
try:
print("[INFO]: Exclude non-source files from scanning: {exclude_formats}".format(**locals()))
if exclude_formats in ('FALSE', 'False', 'false'):
json = re.sub(r"\$EXCLUDED_FILE_FORMATS", "null", json, 1)
elif exclude_formats in ('TRUE', 'True', 'true'):
json = re.sub(r"\$EXCLUDED_FILE_FORMATS", excluded_formats_list, json, 1)
else:
raise ValueError()
except (ValueError, Exception):
print('[WARNING]: You have specified an invalid value. Used "True" as the default.')
json = re.sub(r"\$EXCLUDED_FILE_FORMATS", excluded_formats_list, json, 1)
try:
print("[INFO]: Excluded files and folders list: {excluded_paths_list}".format(**locals()))
if excluded_paths_list is not None:
excluded_paths_string = ''
for excluded_item in excluded_paths_list:
# Take raw value and remove apostrophes
prepared_excluded_item = repr(excluded_item).replace("'", "")
excluded_paths_string = excluded_paths_string + r', "{prepared_excluded_item}"'.format(**locals())
json = json.replace("$EXCLUDED_FILES_FOLDERS", excluded_paths_string, 1)
else:
json = json.replace("$EXCLUDED_FILES_FOLDERS", '', 1)
except (ValueError, Exception):
print('[WARNING]: Something went wrong! The default values are used.')
json = json.replace("$EXCLUDED_FILES_FOLDERS", '', 1)
return json
def print_info(projectname, language, path_to_file):
if path_to_file == '':
folder = './'
print("-" * 50)
print("[INFO]: Project name: {projectname}".format(**locals()))
print("[INFO]: File name: {projectname}.aiproj".format(**locals()))
print("[INFO]: Language: {language}".format(**locals()))
print("[INFO]: Path: {path_to_file}".format(**locals()))
print("-" * 50)
def main(prj, lang, path, exclude_formats, excluded_paths_list):
# ---------- Variables ----------
lang = lang.lower()
langs = ["java", "php", "csharp", "vb", "objectivec", "cplusplus", "sql", "swift", "python", "javascript", "go",
"kotlin"]
os_type = platform.system()
# ------------- Run -------------
check_args(prj, lang, langs, path)
json_file = create_json(prj, lang, exclude_formats, excluded_paths_list)
print_info(prj, lang, path)
proj = open("{prj}.aiproj".format(**locals()), "w")
proj.write(json_file)
proj.close()
print("[INFO]: File {proj.name} was generated successfully".format(**locals()))
if __name__ == '__main__':
print("[INFO]: Start generating project")
args = parse_args()
main(
prj=args.projectname, # Project name
lang=args.language, # Language
path=args.path, # Path to folder
exclude_formats=args.exclude_formats, # Exclusion non-sources files from scanning (on/off)
excluded_paths_list=args.excluded_paths # Exclusion paths from scanning
)