Skip to content

Commit 70619d0

Browse files
committed
Updated Python driver script to support XXE models library.
1 parent f7f8aa5 commit 70619d0

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

driver/mkbench.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,22 @@ def collect_java_binaries(cmdline):
102102
else:
103103
java_libraries.classpath_jar_files.append(path)
104104

105+
modelled_library_directories = []
106+
modelled_java_libraries = CollectedJavaBinaries()
107+
for path in cmdline.modelled_libraries:
108+
if os.path.isdir(path):
109+
_find_java_binaries(path, modelled_java_libraries)
110+
modelled_library_directories.append(path)
111+
else:
112+
modelled_java_libraries.classpath_jar_files.append(path)
113+
105114
prof["num_classes"] = len(java_binaries.class_files)
106-
prof["num_classpath_jar_files"] = len(java_binaries.classpath_jar_files) + len(java_libraries.classpath_jar_files)
107-
prof["num_classpath_directories"] = len(library_directories)
115+
prof["num_classpath_jar_files"] = (
116+
len(java_binaries.classpath_jar_files) +
117+
len(java_libraries.classpath_jar_files) +
118+
len(modelled_java_libraries.classpath_jar_files)
119+
)
120+
prof["num_classpath_directories"] = len(library_directories) + len(modelled_library_directories)
108121

109122
# First we read packages of all collected class files.
110123
classes_info, java_class_info_call_duration = _read_info_of_class_files(
@@ -151,7 +164,11 @@ def collect_java_binaries(cmdline):
151164
copied_command_line = {key.replace("_", "-"): val for key, val in vars(cmdline).items()}
152165

153166
# Loop over all our detected entry points and create a folder for each.
154-
class_paths = [p for p in java_binaries.classpath_jar_files + java_libraries.classpath_jar_files + library_directories]
167+
class_paths = [p for p in (modelled_java_libraries.classpath_jar_files +
168+
modelled_library_directories +
169+
java_binaries.classpath_jar_files +
170+
java_libraries.classpath_jar_files +
171+
library_directories)]
155172
for ep_data in ep_config["entryPoints"]:
156173

157174
method_data = ep_data["method"]

driver/run.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,24 @@ def get_spring_framework_props():
6969
props["spring_framework"]["error"] = "Cannot access Spring Framework's directory " + directory
7070
return props
7171

72+
def get_javax_xxe_library_props():
73+
props = {"javax_xxe_library": {
74+
"paths": [
75+
os.path.join(get_benchmark_library_dir(), "javax_xxe_library", "target", "javax_xxe_models.jar")
76+
],
77+
"error": None
78+
}}
79+
for jar in props["javax_xxe_library"]["paths"]:
80+
if not os.path.isfile(jar):
81+
props["javax_xxe_library"]["error"] = "Cannot find '" + os.path.basename(jar) + "' in the directory " + os.path.dirname(jar)
82+
return props
83+
7284
result = {}
7385
result.update(get_diffblue_models_library_props())
7486
result.update(get_java_runtime_library())
7587
result.update(get_apache_tomcat_props())
7688
result.update(get_spring_framework_props())
89+
result.update(get_javax_xxe_library_props())
7790
return result
7891

7992

@@ -92,6 +105,11 @@ def create_parser():
92105
parser.add_argument("-L", "--libraries", nargs='+', default=[],
93106
help="A list of disk paths to libraries you want to include into class path. A path "
94107
"can either be a path-name of a JAR file, or a directory.")
108+
parser.add_argument("-M", "--modelled-libraries", nargs='+', default=[],
109+
help="A list of disk paths to models of libraries you want to include into class path. A path "
110+
"can either be a path-name of a JAR file, or a directory. The paths will be put to the "
111+
"classpath BEFORE JAR files of the analysed web application and also libraries passed "
112+
"via the option --libraries.")
95113
parser.add_argument("-E", "--entry-point", "--entry-points", nargs='+', default=[],
96114
help="Allows you to specify a list of Java functions which will be considered by the analyser as an "
97115
"entry point. Typically, a function of a class implementing javax.servlet.http.HttpServlet "
@@ -148,6 +166,9 @@ def create_parser():
148166
help="Add the Apache Tomcat's JAR files to the classpath of the security-scanner.")
149167
parser.add_argument("--use-spring-framework", action="store_true",
150168
help="Add the Spring Framework's JAR files to the classpath of the security-scanner.")
169+
parser.add_argument("--use-xxe-models-library", action="store_true",
170+
help="Add the Diffblue XXE Models Library's JAR file to the classpath of the security-scanner. "
171+
"It will be put in front of the JARs of the analysed web application.")
151172
parser.add_argument("--data-flow-insensitive-instrumentation", action="store_true",
152173
help="If specified, then the tool 'security-analyser' will use the data-flow insensitive "
153174
"instrumentation of the checked properties into the output GOTO programs. In that case"
@@ -402,7 +423,7 @@ def __main():
402423
print("ERROR: " + common_libraries["diffblue_models_library"]["error"])
403424
return
404425
else:
405-
cmdline.libraries += common_libraries["diffblue_models_library"]["paths"]
426+
cmdline.modelled_libraries += common_libraries["diffblue_models_library"]["paths"]
406427

407428
if cmdline.use_java_runtime_library:
408429
if common_libraries["java_runtime_library"]["error"] is not None:
@@ -425,6 +446,13 @@ def __main():
425446
else:
426447
cmdline.libraries += common_libraries["spring_framework"]["paths"]
427448

449+
if cmdline.use_xxe_models_library:
450+
if common_libraries["javax_xxe_library"]["error"] is not None:
451+
print("ERROR: " + common_libraries["javax_xxe_library"]["error"])
452+
return
453+
else:
454+
cmdline.modelled_libraries += common_libraries["javax_xxe_library"]["paths"]
455+
428456
cmdline.config = os.path.abspath(cmdline.config)
429457
cmdline.input_path = os.path.abspath(cmdline.input_path)
430458
cmdline.results_dir = os.path.abspath(cmdline.results_dir)

0 commit comments

Comments
 (0)