def _convert_to_firmware(self, entry, analysis_filter=None): firmware = Firmware() firmware.uid = entry['_id'] firmware.size = entry['size'] firmware.set_name(entry['file_name']) firmware.set_device_name(entry['device_name']) firmware.set_device_class(entry['device_class']) firmware.set_release_date(convert_time_to_str(entry['release_date'])) firmware.set_vendor(entry['vendor']) firmware.set_firmware_version(entry['version']) firmware.processed_analysis = self.retrieve_analysis( entry['processed_analysis'], analysis_filter=analysis_filter) firmware.files_included = set(entry['files_included']) firmware.virtual_file_path = entry['virtual_file_path'] firmware.tags = entry['tags'] if 'tags' in entry else dict() firmware.analysis_tags = entry[ 'analysis_tags'] if 'analysis_tags' in entry else dict() try: # for backwards compatibility firmware.set_part_name(entry['device_part']) except KeyError: firmware.set_part_name('complete') if 'comments' in entry: # for backwards compatibility firmware.comments = entry['comments'] return firmware
def create_test_firmware(device_class='Router', device_name='test_router', vendor='test_vendor', bin_path='container/test.zip', all_files_included_set=False, version='0.1'): fw = Firmware(file_path=os.path.join(get_test_data_dir(), bin_path)) fw.set_device_class(device_class) fw.set_device_name(device_name) fw.set_vendor(vendor) fw.set_release_date('1970-01-01') fw.version = version processed_analysis = { 'dummy': { 'summary': ['sum a', 'fw exclusive sum a'], 'content': 'abcd' }, 'unpacker': { 'plugin_used': 'used_unpack_plugin' }, 'file_type': { 'mime': 'test_type', 'full': 'Not a PE file', 'summary': ['a summary'] } } fw.processed_analysis.update(processed_analysis) if all_files_included_set: fw.list_of_all_included_files = list(fw.files_included) fw.list_of_all_included_files.append(fw.uid) return fw
def convert_analysis_task_to_fw_obj(analysis_task): fw = Firmware( scheduled_analysis=analysis_task['requested_analysis_systems']) if 'binary' in analysis_task.keys(): fw.set_binary(analysis_task['binary']) fw.file_name = analysis_task['file_name'] else: if 'file_name' in analysis_task.keys(): fw.file_name = analysis_task['file_name'] fw.overwrite_uid(analysis_task['uid']) fw.set_device_name(analysis_task['device_name']) fw.set_firmware_version(analysis_task['firmware_version']) fw.set_device_class(analysis_task['device_class']) fw.set_vendor(analysis_task['vendor']) fw.set_release_date(analysis_task['release_date']) return fw
def _convert_to_firmware(self, entry, analysis_filter=None): firmware = Firmware() firmware.uid = entry['_id'] firmware.size = entry['size'] firmware.set_name(entry['file_name']) firmware.set_device_name(entry['device_name']) firmware.set_device_class(entry['device_class']) firmware.set_release_date(convert_time_to_str(entry['release_date'])) firmware.set_vendor(entry['vendor']) firmware.set_firmware_version(entry['version']) firmware.processed_analysis = self.retrieve_analysis(entry['processed_analysis'], analysis_filter=analysis_filter) firmware.files_included = set(entry['files_included']) firmware.virtual_file_path = entry['virtual_file_path'] if "comments" in entry: # for backwards compatibility firmware.comments = entry["comments"] return firmware
def convert_analysis_task_to_fw_obj(analysis_task): fw = Firmware(scheduled_analysis=analysis_task['requested_analysis_systems']) if 'binary' in analysis_task.keys(): fw.set_binary(analysis_task['binary']) fw.file_name = analysis_task['file_name'] else: if 'file_name' in analysis_task.keys(): fw.file_name = analysis_task['file_name'] fw.uid = analysis_task['uid'] fw.set_device_name(analysis_task['device_name']) fw.set_part_name(analysis_task['device_part']) fw.set_firmware_version(analysis_task['version']) fw.set_device_class(analysis_task['device_class']) fw.set_vendor(analysis_task['vendor']) fw.set_release_date(analysis_task['release_date']) for tag in _get_tag_list(analysis_task['tags']): fw.set_tag(tag) return fw
def convert_analysis_task_to_fw_obj(analysis_task: dict) -> Firmware: ''' Convert an analysis task to a firmware object. :param analysis_task: The analysis task data. :return: A new `Firmware` object based on the analysis task data. ''' fw = Firmware(scheduled_analysis=analysis_task['requested_analysis_systems']) if 'binary' in analysis_task.keys(): fw.set_binary(analysis_task['binary']) fw.file_name = analysis_task['file_name'] else: if 'file_name' in analysis_task.keys(): fw.file_name = analysis_task['file_name'] fw.uid = analysis_task['uid'] fw.set_device_name(analysis_task['device_name']) fw.set_part_name(analysis_task['device_part']) fw.set_firmware_version(analysis_task['version']) fw.set_device_class(analysis_task['device_class']) fw.set_vendor(analysis_task['vendor']) fw.set_release_date(analysis_task['release_date']) for tag in _get_tag_list(analysis_task['tags']): fw.set_tag(tag) return fw
def add_test_file_and_wait(test_scheduler, path_in_test_dir): firmware = Firmware( file_path=str(Path(get_test_data_dir(), path_in_test_dir))) firmware.set_release_date('1990-01-16') test_scheduler.add_task(firmware)