用python 2强制一个zip文件

时间:2018-02-28 17:33:13

标签: python-2.7 zip

我需要打开一个zip并提取内容。密码以" Super"开头。之后有三个字母。 我已经获得了大部分代码,但它无法正常工作。 任何人都可以看到错误,因为它实际上并没有显示错误,它只是无法正常工作。

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, e:
        pass

# Main code starts here...
# The file name of the zip file.
zipfilename = '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...
# 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)
    # Try to extract the file.
    print "Trying: %s" % password
    extractFile(zip_file, 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)
        break

# If no password was found by the end, let us know!
print 'Password not found.'

1 个答案:

答案 0 :(得分:0)

我知道您在网络启动时在作弊,但无论如何: 您的字母缺少一些字符。如果密码包含大写字母,数字或标点符号怎么办?

alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

应该这样做