Skip to content

Commit 6e0b9a3

Browse files
committed
Add Vulneability column for OWASP .jar file result
1 parent e9a4f79 commit 6e0b9a3

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

src/fosslight_binary/_binary.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,25 @@ def get_comment(self):
3636
return self.comment
3737

3838

39+
class VulnerabilityItem:
40+
file_path = ""
41+
vul_id = ""
42+
nvd_url = ""
43+
44+
def __init__(self, file_path, id, url):
45+
self.file_path = file_path
46+
self.vul_id = id
47+
self.nvd_url = url
48+
49+
3950
class BinaryItem:
4051
bin_name = ""
4152
binary_name_without_path = ""
4253
binary_strip_root = "" # Value of binary name column
4354
tlsh = _TLSH_CHECKSUM_NULL
4455
checksum = _TLSH_CHECKSUM_NULL
4556
oss_items = []
57+
vulnerability_items = []
4658
exclude = False
4759
comment = ""
4860
found_in_db = False
@@ -53,6 +65,7 @@ def __init__(self, value):
5365
self.checksum = _TLSH_CHECKSUM_NULL
5466
self.tlsh = _TLSH_CHECKSUM_NULL
5567
self.oss_items = []
68+
self.vulnerability_items = []
5669
self.binary_name_without_path = ""
5770
self.set_bin_name(value)
5871

@@ -67,6 +80,14 @@ def set_oss_items(self, new_oss_list, exclude_old=False, exclude_msg=""):
6780
# Append New input OSS
6881
self.oss_items.extend(new_oss_list)
6982

83+
def set_vulnerability_items(self, vul_list):
84+
if vul_list is not None:
85+
self.vulnerability_items.extend(vul_list)
86+
87+
def get_vulnerability_items(self):
88+
nvd_url = [vul_item.nvd_url for vul_item in self.vulnerability_items]
89+
return ", ".join(nvd_url)
90+
7091
def set_commnet(self, value):
7192
self.comment = value
7293

