0
votes
from zipfile import ZipFile


fzip=ZipFile("crackme.zip")
fzip.extractall(pwd=b"mysecretpassword")

the script works only on IDLE, but when i run it from the command line, it displays:

unzip.py

fzip.extractall(pwd=b"mysecretpassword")

                              ^

SyntaxError: invalid syntax

what's wrong?

1
Are you sure you are using Python 3? The extractall() method was added in 2.6, so versions prior to that would not have it. - Markku K.
i'm working on Python 3.3.0 - user2816162
You might consider asking a new question, since the title of your question is no longer relevant. - Markku K.

1 Answers

1
votes

It works (Ubuntu 13.04):

>>> import sys
>>> sys.version
'3.3.1 (default, Apr 17 2013, 22:32:14) \n[GCC 4.7.3]'

>>> from zipfile import ZipFile
>>> f = ZipFile('a.zip')

BTW, pwd should be bytes objects:

>>> f.extractall(pwd="mysecretpassword")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.3/zipfile.py", line 1225, in extractall
    self.extract(zipinfo, path, pwd)
  File "/usr/lib/python3.3/zipfile.py", line 1213, in extract
    return self._extract_member(member, path, pwd)
  File "/usr/lib/python3.3/zipfile.py", line 1275, in _extract_member
    with self.open(member, pwd=pwd) as source, \
  File "/usr/lib/python3.3/zipfile.py", line 1114, in open
    raise TypeError("pwd: expected bytes, got %s" % type(pwd))
TypeError: pwd: expected bytes, got <class 'str'>
>>> f.extractall(pwd=b'mysecretpassword')
>>>

According to zipfile.ZipFile.extractall documentation:

Warning Never extract archives from untrusted sources without prior inspection. It is possible that files are created outside of path, e.g. members that have absolute filenames starting with "/" or filenames with two dots "..".

Changed in version 3.3.1: The zipfile module attempts to prevent that. See extract() note.