diff --git a/fact_extractor/plugins/unpacking/sevenz/code/sevenz.py b/fact_extractor/plugins/unpacking/sevenz/code/sevenz.py index 826ce71b..87fd7753 100644 --- a/fact_extractor/plugins/unpacking/sevenz/code/sevenz.py +++ b/fact_extractor/plugins/unpacking/sevenz/code/sevenz.py @@ -31,10 +31,13 @@ 'filesystem/hfs', 'filesystem/ntfs', ] -VERSION = '0.8.1' +VERSION = '0.8.2' UNPACKER_EXECUTABLE = '7z' -PW_LIST = get_merged_password_set(os.path.join(get_src_dir(), 'unpacker/passwords')) + +# Empty password must be first in list to correctly detect if archive has no password +PW_LIST = [""] +PW_LIST.extend(get_merged_password_set(os.path.join(get_src_dir(), 'unpacker/passwords'))) def unpack_function(file_path, tmp_dir): @@ -49,11 +52,11 @@ def unpack_function(file_path, tmp_dir): meta['output'] = output if 'Wrong password' not in output: - if 'AES' in output: + if password: meta['password'] = password break - # Inform the user if not correct password was found + # Inform the user if no correct password was found if 'Wrong password' in meta['output']: logging.warning(f'Password for {file_path} not found in fact_extractor/unpacker/passwords directory') diff --git a/fact_extractor/plugins/unpacking/sevenz/test/data/test_password.zip b/fact_extractor/plugins/unpacking/sevenz/test/data/test_password.zip new file mode 100644 index 00000000..d48705e0 Binary files /dev/null and b/fact_extractor/plugins/unpacking/sevenz/test/data/test_password.zip differ diff --git a/fact_extractor/plugins/unpacking/sevenz/test/test_plugin_sevenz.py b/fact_extractor/plugins/unpacking/sevenz/test/test_plugin_sevenz.py index 02e60f8a..c1b391ae 100644 --- a/fact_extractor/plugins/unpacking/sevenz/test/test_plugin_sevenz.py +++ b/fact_extractor/plugins/unpacking/sevenz/test/test_plugin_sevenz.py @@ -21,14 +21,15 @@ def test_unpacker_selection_generic(self): ('test.rar', 'get_files_test'), ('cramfs.img', ''), ('test.iso', ''), - ], + ] ) def test_extraction(self, test_file, prefix): - self.check_unpacking_of_standard_unpack_set( + meta = self.check_unpacking_of_standard_unpack_set( TEST_DATA_DIR / test_file, additional_prefix_folder=prefix, output=True, ) + assert 'password' not in meta, 'password incorrectly set' @pytest.mark.parametrize( 'test_file, prefix, ignore', @@ -39,16 +40,24 @@ def test_extraction(self, test_file, prefix): ('ext2.img.xz', 'get_files_test', {'Journal'}), ('ext3.img.xz', 'get_files_test', {'Journal'}), ('ext4.img.xz', 'get_files_test', {'Journal'}), - ], + ] ) def test_extraction_compressed(self, test_file, prefix, ignore): with decompress_test_file(TEST_DATA_DIR / test_file) as file: - self.check_unpacking_of_standard_unpack_set( + meta = self.check_unpacking_of_standard_unpack_set( file, output=True, additional_prefix_folder=prefix, ignore=ignore ) + assert 'password' not in meta, 'password incorrectly set' - def test_extraction_password(self): + @pytest.mark.parametrize( + 'test_file', + [ + 'test_password.7z', + 'test_password.zip' + ] + ) + def test_extraction_password(self, test_file): meta = self.check_unpacking_of_standard_unpack_set( - TEST_DATA_DIR / 'test_password.7z', additional_prefix_folder='get_files_test', output=True + TEST_DATA_DIR / test_file, additional_prefix_folder='get_files_test', output=True ) assert meta['password'] == 'test', 'password info not set'