@@ -93,8 +114,9 @@ def get_oss_report(self):
93114
if len(self.oss_items) > 0:
94115
for oss in self.oss_items:
95116
exclude = _EXCLUDE_TRUE_VALUE if (self.exclude or oss.exclude) else ""
117+
nvd_url = self.get_vulnerability_items()
96118
print_rows.append([self.binary_strip_root, oss.name, oss.version,
97-
oss.license, oss.dl_url, '', '', exclude, oss.comment])
119+
oss.license, oss.dl_url, '', '', exclude, oss.comment, nvd_url])
98120
else:
99121
exclude = _EXCLUDE_TRUE_VALUE if self.exclude else ""
100122
print_rows.append([self.binary_strip_root, '',

src/fosslight_binary/_jar_analysis.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import subprocess
1010
import fosslight_util.constant as constant
11-
from ._binary import BinaryItem, OssItem
11+
from ._binary import BinaryItem, OssItem, VulnerabilityItem
1212

1313

1414
logger = logging.getLogger(constant.LOGGER_NAME)
@@ -41,7 +41,7 @@ def get_oss_lic_in_jar(data):
4141
return license
4242

4343

44-
def merge_binary_list(owasp_items, bin_list):
44+
def merge_binary_list(owasp_items, vulnerability_items, bin_list):
4545
not_found_bin = []
4646

4747
# key : file_path / value : oss_list for one binary
@@ -50,6 +50,8 @@ def merge_binary_list(owasp_items, bin_list):
5050
for bin in bin_list:
5151
if bin.binary_strip_root == key:
5252
bin.set_oss_items(value, False)
53+
if vulnerability_items is not None:
54+
bin.set_vulnerability_items(vulnerability_items.get(key))
5355
found = True
5456
break
5557

@@ -64,9 +66,36 @@ def merge_binary_list(owasp_items, bin_list):
6466
return bin_list
6567

6668

69+
def get_vulnerability_info(file_with_path, vulnerability, vulnerability_items, remove_vulnerability_items):
70+
if vulnerability is not None:
71+
try:
72+
for vul_info in vulnerability:
73+
vul_id = ""
74+
nvd_url = ""
75+
for key, val in vul_info.items():
76+
if key == 'id':
77+
vul_id = val
78+
elif key == 'url':
79+
nvd_url = val
80+
81+
vul_item = VulnerabilityItem(file_with_path, vul_id, nvd_url)
82+
83+
remove_vulnerability_items = vulnerability_items.get(file_with_path)
84+
if remove_vulnerability_items:
85+
remove_vulnerability_items.append(vul_item)
86+
else:
87+
vulnerability_items[file_with_path] = [vul_item]
88+
except Exception as ex:
89+
logger.info(f"Error to get vul_id and nvd_url: {ex}")
90+
91+
return vulnerability_items
92+
93+
6794
def ananlyze_jar_file(path_to_find_bin):
6895
remove_owasp_item = []
6996
owasp_items = {}
97+
remove_vulnerability_items = []
98+
vulnerability_items = {}
7099

71100
try:
72101
command = f"dependency-check --scan {path_to_find_bin} --out {path_to_find_bin} --disableArchive --disableAssembly --disableRetireJS --disableNodeJS \
@@ -91,6 +120,7 @@ def ananlyze_jar_file(path_to_find_bin):
91120
get_oss_info = False
92121

93122
all_evidence = val.get("evidenceCollected")
123+
vulnerability = val.get("vulnerabilityIds")
94124
vendor_evidences = all_evidence.get('vendorEvidence')
95125
product_evidences = all_evidence.get('productEvidence')
96126
version_evidences = all_evidence.get('versionEvidence')
@@ -133,6 +163,12 @@ def ananlyze_jar_file(path_to_find_bin):
133163
if oss_ver == "" and (product_info['name'] == 'Implementation-Version' or product_info['name'] == 'Bundle-Version'):
134164
oss_ver = product_info['value']
135165

166+
# Get Vulnerability Info.
167+
try:
168+
vulnerability_items = get_vulnerability_info(file_with_path, vulnerability, vulnerability_items, remove_vulnerability_items)
169+
except Exception as ex:
170+
logger.info(f"Error to get vulnerability Info. : {ex}")
171+
136172
if oss_name != "" or oss_ver != "" or oss_license != "" or oss_dl_url != "":
137173
oss = OssItem(oss_name, oss_ver, oss_license, oss_dl_url)
138174
oss.set_comment("OWASP Result. ")
@@ -148,4 +184,4 @@ def ananlyze_jar_file(path_to_find_bin):
148184
except Exception as ex:
149185
logger.warning(f"Error to use dependency-check : {ex}")
150186

151-
return owasp_items
187+
return owasp_items, vulnerability_items

src/fosslight_binary/binary_analysis.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
_root_path = ""
4141
_start_time = ""
4242
windows = False
43+
extended_header = {}
44+
45+
JAR_VUL_HEADER = {'BIN_FL_Binary': ['ID', 'Source Name or Path', 'OSS Name',
46+
'OSS Version', 'License', 'Download Location',
47+
'Homepage', 'Copyright Text', 'Exclude',
48+
'Comment', 'Vulnerability Link']}
4349

4450

4551
def init(path_to_find_bin, output_file_name, format):
@@ -145,9 +151,10 @@ def find_binaries(path_to_find_bin, output_dir, format, dburl=""):
145151
# Run OWASP Dependency-check
146152
if found_jar:
147153
logger.info("Run OWASP Dependency-check to analyze .jar file")
148-
owasp_items = ananlyze_jar_file(path_to_find_bin)
154+
owasp_items, vulnerability_items = ananlyze_jar_file(path_to_find_bin)
149155
if owasp_items:
150-
return_list = merge_binary_list(owasp_items, return_list)
156+
return_list = merge_binary_list(owasp_items, vulnerability_items, return_list)
157+
extended_header = JAR_VUL_HEADER
151158

152159
return_list, db_loaded_cnt = get_oss_info_from_db(return_list, dburl)
153160
return_list = sorted(return_list, key=lambda row: (row.bin_name))
@@ -167,8 +174,7 @@ def find_binaries(path_to_find_bin, output_dir, format, dburl=""):
167174
content_list.extend(scan_item.get_oss_report())
168175
sheet_list["BIN_FL_Binary"] = content_list
169176

170-
success_to_write, writing_msg = write_output_file(result_report, output_extension,
171-
sheet_list)
177+
success_to_write, writing_msg = write_output_file(result_report, output_extension, sheet_list, extended_header)
172178
except Exception as ex:
173179
error_occured(error_msg=str(ex), exit=False)
174180

0 commit comments

Comments
 (0)