如何解决暴力破解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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。