Skip to content

Commit

Permalink
Bugfix(offline-endpoint-scan): Read all json files as UTF-8 (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
itamarga authored Feb 13, 2023
1 parent beb7a8f commit ffa47d2
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions intezer_sdk/endpoint_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _send_analyze_to_api(self, **additional_parameters) -> str:
return self.analysis_id

def _create_scan(self):
with open(os.path.join(self._offline_scan_directory, 'scanner_info.json')) as f:
with open(os.path.join(self._offline_scan_directory, 'scanner_info.json'), encoding='utf-8') as f:
scanner_info = json.load(f)
result = self._api.create_endpoint_scan(scanner_info)
scan_id = result['scan_id']
Expand All @@ -149,13 +149,13 @@ def _initialize_endpoint_api(self):

def _send_host_info(self):
logger.info(f'Endpoint analysis: {self.analysis_id}, uploading host info')
with open(os.path.join(self._offline_scan_directory, 'host_info.json')) as f:
with open(os.path.join(self._offline_scan_directory, 'host_info.json'), encoding='utf-8') as f:
host_info = json.load(f)
self._scan_api.send_host_info(host_info)

def _send_processes_info(self):
logger.info(f'Endpoint analysis: {self.analysis_id}, uploading processes info')
with open(os.path.join(self._offline_scan_directory, 'processes_info.json')) as f:
with open(os.path.join(self._offline_scan_directory, 'processes_info.json'), encoding='utf-8') as f:
processes_info = json.load(f)
self._scan_api.send_processes_info(processes_info)

Expand All @@ -164,14 +164,17 @@ def _send_scheduled_tasks_info(self):
if not os.path.isfile(scheduled_tasks_info_path):
return
logger.info(f'Endpoint analysis: {self.analysis_id}, uploading scheduled tasks info')
with open(scheduled_tasks_info_path) as f:
scheduled_tasks_info = json.load(f)
self._scan_api.send_scheduled_tasks_info(scheduled_tasks_info)
try:
with open(scheduled_tasks_info_path, encoding= 'utf-8') as f:
scheduled_tasks_info = json.load(f)
self._scan_api.send_scheduled_tasks_info(scheduled_tasks_info)
except BaseException:
logger.warning(f'Endpoint analysis: {self.analysis_id}, failed to upload scheduled tasks info')

def _send_loaded_modules_info(self):
logger.info(f'Endpoint analysis: {self.analysis_id}, uploading loaded modules info')
for loaded_module_info_file in glob.glob(os.path.join(self._offline_scan_directory, '*_loaded_modules_info.json')):
with open(loaded_module_info_file) as f:
with open(loaded_module_info_file, encoding= 'utf-8') as f:
loaded_modules_info = json.load(f)

pid = os.path.basename(loaded_module_info_file).split('_', maxsplit=1)[0]
Expand All @@ -183,7 +186,7 @@ def _send_files_info_and_upload_required(self):
for files_info_file in glob.glob(os.path.join(self._offline_scan_directory, 'files_info_*.json')):

logger.debug(f'Endpoint analysis: {self.analysis_id}, uploading {files_info_file}')
with open(files_info_file) as f:
with open(files_info_file, encoding= 'utf-8') as f:
files_info = json.load(f)
files_to_upload = self._scan_api.send_files_info(files_info)

Expand All @@ -199,13 +202,13 @@ def _send_files_info_and_upload_required(self):

def _send_module_differences(self):
logger.info(f'Endpoint analysis: {self.analysis_id}, uploading file module differences info')
with open(os.path.join(self._offline_scan_directory, 'file_module_differences.json')) as f:
with open(os.path.join(self._offline_scan_directory, 'file_module_differences.json'), encoding= 'utf-8') as f:
file_module_differences = json.load(f)
self._scan_api.send_file_module_differences(file_module_differences)

def _send_injected_modules_info(self):
logger.info(f'Endpoint analysis: {self.analysis_id}, uploading injected modules info')
with open(os.path.join(self._offline_scan_directory, 'injected_modules_info.json')) as f:
with open(os.path.join(self._offline_scan_directory, 'injected_modules_info.json'), encoding= 'utf-8') as f:
injected_modules_info = json.load(f)
self._scan_api.send_injected_modules_info(injected_modules_info)

Expand All @@ -216,7 +219,7 @@ def _send_memory_module_dump_info_and_upload_required(self):
'memory_module_dump_info_*.json')):

logger.debug(f'Endpoint analysis: {self.analysis_id}, uploading {memory_module_dump_info_file}')
with open(memory_module_dump_info_file) as f:
with open(memory_module_dump_info_file, encoding= 'utf-8') as f:
memory_module_dump_info = json.load(f)
files_to_upload = self._scan_api.send_memory_module_dump_info(memory_module_dump_info)

Expand Down

0 comments on commit ffa47d2

Please sign in to comment.