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

问题描述

我遇到了一个要解决的问题,要求再给“超级”添加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.'

但是我的代码返回了

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

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

解决方法

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

#! /usr/bin/env python2

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...