用Python解决忘记压缩包密码的问题(日常实战)
python脚本化处理
1、基本思路
首先如果想要python命令行来打开相册,那么首先要找到尝试打开的命令行,即解压缩时使用的命令行。然后我们使用python脚本写嵌套循环,不断的对zip文件进行尝试解压,然后找回真实的密码。
2、解压命令
首先压缩文件是zip格式的,我们使用万能的7z命令来进行解压。
为什么不用unzip命令呢?(因为unzip无法循环?)
3、解压命令参数分析
#7Z详细参数,下面只截取几个关键参数
PS C:\Users\lex> 7z
7-Zip 21.01 alpha (x64) : Copyright (c) 1999-2021 Igor Pavlov : 2021-03-09
Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]
<Commands>
a : Add files to archive #加入压缩
d : Delete files from archive
e : Extract files from archive (without using directory names)
t : Test integrity of archive #尝试密码,不解压
...
<Switches>
-o{Directory} : set Output directory
-p{Password} : set Password #设置密码参数
4、整理7z解压命令
命令太简单,感觉都有点配不上我的才华和思路
7z -p 123456 t 相册.zip
# t:尝试打开,类似后台运行
# -p:尝试的密码
# 最后是要解压的文件
5、关门!上python脚本
根据记忆,密码好像是6位纯数字密码。
只对6位纯数字进行尝试就可以了。
# -*- coding:utf-8 -*-
import os
import subprocess
import zipfile
def brutecrack():
for a in range(1,10):
for b in range(1,10):
for c in range(1,10):
for d in range(1,10):
for e in range(1,10):
for f in range(1,10):
passwd=str(a)+str(b)+str(c)+str(d)+str(e)+str(f)
command='7z -p'+passwd+' t F:/相册.zip' #t 表示test,不进行实际解压,只测试密码
print(passwd)
child=subprocess.call(command)
#os.popen(command)#这个也可以用,但是不好监控解压状态
print(child)
if child==0:
print("相册密码为:"+passwd)
return
if __name__ == '__main__':
brutecrack()
正文到此结束