Skip to content

Commit

Permalink
Merge pull request fkie-cad#134 from eclipsotic/sevenz_fixes
Browse files Browse the repository at this point in the history
Accurately record whether a 7z-supported file did/didn't require a password to extract
  • Loading branch information
jstucke authored Apr 29, 2024
2 parents 1967403 + 2bab0e9 commit 12cf355
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
11 changes: 7 additions & 4 deletions fact_extractor/plugins/unpacking/sevenz/code/sevenz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')

Expand Down
Binary file not shown.
21 changes: 15 additions & 6 deletions fact_extractor/plugins/unpacking/sevenz/test/test_plugin_sevenz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'

0 comments on commit 12cf355

Please sign in to comment.