Skip to content

Commit ebf716c

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#548 from diffblue/add_support_of_XXE_models_lib_to_Python_driver_script
SEC-633: Updated Python driver script to support XXE models library.
2 parents fea1a5b + beefa49 commit ebf716c

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
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 = (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: 31 additions & 2 deletions
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 "
@@ -139,7 +157,8 @@ def create_parser():
139157
"option the GOTO binary won't be produced and taint analysis is applied directly to "
140158
"the loaded Java program (translated to GOTO in the memory).")
141159
parser.add_argument("--use-models-library", action="store_true",
142-
help="Add the Diffblue Models Library's JAR file to the classpath of the security-scanner.")
160+
help="Add the Diffblue Models Library's JAR file to the classpath of the security-scanner. "
161+
"It will be put in front of the JARs of the analysed web application.")
143162
parser.add_argument("--use-java-runtime-library", action="store_true",
144163
help="Add the Java standard library to the classpath. First, there will be attempt to add "
145164
"OpenJDK version of the library. If it is not found (e.g. not installed), then the "
@@ -148,6 +167,9 @@ def create_parser():
148167
help="Add the Apache Tomcat's JAR files to the classpath of the security-scanner.")
149168
parser.add_argument("--use-spring-framework", action="store_true",
150169
help="Add the Spring Framework's JAR files to the classpath of the security-scanner.")
170+
parser.add_argument("--use-xxe-models-library", action="store_true",
171+
help="Add the Diffblue XXE Models Library's JAR file to the classpath of the security-scanner. "
172+
"It will be put in front of the JARs of the analysed web application.")
151173
parser.add_argument("--data-flow-insensitive-instrumentation", action="store_true",
152174
help="If specified, then the tool 'security-analyser' will use the data-flow insensitive "
153175
"instrumentation of the checked properties into the output GOTO programs. In that case"
@@ -402,7 +424,7 @@ def __main():
402424
print("ERROR: " + common_libraries["diffblue_models_library"]["error"])
403425
return
404426
else:
405-
cmdline.libraries += common_libraries["diffblue_models_library"]["paths"]
427+
cmdline.modelled_libraries += common_libraries["diffblue_models_library"]["paths"]
406428

407429
if cmdline.use_java_runtime_library:
408430
if common_libraries["java_runtime_library"]["error"] is not None:
@@ -425,6 +447,13 @@ def __main():
425447
else:
426448
cmdline.libraries += common_libraries["spring_framework"]["paths"]
427449

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

0 commit comments

Comments
 (0)