fosslight-binary 4.1.33__tar.gz → 5.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/PKG-INFO +1 -1
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/requirements.txt +1 -1
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/setup.py +1 -1
- fosslight_binary-5.1.0/src/fosslight_binary/_binary.py +101 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary/_binary_dao.py +5 -4
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary/_jar_analysis.py +7 -6
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary/binary_analysis.py +84 -42
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary/cli.py +1 -1
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/PKG-INFO +1 -1
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/requires.txt +1 -1
- fosslight_binary-4.1.33/src/fosslight_binary/_binary.py +0 -168
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/LICENSE +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/LICENSES/Apache-2.0.txt +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/LICENSES/LicenseRef-3rd_party_licenses.txt +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/MANIFEST.in +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/README.md +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/setup.cfg +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary/__init__.py +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary/_help.py +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/SOURCES.txt +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/dependency_links.txt +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/entry_points.txt +0 -0
- {fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
# Copyright (c) 2020 LG Electronics Inc.
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
from fosslight_util.oss_item import FileItem
|
|
6
|
+
|
|
7
|
+
EXCLUDE_TRUE_VALUE = "Exclude"
|
|
8
|
+
TLSH_CHECKSUM_NULL = "0"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class VulnerabilityItem:
|
|
12
|
+
file_path = ""
|
|
13
|
+
vul_id = ""
|
|
14
|
+
nvd_url = ""
|
|
15
|
+
|
|
16
|
+
def __init__(self, file_path, id, url):
|
|
17
|
+
self.file_path = file_path
|
|
18
|
+
self.vul_id = id
|
|
19
|
+
self.nvd_url = url
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BinaryItem(FileItem):
|
|
23
|
+
def __init__(self, value):
|
|
24
|
+
super().__init__("")
|
|
25
|
+
self.exclude = False
|
|
26
|
+
self.source_name_or_path = ""
|
|
27
|
+
self.tlsh = TLSH_CHECKSUM_NULL
|
|
28
|
+
self.vulnerability_items = []
|
|
29
|
+
self.binary_name_without_path = ""
|
|
30
|
+
self.bin_name_with_path = value
|
|
31
|
+
self.found_in_owasp = False
|
|
32
|
+
self.is_binary = True
|
|
33
|
+
|
|
34
|
+
def __del__(self):
|
|
35
|
+
pass
|
|
36
|
+
|
|
37
|
+
def set_oss_items(self, new_oss_list, exclude=False, exclude_msg=""):
|
|
38
|
+
if exclude:
|
|
39
|
+
for oss in new_oss_list:
|
|
40
|
+
oss.exclude = True
|
|
41
|
+
oss.comment = exclude_msg
|
|
42
|
+
# Append New input OSS
|
|
43
|
+
self.oss_items.extend(new_oss_list)
|
|
44
|
+
|
|
45
|
+
def get_vulnerability_items(self):
|
|
46
|
+
nvd_url = [vul_item.nvd_url for vul_item in self.vulnerability_items]
|
|
47
|
+
return ", ".join(nvd_url)
|
|
48
|
+
|
|
49
|
+
def get_print_binary_only(self):
|
|
50
|
+
return (self.source_name_or_path + "\t" + self.checksum + "\t" + self.tlsh)
|
|
51
|
+
|
|
52
|
+
def get_print_array(self):
|
|
53
|
+
items = []
|
|
54
|
+
if self.oss_items:
|
|
55
|
+
for oss in self.oss_items:
|
|
56
|
+
lic = ",".join(oss.license)
|
|
57
|
+
exclude = EXCLUDE_TRUE_VALUE if (self.exclude or oss.exclude) else ""
|
|
58
|
+
nvd_url = self.get_vulnerability_items()
|
|
59
|
+
items.append([self.source_name_or_path, oss.name, oss.version,
|
|
60
|
+
lic, oss.download_location, oss.homepage,
|
|
61
|
+
oss.copyright, exclude, oss.comment,
|
|
62
|
+
nvd_url, self.tlsh, self.checksum])
|
|
63
|
+
else:
|
|
64
|
+
exclude = EXCLUDE_TRUE_VALUE if self.exclude else ""
|
|
65
|
+
items.append([self.source_name_or_path, '',
|
|
66
|
+
'', '', '', '', '', exclude, self.comment, '',
|
|
67
|
+
self.tlsh, self.checksum])
|
|
68
|
+
return items
|
|
69
|
+
|
|
70
|
+
def get_print_json(self):
|
|
71
|
+
items = []
|
|
72
|
+
if self.oss_items:
|
|
73
|
+
for oss in self.oss_items:
|
|
74
|
+
json_item = {}
|
|
75
|
+
json_item["name"] = oss.name
|
|
76
|
+
json_item["version"] = oss.version
|
|
77
|
+
|
|
78
|
+
if self.source_name_or_path:
|
|
79
|
+
json_item["source path"] = self.source_name_or_path
|
|
80
|
+
if len(oss.license) > 0:
|
|
81
|
+
json_item["license"] = oss.license
|
|
82
|
+
if oss.download_location:
|
|
83
|
+
json_item["download location"] = oss.download_location
|
|
84
|
+
if oss.homepage:
|
|
85
|
+
json_item["homepage"] = oss.homepage
|
|
86
|
+
if oss.copyright:
|
|
87
|
+
json_item["copyright text"] = oss.copyright
|
|
88
|
+
if self.exclude or oss.exclude:
|
|
89
|
+
json_item["exclude"] = True
|
|
90
|
+
if oss.comment:
|
|
91
|
+
json_item["comment"] = oss.comment
|
|
92
|
+
items.append(json_item)
|
|
93
|
+
else:
|
|
94
|
+
json_item = {}
|
|
95
|
+
if self.source_name_or_path:
|
|
96
|
+
json_item["source path"] = self.source_name_or_path
|
|
97
|
+
if self.exclude:
|
|
98
|
+
json_item["exclude"] = True
|
|
99
|
+
if self.comment:
|
|
100
|
+
json_item["comment"] = self.comment
|
|
101
|
+
return items
|
|
@@ -8,7 +8,8 @@ import logging
|
|
|
8
8
|
import psycopg2
|
|
9
9
|
import pandas as pd
|
|
10
10
|
from urllib.parse import urlparse
|
|
11
|
-
from ._binary import
|
|
11
|
+
from ._binary import TLSH_CHECKSUM_NULL
|
|
12
|
+
from fosslight_util.oss_item import OssItem
|
|
12
13
|
import fosslight_util.constant as constant
|
|
13
14
|
|
|
14
15
|
columns = ['filename', 'pathname', 'checksum', 'tlshchecksum', 'ossname',
|
|
@@ -43,10 +44,10 @@ def get_oss_info_from_db(bin_info_list, dburl=""):
|
|
|
43
44
|
if not item.found_in_owasp:
|
|
44
45
|
oss_from_db = OssItem(row['ossname'], row['ossversion'], row['license'])
|
|
45
46
|
bin_oss_items.append(oss_from_db)
|
|
46
|
-
item.set_comment("Binary DB result")
|
|
47
47
|
|
|
48
48
|
if bin_oss_items:
|
|
49
49
|
item.set_oss_items(bin_oss_items)
|
|
50
|
+
item.comment = "Binary DB result"
|
|
50
51
|
|
|
51
52
|
disconnect_lge_bin_db()
|
|
52
53
|
return bin_info_list, _cnt_auto_identified
|
|
@@ -97,14 +98,14 @@ def get_oss_info_by_tlsh_and_filename(file_name, checksum_value, tlsh_value):
|
|
|
97
98
|
sql_statement_filename, ['tlshchecksum'])
|
|
98
99
|
if df_result is None or len(df_result) <= 0:
|
|
99
100
|
final_result_item = ""
|
|
100
|
-
elif tlsh_value ==
|
|
101
|
+
elif tlsh_value == TLSH_CHECKSUM_NULL: # Couldn't get the tlsh of a file.
|
|
101
102
|
final_result_item = ""
|
|
102
103
|
else:
|
|
103
104
|
matched_tlsh = ""
|
|
104
105
|
matched_tlsh_diff = -1
|
|
105
106
|
for row in df_result.tlshchecksum:
|
|
106
107
|
try:
|
|
107
|
-
if row !=
|
|
108
|
+
if row != TLSH_CHECKSUM_NULL:
|
|
108
109
|
tlsh_diff = tlsh.diff(row, tlsh_value)
|
|
109
110
|
if tlsh_diff <= 120: # MATCHED
|
|
110
111
|
if (matched_tlsh_diff < 0) or (tlsh_diff < matched_tlsh_diff):
|
|
@@ -8,7 +8,8 @@ import json
|
|
|
8
8
|
import os
|
|
9
9
|
import sys
|
|
10
10
|
import fosslight_util.constant as constant
|
|
11
|
-
from ._binary import BinaryItem,
|
|
11
|
+
from ._binary import BinaryItem, VulnerabilityItem
|
|
12
|
+
from fosslight_util.oss_item import OssItem
|
|
12
13
|
from dependency_check import run as dependency_check_run
|
|
13
14
|
|
|
14
15
|
|
|
@@ -63,21 +64,21 @@ def merge_binary_list(owasp_items, vulnerability_items, bin_list):
|
|
|
63
64
|
for key, value in owasp_items.items():
|
|
64
65
|
found = False
|
|
65
66
|
for bin in bin_list:
|
|
66
|
-
if bin.
|
|
67
|
+
if bin.source_name_or_path == key:
|
|
67
68
|
for oss in value:
|
|
68
69
|
if oss.name and oss.license:
|
|
69
70
|
bin.found_in_owasp = True
|
|
70
71
|
break
|
|
71
72
|
bin.set_oss_items(value)
|
|
72
|
-
if vulnerability_items
|
|
73
|
-
bin.
|
|
73
|
+
if vulnerability_items and vulnerability_items.get(key):
|
|
74
|
+
bin.vulnerability_items.extend(vulnerability_items.get(key))
|
|
74
75
|
found = True
|
|
75
76
|
break
|
|
76
77
|
|
|
77
78
|
if not found:
|
|
78
79
|
bin_item = BinaryItem(os.path.abspath(key))
|
|
79
80
|
bin_item.binary_name_without_path = os.path.basename(key)
|
|
80
|
-
bin_item.
|
|
81
|
+
bin_item.source_name_or_path = key
|
|
81
82
|
bin_item.set_oss_items(value)
|
|
82
83
|
not_found_bin.append(bin_item)
|
|
83
84
|
|
|
@@ -261,7 +262,7 @@ def analyze_jar_file(path_to_find_bin, path_to_exclude):
|
|
|
261
262
|
|
|
262
263
|
if oss_name != "" or oss_ver != "" or oss_license != "" or oss_dl_url != "":
|
|
263
264
|
oss = OssItem(oss_name, oss_ver, oss_license, oss_dl_url)
|
|
264
|
-
oss.
|
|
265
|
+
oss.comment = "OWASP result"
|
|
265
266
|
|
|
266
267
|
remove_owasp_item = owasp_items.get(file_with_path)
|
|
267
268
|
if remove_owasp_item:
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
# SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
import os
|
|
7
7
|
import sys
|
|
8
|
+
import platform
|
|
8
9
|
from datetime import datetime
|
|
9
10
|
from binaryornot.check import is_binary
|
|
10
11
|
import magic
|
|
@@ -13,14 +14,17 @@ import yaml
|
|
|
13
14
|
import stat
|
|
14
15
|
from fosslight_util.set_log import init_log
|
|
15
16
|
import fosslight_util.constant as constant
|
|
16
|
-
from fosslight_util.output_format import
|
|
17
|
+
from fosslight_util.output_format import check_output_formats_v2, write_output_file
|
|
17
18
|
from ._binary_dao import get_oss_info_from_db
|
|
18
|
-
from ._binary import BinaryItem
|
|
19
|
+
from ._binary import BinaryItem, TLSH_CHECKSUM_NULL
|
|
19
20
|
from ._jar_analysis import analyze_jar_file, merge_binary_list
|
|
20
21
|
from fosslight_util.correct import correct_with_yaml
|
|
21
|
-
from fosslight_util.
|
|
22
|
+
from fosslight_util.oss_item import ScannerItem
|
|
23
|
+
import hashlib
|
|
24
|
+
import tlsh
|
|
25
|
+
from io import open
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
PKG_NAME = "fosslight_binary"
|
|
24
28
|
logger = logging.getLogger(constant.LOGGER_NAME)
|
|
25
29
|
|
|
26
30
|
_REMOVE_FILE_EXTENSION = ['qm', 'xlsx', 'pdf', 'pptx', 'jfif', 'docx', 'doc', 'whl',
|
|
@@ -40,11 +44,31 @@ _root_path = ""
|
|
|
40
44
|
_start_time = ""
|
|
41
45
|
windows = False
|
|
42
46
|
BYTES = 2048
|
|
43
|
-
|
|
44
47
|
BIN_EXT_HEADER = {'BIN_FL_Binary': ['ID', 'Binary Path', 'OSS Name',
|
|
45
48
|
'OSS Version', 'License', 'Download Location',
|
|
46
49
|
'Homepage', 'Copyright Text', 'Exclude',
|
|
47
50
|
'Comment', 'Vulnerability Link', 'TLSH', 'SHA1']}
|
|
51
|
+
HIDE_HEADER = {'TLSH', "SHA1"}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def get_checksum_and_tlsh(bin_with_path):
|
|
55
|
+
checksum_value = TLSH_CHECKSUM_NULL
|
|
56
|
+
tlsh_value = TLSH_CHECKSUM_NULL
|
|
57
|
+
error_msg = ""
|
|
58
|
+
try:
|
|
59
|
+
f = open(bin_with_path, "rb")
|
|
60
|
+
byte = f.read()
|
|
61
|
+
sha1_hash = hashlib.sha1(byte)
|
|
62
|
+
checksum_value = str(sha1_hash.hexdigest())
|
|
63
|
+
try:
|
|
64
|
+
tlsh_value = str(tlsh.hash(byte))
|
|
65
|
+
except:
|
|
66
|
+
tlsh_value = TLSH_CHECKSUM_NULL
|
|
67
|
+
f.close()
|
|
68
|
+
except Exception as ex:
|
|
69
|
+
error_msg = f"(Error) Get_checksum, tlsh: {ex}"
|
|
70
|
+
|
|
71
|
+
return checksum_value, tlsh_value, error_msg
|
|
48
72
|
|
|
49
73
|
|
|
50
74
|
def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
|
|
@@ -53,14 +77,14 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
|
|
|
53
77
|
_json_ext = ".json"
|
|
54
78
|
_start_time = datetime.now().strftime('%y%m%d_%H%M')
|
|
55
79
|
_result_log = {
|
|
56
|
-
"Tool Info":
|
|
80
|
+
"Tool Info": PKG_NAME
|
|
57
81
|
}
|
|
58
82
|
|
|
59
83
|
_root_path = path_to_find_bin
|
|
60
84
|
if not path_to_find_bin.endswith(os.path.sep):
|
|
61
85
|
_root_path += os.path.sep
|
|
62
86
|
|
|
63
|
-
success, msg, output_path, output_files, output_extensions =
|
|
87
|
+
success, msg, output_path, output_files, output_extensions, formats = check_output_formats_v2(output_file_name, formats)
|
|
64
88
|
|
|
65
89
|
if success:
|
|
66
90
|
if output_path == "":
|
|
@@ -70,12 +94,33 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
|
|
|
70
94
|
|
|
71
95
|
while len(output_files) < len(output_extensions):
|
|
72
96
|
output_files.append(None)
|
|
97
|
+
to_remove = [] # elements of spdx format on windows that should be removed
|
|
73
98
|
for i, output_extension in enumerate(output_extensions):
|
|
74
99
|
if output_files[i] is None or output_files[i] == "":
|
|
75
|
-
if
|
|
76
|
-
|
|
100
|
+
if formats:
|
|
101
|
+
if formats[i].startswith('spdx'):
|
|
102
|
+
if platform.system() != 'Windows':
|
|
103
|
+
output_files[i] = f"fosslight_spdx_bin_{_start_time}"
|
|
104
|
+
else:
|
|
105
|
+
logger.warning('spdx format is not supported on Windows. Please remove spdx from format.')
|
|
106
|
+
to_remove.append(i)
|
|
107
|
+
else:
|
|
108
|
+
if output_extension == _json_ext:
|
|
109
|
+
output_files[i] = f"fosslight_opossum_bin_{_start_time}"
|
|
110
|
+
else:
|
|
111
|
+
output_files[i] = f"fosslight_report_bin_{_start_time}"
|
|
77
112
|
else:
|
|
78
|
-
|
|
113
|
+
if output_extension == _json_ext:
|
|
114
|
+
output_files[i] = f"fosslight_opossum_bin_{_start_time}"
|
|
115
|
+
else:
|
|
116
|
+
output_files[i] = f"fosslight_report_bin_{_start_time}"
|
|
117
|
+
for index in sorted(to_remove, reverse=True):
|
|
118
|
+
# remove elements of spdx format on windows
|
|
119
|
+
del output_files[index]
|
|
120
|
+
del output_extensions[index]
|
|
121
|
+
del formats[index]
|
|
122
|
+
if len(output_extensions) < 1:
|
|
123
|
+
sys.exit(0)
|
|
79
124
|
|
|
80
125
|
combined_paths_and_files = [os.path.join(output_path, file) for file in output_files]
|
|
81
126
|
else:
|
|
@@ -83,7 +128,8 @@ def init(path_to_find_bin, output_file_name, formats, path_to_exclude=[]):
|
|
|
83
128
|
sys.exit(1)
|
|
84
129
|
|
|
85
130
|
log_file = os.path.join(output_path, f"fosslight_log_bin_{_start_time}.txt")
|
|
86
|
-
logger, _result_log = init_log(log_file, True, logging.INFO, logging.DEBUG,
|
|
131
|
+
logger, _result_log = init_log(log_file, True, logging.INFO, logging.DEBUG,
|
|
132
|
+
PKG_NAME, path_to_find_bin, path_to_exclude)
|
|
87
133
|
|
|
88
134
|
if not success:
|
|
89
135
|
error_occured(error_msg=msg,
|
|
@@ -121,15 +167,15 @@ def get_file_list(path_to_find, abs_path_to_exclude):
|
|
|
121
167
|
bin_with_path = os.path.join(root, file)
|
|
122
168
|
bin_item = BinaryItem(bin_with_path)
|
|
123
169
|
bin_item.binary_name_without_path = file
|
|
124
|
-
bin_item.
|
|
170
|
+
bin_item.source_name_or_path = bin_with_path.replace(
|
|
125
171
|
_root_path, '', 1)
|
|
126
172
|
|
|
127
173
|
if any(dir_name in dir_path for dir_name in _EXCLUDE_DIR):
|
|
128
|
-
bin_item.
|
|
174
|
+
bin_item.exclude = True
|
|
129
175
|
elif file.lower() in _EXCLUDE_FILE:
|
|
130
|
-
bin_item.
|
|
176
|
+
bin_item.exclude = True
|
|
131
177
|
elif extension in _EXCLUDE_FILE_EXTENSION:
|
|
132
|
-
bin_item.
|
|
178
|
+
bin_item.exclude = True
|
|
133
179
|
bin_list.append(bin_item)
|
|
134
180
|
file_cnt += 1
|
|
135
181
|
return file_cnt, bin_list, found_jar
|
|
@@ -146,11 +192,10 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
|
|
|
146
192
|
db_loaded_cnt = 0
|
|
147
193
|
success_to_write = False
|
|
148
194
|
writing_msg = ""
|
|
149
|
-
hide_header = {'TLSH', "SHA1"}
|
|
150
|
-
content_list = []
|
|
151
195
|
results = []
|
|
152
196
|
bin_list = []
|
|
153
197
|
base_dir_name = os.path.basename(path_to_find_bin)
|
|
198
|
+
scan_item = ScannerItem(PKG_NAME, "")
|
|
154
199
|
abs_path_to_exclude = [os.path.abspath(os.path.join(base_dir_name, path)) for path in path_to_exclude if path.strip() != ""]
|
|
155
200
|
|
|
156
201
|
if not os.path.isdir(path_to_find_bin):
|
|
@@ -168,12 +213,10 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
|
|
|
168
213
|
exit=True)
|
|
169
214
|
total_bin_cnt = len(return_list)
|
|
170
215
|
if simple_mode:
|
|
171
|
-
bin_list = [bin.
|
|
216
|
+
bin_list = [bin.bin_name_with_path for bin in return_list]
|
|
172
217
|
else:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
input_path=path_to_find_bin,
|
|
176
|
-
exclude_path=path_to_exclude)
|
|
218
|
+
scan_item = ScannerItem(PKG_NAME, _start_time)
|
|
219
|
+
scan_item.set_cover_pathinfo(path_to_find_bin, path_to_exclude)
|
|
177
220
|
try:
|
|
178
221
|
# Run OWASP Dependency-check
|
|
179
222
|
if found_jar:
|
|
@@ -185,25 +228,24 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
|
|
|
185
228
|
logger.warning("Could not find OSS information for some jar files.")
|
|
186
229
|
|
|
187
230
|
return_list, db_loaded_cnt = get_oss_info_from_db(return_list, dburl)
|
|
188
|
-
return_list = sorted(return_list, key=lambda row: (row.
|
|
189
|
-
|
|
190
|
-
sheet_list = {}
|
|
191
|
-
for item in return_list:
|
|
192
|
-
content_list.extend(item.get_oss_report())
|
|
193
|
-
sheet_list["BIN_FL_Binary"] = content_list
|
|
231
|
+
return_list = sorted(return_list, key=lambda row: (row.bin_name_with_path))
|
|
232
|
+
scan_item.append_file_items(return_list, PKG_NAME)
|
|
194
233
|
if correct_mode:
|
|
195
|
-
success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_find_bin,
|
|
234
|
+
success, msg_correct, correct_list = correct_with_yaml(correct_filepath, path_to_find_bin, scan_item)
|
|
196
235
|
if not success:
|
|
197
236
|
logger.info(f"No correction with yaml: {msg_correct}")
|
|
198
237
|
else:
|
|
199
|
-
|
|
238
|
+
return_list = correct_list
|
|
200
239
|
logger.info("Success to correct with yaml.")
|
|
201
|
-
|
|
240
|
+
|
|
241
|
+
scan_item.set_cover_comment(f"Total number of binaries: {total_bin_cnt}")
|
|
202
242
|
if total_bin_cnt == 0:
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
243
|
+
scan_item.set_cover_comment("(No binary detected.) ")
|
|
244
|
+
scan_item.set_cover_comment(f"Total number of files: {total_file_cnt}")
|
|
245
|
+
|
|
246
|
+
for combined_path_and_file, output_extension, output_format in zip(result_reports, output_extensions, formats):
|
|
247
|
+
results.append(write_output_file(combined_path_and_file, output_extension, scan_item,
|
|
248
|
+
BIN_EXT_HEADER, HIDE_HEADER, output_format))
|
|
207
249
|
|
|
208
250
|
except Exception as ex:
|
|
209
251
|
error_occured(error_msg=str(ex), exit=False)
|
|
@@ -214,8 +256,8 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
|
|
|
214
256
|
logger.info(f"Output file :{result_file}")
|
|
215
257
|
else:
|
|
216
258
|
logger.warning(f"{writing_msg}")
|
|
217
|
-
|
|
218
|
-
logger.info(
|
|
259
|
+
for row in scan_item.get_cover_comment():
|
|
260
|
+
logger.info(row)
|
|
219
261
|
else:
|
|
220
262
|
logger.error(f"Fail to generate result file.:{writing_msg}")
|
|
221
263
|
|
|
@@ -227,21 +269,21 @@ def find_binaries(path_to_find_bin, output_dir, formats, dburl="", simple_mode=F
|
|
|
227
269
|
except Exception as ex:
|
|
228
270
|
error_occured(error_msg=f"Print log : {ex}", exit=False)
|
|
229
271
|
|
|
230
|
-
return success_to_write,
|
|
272
|
+
return success_to_write, scan_item
|
|
231
273
|
|
|
232
274
|
|
|
233
275
|
def return_bin_only(file_list, need_checksum_tlsh=True):
|
|
234
276
|
for file_item in file_list:
|
|
235
277
|
try:
|
|
236
|
-
if check_binary(file_item.
|
|
278
|
+
if check_binary(file_item.bin_name_with_path):
|
|
237
279
|
if need_checksum_tlsh:
|
|
238
|
-
|
|
239
|
-
if
|
|
280
|
+
file_item.checksum, file_item.tlsh, error_msg = get_checksum_and_tlsh(file_item.bin_name_with_path)
|
|
281
|
+
if error_msg:
|
|
240
282
|
error_occured(error_msg=error_msg, exit=False)
|
|
241
283
|
yield file_item
|
|
242
284
|
except Exception as ex:
|
|
243
285
|
logger.debug(f"Exception in get_file_list: {ex}")
|
|
244
|
-
file_item.
|
|
286
|
+
file_item.comment = "Exclude or delete if it is not binary."
|
|
245
287
|
yield file_item
|
|
246
288
|
|
|
247
289
|
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
# Copyright (c) 2020 LG Electronics Inc.
|
|
4
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
import hashlib
|
|
6
|
-
import tlsh
|
|
7
|
-
from io import open
|
|
8
|
-
|
|
9
|
-
_EXCLUDE_TRUE_VALUE = "Exclude"
|
|
10
|
-
_TLSH_CHECKSUM_NULL = "0"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class OssItem:
|
|
14
|
-
name = ""
|
|
15
|
-
version = ""
|
|
16
|
-
license = ""
|
|
17
|
-
dl_url = ""
|
|
18
|
-
comment = ""
|
|
19
|
-
exclude = False
|
|
20
|
-
|
|
21
|
-
def __init__(self, name, version, license, dl_url=""):
|
|
22
|
-
self.name = name
|
|
23
|
-
self.version = version
|
|
24
|
-
self.license = license
|
|
25
|
-
self.dl_url = dl_url
|
|
26
|
-
self.exclude = False
|
|
27
|
-
self.comment = ""
|
|
28
|
-
|
|
29
|
-
def set_comment(self, value):
|
|
30
|
-
if self.comment:
|
|
31
|
-
self.comment = f"{self.comment} / {value}"
|
|
32
|
-
else:
|
|
33
|
-
self.comment = value
|
|
34
|
-
|
|
35
|
-
def set_exclude(self, value):
|
|
36
|
-
self.exclude = value
|
|
37
|
-
|
|
38
|
-
def get_comment(self):
|
|
39
|
-
return self.comment
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class VulnerabilityItem:
|
|
43
|
-
file_path = ""
|
|
44
|
-
vul_id = ""
|
|
45
|
-
nvd_url = ""
|
|
46
|
-
|
|
47
|
-
def __init__(self, file_path, id, url):
|
|
48
|
-
self.file_path = file_path
|
|
49
|
-
self.vul_id = id
|
|
50
|
-
self.nvd_url = url
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
class BinaryItem:
|
|
54
|
-
bin_name = ""
|
|
55
|
-
binary_name_without_path = ""
|
|
56
|
-
binary_strip_root = "" # Value of binary name column
|
|
57
|
-
tlsh = _TLSH_CHECKSUM_NULL
|
|
58
|
-
checksum = _TLSH_CHECKSUM_NULL
|
|
59
|
-
oss_items = []
|
|
60
|
-
vulnerability_items = []
|
|
61
|
-
exclude = False
|
|
62
|
-
comment = ""
|
|
63
|
-
found_in_owasp = False
|
|
64
|
-
|
|
65
|
-
def __init__(self, value):
|
|
66
|
-
self.exclude = False
|
|
67
|
-
self.binary_strip_root = ""
|
|
68
|
-
self.checksum = _TLSH_CHECKSUM_NULL
|
|
69
|
-
self.tlsh = _TLSH_CHECKSUM_NULL
|
|
70
|
-
self.oss_items = []
|
|
71
|
-
self.vulnerability_items = []
|
|
72
|
-
self.binary_name_without_path = ""
|
|
73
|
-
self.set_bin_name(value)
|
|
74
|
-
|
|
75
|
-
def __del__(self):
|
|
76
|
-
pass
|
|
77
|
-
|
|
78
|
-
def set_oss_items(self, new_oss_list, exclude=False, exclude_msg=""):
|
|
79
|
-
if exclude:
|
|
80
|
-
for oss in new_oss_list:
|
|
81
|
-
oss.set_exclude(True)
|
|
82
|
-
oss.set_comment(exclude_msg)
|
|
83
|
-
# Append New input OSS
|
|
84
|
-
self.oss_items.extend(new_oss_list)
|
|
85
|
-
|
|
86
|
-
def get_oss_items(self):
|
|
87
|
-
return self.oss_items
|
|
88
|
-
|
|
89
|
-
def set_vulnerability_items(self, vul_list):
|
|
90
|
-
if vul_list is not None:
|
|
91
|
-
self.vulnerability_items.extend(vul_list)
|
|
92
|
-
|
|
93
|
-
def get_vulnerability_items(self):
|
|
94
|
-
nvd_url = [vul_item.nvd_url for vul_item in self.vulnerability_items]
|
|
95
|
-
return ", ".join(nvd_url)
|
|
96
|
-
|
|
97
|
-
def set_comment(self, value):
|
|
98
|
-
if self.comment:
|
|
99
|
-
self.comment = f"{self.comment} / {value}"
|
|
100
|
-
else:
|
|
101
|
-
self.comment = value
|
|
102
|
-
|
|
103
|
-
def set_bin_name(self, value):
|
|
104
|
-
self.bin_name = value
|
|
105
|
-
|
|
106
|
-
def set_exclude(self, value):
|
|
107
|
-
self.exclude = value
|
|
108
|
-
|
|
109
|
-
def set_checksum(self, value):
|
|
110
|
-
self.checksum = value
|
|
111
|
-
|
|
112
|
-
def set_tlsh(self, value):
|
|
113
|
-
self.tlsh = value
|
|
114
|
-
|
|
115
|
-
def get_comment(self):
|
|
116
|
-
return self.comment
|
|
117
|
-
|
|
118
|
-
def get_print_binary_only(self):
|
|
119
|
-
return (self.binary_strip_root + "\t" + self.checksum + "\t" + self.tlsh)
|
|
120
|
-
|
|
121
|
-
def get_oss_report(self):
|
|
122
|
-
comment = ""
|
|
123
|
-
if len(self.oss_items) > 0:
|
|
124
|
-
for oss in self.oss_items:
|
|
125
|
-
exclude = _EXCLUDE_TRUE_VALUE if (self.exclude or oss.exclude) else ""
|
|
126
|
-
nvd_url = self.get_vulnerability_items()
|
|
127
|
-
|
|
128
|
-
if self.comment:
|
|
129
|
-
if oss.comment:
|
|
130
|
-
comment = f"{self.comment} / {oss.comment}"
|
|
131
|
-
else:
|
|
132
|
-
comment = self.comment
|
|
133
|
-
else:
|
|
134
|
-
comment = oss.comment
|
|
135
|
-
|
|
136
|
-
yield [self.binary_strip_root, oss.name, oss.version,
|
|
137
|
-
oss.license, oss.dl_url, '', '', exclude, comment,
|
|
138
|
-
nvd_url, self.tlsh, self.checksum]
|
|
139
|
-
else:
|
|
140
|
-
exclude = _EXCLUDE_TRUE_VALUE if self.exclude else ""
|
|
141
|
-
yield [self.binary_strip_root, '',
|
|
142
|
-
'', '', '', '', '', exclude, self.comment, '', self.tlsh, self.checksum]
|
|
143
|
-
|
|
144
|
-
def set_checksum_tlsh(self):
|
|
145
|
-
self.checksum, self.tlsh, error, msg = get_checksum_and_tlsh(
|
|
146
|
-
self.bin_name)
|
|
147
|
-
return error, msg
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
def get_checksum_and_tlsh(bin_with_path):
|
|
151
|
-
checksum_value = _TLSH_CHECKSUM_NULL
|
|
152
|
-
tlsh_value = _TLSH_CHECKSUM_NULL
|
|
153
|
-
error_msg = ""
|
|
154
|
-
error = False
|
|
155
|
-
try:
|
|
156
|
-
f = open(bin_with_path, "rb")
|
|
157
|
-
byte = f.read()
|
|
158
|
-
sha1_hash = hashlib.sha1(byte)
|
|
159
|
-
checksum_value = str(sha1_hash.hexdigest())
|
|
160
|
-
try:
|
|
161
|
-
tlsh_value = str(tlsh.hash(byte))
|
|
162
|
-
except:
|
|
163
|
-
tlsh_value = _TLSH_CHECKSUM_NULL
|
|
164
|
-
f.close()
|
|
165
|
-
except Exception as ex:
|
|
166
|
-
error_msg = f"(Error) Get_checksum, tlsh: {ex}"
|
|
167
|
-
error = True
|
|
168
|
-
return checksum_value, tlsh_value, error, error_msg
|
|
File without changes
|
|
File without changes
|
{fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/LICENSES/LicenseRef-3rd_party_licenses.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{fosslight_binary-4.1.33 → fosslight_binary-5.1.0}/src/fosslight_binary.egg-info/top_level.txt
RENAMED
|
File without changes
|