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"))
Dharman
  • 30,962
  • 25
  • 85
  • 135
Radagast
  • 509
  • 10
  • 23

2 Answers2

7

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

  zFile.extractall(pwd = 'PASSWORD'.encode('cp850','replace'))
Amarth Gûl
  • 1,040
  • 2
  • 14
  • 33
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
Amarth Gûl
  • 1,040
  • 2
  • 14
  • 33
Nerf D
  • 143
  • 1
  • 8
  • 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 06 '17 at 10:12