python中的暴力攻击程序不起作用
我开发了一个zipfile密码破解程序,可以进行暴力攻击。zipfile的密码是1234。当我运行程序时,它会给我以下错误:python中的暴力攻击程序不起作用,python,zipfile,cracking,Python,Zipfile,Cracking,我开发了一个zipfile密码破解程序,可以进行暴力攻击。zipfile的密码是1234。当我运行程序时,它会给我以下错误: Traceback (most recent call last): File "C:\Users\Kartikey\Desktop\cracking\bruteforce\bruteforce.py", line 51, in <module> zf.extractall(password) File "C:\Python27\lib\zip
Traceback (most recent call last):
File "C:\Users\Kartikey\Desktop\cracking\bruteforce\bruteforce.py", line 51, in <module>
zf.extractall(password)
File "C:\Python27\lib\zipfile.py", line 1040, in extractall
self.extract(zipinfo, path, pwd)
File "C:\Python27\lib\zipfile.py", line 1028, in extract
return self._extract_member(member, path, pwd)
File "C:\Python27\lib\zipfile.py", line 1069, in _extract_member
targetpath = os.path.join(targetpath, arcname)
File "C:\Python27\lib\ntpath.py", line 84, in join
result_path = result_path + '\\'
TypeError: can only concatenate tuple (not "str") to tuple
有什么想法吗?
itertools。将_与_replacement()的组合生成包含单个字符的元组,而不是字符串:
>>> import itertools
>>> gen = itertools.combinations_with_replacement('1234', 3)
>>> next(gen)
('1', '1', '1')
使用'.join()
将它们组成一个字符串:
password = ''.join(password)
但是请注意,zf.extractall()
的第一个参数是路径,而不是密码。您正在尝试将内容提取到由生成的密码命名的路径。我怀疑那是你想做的
使用pwd
关键字参数指定密码:
zf.extractall(pwd=password)
@卡提基库什瓦哈:请不要把你的问题改成问什么是新问题。这将是一篇新文章的主题。您的密码错误,请捕获该异常并尝试新密码。@machineyearning:我知道您的意思是好的,但您的措辞不太正确。发布一个错误和你的相关代码是优秀的。是的,更多的研究会有帮助,但许多初学者不知道如何做到这一点。这不是一个糟糕的问题。@MartijnPieters谢谢你的澄清,很抱歉我的措辞不准确。我想的不是网站的规则,而是培养长期的工程研究技能。在我看来,学习将问题陈述细化到可以提出好问题的程度,对任何程序员来说都是一项关键技能。无论如何,我不会在评论部分拖太长时间。不过评论收回了。
zf.extractall(pwd=password)