Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Zipfile compression method is not supported

The times when this worked were when I used ZIPCrypto compression. It's with AES-256 that it fails. How to get around this please?

I previously had success using the following Python code to open a password protected .zip file created with 7-Zip:

import zipfile

zip_file = zipfile.ZipFile('crack_me.zip')
output_verbose = 1  # increase that for long password list
with open('passwords.txt', 'rb') as password_list:
    for index, line in enumerate(password_list):
        try:
            pwd = line.strip(b'\r\n')
            zip_file.extractall(pwd=pwd)
        except RuntimeError as e:
            print(e)
            if index % output_verbose == 0:
                print('{}. The {} word not matched.'.format(index + 1, pwd))
        else:
            print('{}. Wow ! found the password: {}'.format(index + 1, pwd))
            break

zip_file.close()

However, for no understandable reason, it has only worked a couple of times out of many attempts. Most times is gives "That compression method is not supported" for the exception.

I've tried deleting, renaming, re-creating the .zip file but no success. It makes no sense to me that it works occasionally.

I tried to simplify the issue as below:

import zipfile

zip_file = zipfile.ZipFile('crack_me.zip')
try:
    zip_file.extractall(pwd=b"password")
    print('Opened')
except RuntimeError as e:
    print(e)

But I get the same exception. I've tried variations of pwd such as bytes("password", "utf-8) and others.

The provided password opens the .zip file when opening with 7-Zip.

What is going on here please?

like image 299
Robin Andrews Avatar asked Jun 17 '26 07:06

Robin Andrews


1 Answers

Try using pyzipper. Here is a sample script:

import pyzipper


password = 'abc'

with pyzipper.AESZipFile('yourdocument.zip', 'r', compression=pyzipper.ZIP_DEFLATED, encryption=pyzipper.WZ_AES) as extracted_zip:
    extracted_zip.extractall(pwd=str.encode(password))
like image 149
Tomas velez Avatar answered Jun 19 '26 20:06

Tomas velez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!