From 2bab0e94174fac099375a8d1e6a423a1f3f1d784 Mon Sep 17 00:00:00 2001 From: eclipsotic Date: Wed, 24 Apr 2024 16:21:45 -0400 Subject: [PATCH] Accurately record whether a 7z-supported file did/didn't require a password to extract --- .../plugins/unpacking/sevenz/code/sevenz.py | 11 +++++---- .../sevenz/test/data/test_password.zip | Bin 0 -> 1006 bytes .../sevenz/test/test_plugin_sevenz.py | 21 +++++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 fact_extractor/plugins/unpacking/sevenz/test/data/test_password.zip 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 0000000000000000000000000000000000000000..d48705e03bd1905d5d609d224b9e1cb409a3f57a GIT binary patch literal 1006 zcmWIWW@Zs#W&naIM*8j`8V2}*jP%r!__WNN)Z+M()Z!BT0Gx{DFcqh#=A{;8CM%@n z=cJ?-LG>~M)qyNxFFZ6;0mv2sVm%;6vj|Nu$Z`dcI~0uL^-3yAc1`>C!=N*y#5MKs zkzeU6RhtC92d5;SIG(d2=gZ9HTMt0o3A0Pu{L)J=pdEHVEP-hk$Z(L^hCX}|OEql| zruCUFX7$_3RkJZXV~3-CL{ZI~HP#l|k8CD>S;EcqRG5u(f^T5QW%1He$FK9f)9e$w zbg_G4vmc{udq%h9;#3s|g9udne;heirvbEA2EYAAzhk&J&c45NE!aGZWmEEbrRl)(@j7;{-xFSsjXbT7kG`w{L(P$yd#h?HZWncsa zh0hA@1@A8~HfY2=sGoL=vB5p<7Kp}YfgA&}1-d|!&@4cUI;{3V?LoH>7GbD~17@E> z!;;2Kg7%>&6|DB-@Gs1M)C7ZU|5Z%;;mL;_n^2PmvQ42t$DoBQ%qAn^Y+_{tI+lSI O2vwOF7&e1E#{dAu>l{1) literal 0 HcmV?d00001 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'