-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(offline-endpoint-scan): Add EndpointScanApi and expand EndpointAnalysis to support uploading offline scan files
- Loading branch information
Showing
34 changed files
with
881 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import sys | ||
from pprint import pprint | ||
|
||
from intezer_sdk import api | ||
from intezer_sdk.endpoint_analysis import EndpointAnalysis | ||
|
||
|
||
def send_file_with_wait(offline_scan_directory: str): | ||
api.set_global_api('api-key') | ||
analysis = EndpointAnalysis(offline_scan_directory=offline_scan_directory) | ||
analysis.send(wait=True) | ||
pprint(analysis.result()) | ||
|
||
if __name__ == '__main__': | ||
send_file_with_wait(*sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '1.14.4' | ||
__version__ = '1.15.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import gzip | ||
from typing import List | ||
from urllib.parse import urlparse | ||
|
||
from intezer_sdk.api import raise_for_status | ||
|
||
from intezer_sdk.api import IntezerProxy | ||
|
||
|
||
class EndpointScanApi: | ||
def __init__(self, | ||
scan_id: str, | ||
base_api: IntezerProxy): | ||
self.base_api = base_api | ||
if not scan_id: | ||
raise ValueError('scan_id must be provided') | ||
self.scan_id = scan_id | ||
api_base = f'https://{urlparse(base_api.base_url).netloc}' | ||
self.base_url = f'{api_base}/scans/scans/{scan_id}' | ||
|
||
def request_with_refresh_expired_access_token(self, *args, **kwargs): | ||
return self.base_api.request_with_refresh_expired_access_token(base_url=self.base_url, *args, **kwargs) | ||
|
||
def send_host_info(self, host_info: dict): | ||
response = self.request_with_refresh_expired_access_token(path='/host-info', | ||
data=host_info, | ||
method='POST') | ||
raise_for_status(response) | ||
|
||
def send_processes_info(self, processes_info: dict): | ||
response = self.request_with_refresh_expired_access_token(path='/processes-info', | ||
data=processes_info, | ||
method='POST') | ||
raise_for_status(response) | ||
|
||
def send_loaded_modules_info(self, pid, loaded_modules_info: dict): | ||
response = self.request_with_refresh_expired_access_token(path=f'/processes/{pid}/loaded-modules-info', | ||
data=loaded_modules_info, | ||
method='POST') | ||
raise_for_status(response) | ||
|
||
def send_injected_modules_info(self, injected_module_list: dict): | ||
response = self.request_with_refresh_expired_access_token(path='/injected-modules-info', | ||
data=injected_module_list, | ||
method='POST') | ||
raise_for_status(response) | ||
|
||
def send_scheduled_tasks_info(self, scheduled_tasks_info: dict): | ||
response = self.request_with_refresh_expired_access_token(path='/scheduled-tasks-info', | ||
data=scheduled_tasks_info, | ||
method='POST') | ||
raise_for_status(response) | ||
|
||
def send_file_module_differences(self, file_module_differences: dict): | ||
response = self.request_with_refresh_expired_access_token(path='/file-module-differences', | ||
data=file_module_differences, | ||
method='POST') | ||
raise_for_status(response) | ||
|
||
def send_files_info(self, files_info: dict) -> List[str]: | ||
""" | ||
:param files_info: endpoint scan files info | ||
:return: list of file hashes to upload | ||
""" | ||
response = self.request_with_refresh_expired_access_token(path='/files-info', | ||
data=files_info, | ||
method='POST') | ||
raise_for_status(response) | ||
return response.json()['result'] | ||
|
||
def send_memory_module_dump_info(self, memory_modules_info: dict) -> List[str]: | ||
""" | ||
:param memory_modules_info: endpoint scan memory modules info | ||
:return: list of file hashes to upload | ||
""" | ||
response = self.request_with_refresh_expired_access_token(path='/memory-module-dumps-info', | ||
data=memory_modules_info, | ||
method='POST') | ||
raise_for_status(response) | ||
return response.json()['result'] | ||
|
||
def upload_collected_binary(self, file_path: str, collected_from: str): | ||
with open(file_path, 'rb') as file_to_upload: | ||
file_data = file_to_upload.read() | ||
compressed_data = gzip.compress(file_data, compresslevel=9) | ||
response = self.request_with_refresh_expired_access_token( | ||
path=f'/{collected_from}/collected-binaries', | ||
data=compressed_data, | ||
headers={'Content-Type': 'application/octet-stream', 'Content-Encoding': 'gzip'}, | ||
method='POST') | ||
|
||
raise_for_status(response) | ||
|
||
def end_scan(self, scan_summary: dict): | ||
response = self.request_with_refresh_expired_access_token(path='/end', | ||
data=scan_summary, | ||
method='POST') | ||
raise_for_status(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.