Zipfile方法不起作用

Rad*_*ast 3 python zipfile python-3.x

我使用rockyou密码创建了一个zip文件,并尝试提取所有文件。但是我遇到了一些问题。无论我总是如何输入extractall中的密码,我都会得到:

('Bad password for file', <zipfile.ZipInfo object at 0x7f7928d14dc8>)
Run Code Online (Sandbox Code Playgroud)

码:

import zipfile

zfile = zipfile.ZipFile("./rockyou.zip")

pss = b"rockyou"

try:
    zfile.extractall(pwd = pss)

except RuntimeError as e:
    print(e)
    zfile.close()
Run Code Online (Sandbox Code Playgroud)

如果我传递字符串,则会遇到另一个问题:

TypeError: pwd: expected bytes, got <class 'str'>
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

pss = str.encode("rockyou")
Run Code Online (Sandbox Code Playgroud)

和:

pss = bytes(str.encode("rockyou"))
Run Code Online (Sandbox Code Playgroud)

和:

pss = bytes("rockyou".encode("UTF-8"))
Run Code Online (Sandbox Code Playgroud)

有人帮忙吗?

Ama*_*Gûl 7

好吧,我找到了一种解决方法,对我有用,可能并不那么漂亮...

  zFile.extractall(pwd = 'PASSWORD'.encode('cp850','replace'))
Run Code Online (Sandbox Code Playgroud)


Ner*_*f D 5

我一直在阅读暴力的python书籍,在第一章中,您制作了一个迷你脚本来解锁加密的zip文件。对我有用的是添加一个,b以便字符串以字节为单位:

import zipfile
zFile = zipfile.ZipFile("evil.zip")
zFile.extractall(pwd=b'secret') #this is what i'm talking about
Run Code Online (Sandbox Code Playgroud)