from zipfile import ZipFile
fzip=ZipFile("crackme.zip")
fzip.extractall(pwd=b"mysecretpassword")
该脚本仅适用于IDLE,但是当我从命令行运行它时,它会显示:
unzip.py
fzip.extractall(PWD = b “的mysecretpassword”)
^
SyntaxError:语法无效
出了什么问题?
答案 0 :(得分:1)
它有效(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
应该是字节对象:
>>> 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')
>>>
根据zipfile.ZipFile.extractall
documentation:
警告未经事先检查,切勿从不受信任的来源提取档案。文件可能是在外面创建的 路径,例如具有以“/”开头的绝对文件名的成员 文件名有两个点“..”。
在版本3.3.1中更改:zipfile模块尝试阻止它。请参阅
extract()
注释。