暴力破解zip文件,带密码返回语法错误

问题描述

@H_502_0@我遇到了一个解决的问题,要求再给“超级”添加3个字母,然后用它来解锁一个zip文件。我的代码如下:

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 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMnopQRSTUVWXYZ'
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
    # 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,let us kNow!
print 'Password not found.'
@H_502_0@但是我的代码返回了

@H_502_0@ ./ code.py:第6行:意外令牌('./code.py: line 6: def extractFile(zip_file,password)附近的语法错误:'

@H_502_0@什么是语法错误,因为我找不到它?

解决方法

您必须添加一个shebang: 在第一行中添加

#! /usr/bin/env python2