所以我正在重写一个ZIP破解器,它是由TJ‘’Connor在Python2.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时,没有响应/输出等。

我怎么才能解决这个问题?
发布于 2019-01-30 01:27:49
使用代码中的part解析部分:
import argparse
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()
print(args)样本运行:
2033:~/mypy$ python3 stack54431649.py -h
usage: CRARk.py -z zipname.zip -f file.txt
Unzips selected .zip using a dictionary attack
optional arguments:
-h, --help show this help message and exit
-z , --zip Location and the name of the .zip file.
-f , --file Location and the name of the word-list/dictionary-
list/password-list.
1726:~/mypy$ python3 stack54431649.py
usage: CRARk.py -z zipname.zip -f file.txt
stack54431649.py: error: the following arguments are required: -z/--zip, -f/--file
1726:~/mypy$ python3 stack54431649.py -z zippy -f afile
Namespace(file='afile', zip='zippy')这意味着我可以使用
args.file # 'afile'
args.zip # 'zippy'
main(args.zip, args.file)在main中
if zip is None: # better than zip == None但是,由于这两个参数是必需的,所以它们永远不会是None。
接下来的问题是,zip的值是否是有效zip文件的名称,以及是否可以打开dictionary。
https://stackoverflow.com/questions/54431649
复制相似问题