【问题标题】:Open Password Protected zip file with python使用 python 打开受密码保护的 zip 文件
【发布时间】:2023-09-05 19:19:01
【问题描述】:

我正在尝试打开一个受保护的 zip 文件,我知道前 5 个字符是 Super 并且密码长度为 8 个字符,没有数字或符号我在 python 中使用此代码来帮助我,但事实并非如此工作有人可以帮忙吗?

代码:

import zipfile
import itertools
import time

# Function for extracting zip files to test if the password works!
def extractFile(zip_file, password):
try:
    zip_file.extractall(pwd=password)
    return True
except KeyboardInterrupt:
    exit(0)
except Exception as e:
    pass

# The file name of the zip file.
zipfilename = 'planz.zip'
# The first part of the password.
first_half_password = 'Super'
# We don't know what characters they add afterwards...
alphabet = 'abcdefghijklmnopqrstuvwxyz'
zip_file = zipfile.ZipFile(zipfilename)

# For every possible combination of 3 letters from alphabet...
for c in itertools.product(alphabet, repeat=3):
   # Add the three letters to the first half of the password.
   password = first_half_password+''.join(c)
   # Try to extract the file.
   print("Trying: %s" % password)
   # If the file was extracted, you found the right password.

   if extractFile(zip_file, password):
       print('*' * 20)
       print('Password found: %s' % password)
       print('Files extracted...')
       exit(0)

# If no password was found by the end, let us know!
print('Password not found.')

【问题讨论】:

  • 不工作意味着您收到错误,如果是,请提供错误?
  • 它正在工作,但它正在打印 Password not found
  • 你没有检查大写字母
  • 我该怎么做?

标签: python brute-force password-recovery


【解决方案1】:

嘿,伙计!基本上,你可以只附加字母变量来包含大写字母,密码是超人的游戏,如果我没记错的话

【讨论】:

    【解决方案2】:

    问题是, 如果提取文件(zip_file,密码): 在许多情况下,密码错误也是如此。 (见:https://bugs.python.org/issue18134)然后它会留下一个长度为 0 或一些字节的“解压缩文件”。

    您必须检查输出文件的大小是否正确。

    例如通过找出 zip 中第一个文件的大小

    zip_file = zipfile.ZipFile(zipfilename)
    
    firstmember=zip_file.namelist()[0]
    firstmembersize=zip_file.getinfo(firstmember).file_size
    

    以后

    if os.path.getsize(firstmember) == firstmembersize:
    

    并且不要忘记在检查后删除错误大小的文件以便下次尝试...

    【讨论】:

      最近更新 更多