3

I create a zip file with rockyou password and I tried to extractall files. But I got some issues. Doesn't matter how password I put in extractall always I will get:

('Bad password for file', <zipfile.ZipInfo object at 0x7f7928d14dc8>)

Code:

import zipfile

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

pss = b"rockyou"

try:
    zfile.extractall(pwd = pss)

except RuntimeError as e:
    print(e)
    zfile.close()

If I pass a string I got another issue:

TypeError: pwd: expected bytes, got <class 'str'>

And I tried too:

pss = str.encode("rockyou")

And:

pss = bytes(str.encode("rockyou"))

And:

pss = bytes("rockyou".encode("UTF-8"))
18
  • 1
    why are you converting to bytes? why not just pass as string?
    – R Nar
    Nov 6, 2015 at 23:26
  • also, don't use pass as it's a reserved word
    – William
    Nov 6, 2015 at 23:27
  • 1
    Please confirm that you can open the file, with that password, using a standard zip program.
    – Kevin
    Nov 6, 2015 at 23:33
  • 1
    have you seen this?
    – R Nar
    Nov 6, 2015 at 23:33
  • 1
    an ugly (but functional) solution is: os.system('7z e -y -p"password" filename.zip') after importing os
    – William
    Nov 7, 2015 at 0:01

2 Answers 2

7

Well, I found a way to fix that, works for me, may not so beautiful...

  zFile.extractall(pwd = 'PASSWORD'.encode('cp850','replace'))
1
  • Thank you for that, was getting TypeError: pwd: expected bytes, got <class 'str'>
    – gaut
    Nov 1, 2018 at 18:46
6

I've been following the violent python book and in Chapter one you make a mini script to unlock a encrypted zip file. what worked for me was to add a b so the string would be in bytes:

import zipfile
zFile = zipfile.ZipFile("evil.zip")
zFile.extractall(pwd=b'secret') #this is what i'm talking about
1
  • as commented above, looks like that is a compatibility issue between zipfiles encryption, so if you encrypt your file with AES-256 will get the error. i don't know if was fixed, but the correct way is passing bytes in pwd-param and encrypt your file with zipcrypto encription mode.
    – Radagast
    Jun 6, 2017 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.