【发布时间】:2019-06-23 04:56:58
【问题描述】:
所以我正在重写 TJ O'Connor 在 Violent Python 上发布的 ZIP Cracker,它是用 Python 2.7 编写的。作者使用了optparse,但我使用了argparse。
我的代码如下:
import argparse
from threading import Thread
import zipfile
import io
parser = argparse.ArgumentParser(description="Unzips selected .zip using a dictionary attack", usage="CRARk.py -z zipname.zip -f file.txt")
# Creates -z arg
parser.add_argument("-z", "--zip", metavar="", required=True, help="Location and the name of the .zip file.")
# Creates -f arg
parser.add_argument("-f", "--file", metavar="", required=True, help="Location and the name of the word-list/dictionary-list/password-list.")
args = parser.parse_args()
def extract_zip(zipFile, password):
try:
zipFile.extractall(pwd=password.encode())
print("[+] Password for the .zip: {0}".format(password) + "\n")
except:
pass
def main(zip, dictionary):
if (zip == None) | (dictionary == None):
print(parser.usage)
exit(0)
zip_file = zipfile.ZipFile(zip)
pass_file = io.open(dictionary, mode="r", encoding="utf-8")
for line in pass_file.readlines():
password = line.strip("\n")
t = Thread(target=extract_zip, args=(zip_file, password))
t.start()
if __name__ == '__main__':
# USAGE - Project.py -z zipname.zip -f file.txt
main(args.zip, args.dictionary)
我得到的错误是:
Traceback (most recent call last):
File "C:\Users\User\Documents\Jetbrains\PyCharm\Project\Project.py", line 39, in <module>
main(args.zip, args.dictionary)
AttributeError: 'Namespace' object has no attribute 'dictionary'
现在我有点不确定这意味着什么。我尝试将args.dictionary 重命名为args.file 或类似名称,但是当我运行代码时,最终在我的终端上返回了一个空响应。如下图所示,当我正确运行 .py 时,没有响应/输出等。
我该如何解决这个问题?
【问题讨论】:
-
您将参数命名为
--file,并且尝试访问args.dictionary。当然没有args.dictionary。 -
所以我应该使用
args.file而不是args.dictionary?但是话又说回来,这并不能解释当我使用args.file而不是args.dictionary时运行程序得到的空响应 -
解密失败。
-
看来你是对的@user2357112。但是我不明白为什么当我从raw.githubusercontent.com/ncorbuk/… 的密码中选择一个密码然后用它来制作一个简单的受密码保护的.zip 时它会失败。我将该粘贴为 .txt,另存为“最常见的 10k 密码”(如图所示)。不知道出了什么问题,因为我使用随机选择的几个词创建了一个类似的 zip 并且它有效。所以不太清楚为什么我不能使用更大的字典/密码列表/单词列表来暴力破解。
标签: python python-3.x argparse optparse