通过暴力破解密码保护的.zip文件。

问题描述 投票:-1回答:1

我想通过暴力攻击进入一个受密码保护的.zip文件。

然而,每次密码试验都会返回这个错误。

Bad password for file {{fileName}}

这是我的代码

import zipfile
import itertools
import time

# Function for extracting zip files to test if the password works!
def extractFile(zip_file, password):
    try:
        zip_file.extractall(pwd=password)
        return True
    except KeyboardInterrupt:
        exit(0)
    except Exception as e:
        print(e)

# Main code starts here

# The file name of the zip file
zipfilename = 'C:/Users/Lenovo/Desktop/DevFiles/CyberDisc/planz.zip'

# The first part of the password. We know this for sure!
first_half_password = 'Super'

# We don't know what characters they add afterwards
# This is case sensitive!
alphabet = 'abcdefghijklmnopqrstuvwxyz'
zip_file = zipfile.ZipFile(zipfilename)

# We know they always have 3 characters after Super...

# So for every possible combination of 3 letters from alphabet:
for c in itertools.product(alphabet, repeat=3):

    # Slowing it down on purpose to make it work better with the web terminal
    # Remove at your peril
    time.sleep(0.001)

    # Add the three letters to the first half of the password
    password = first_half_password+''.join(c)
    password = password.encode('utf-8')

    # Try to extract the file
    print("Trying: %s" % password)

    # If the file was extracted, you found the right password.
    if extractFile(zip_file, password):
        print('*' * 20)
        print('Password found: %s' % password)
        print('Files extracted...')
        exit(0)

# If no password was found by the end, output this
print('Password not found.')

以下是程序运行后的shell内容

我不知道自己做错了什么。请谁能帮我解决这个问题?

python file passwords zip brute-force
1个回答
0
投票

在字母表中,我只包括小写字母。

alphabet = 'abcdefghijklmnopqrstuvwxyz'

我应该把大写字母也包括进去的。

alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
© www.soinside.com 2019 - 2024. All rights reserved.