掌握基础语法后,尝试使用python的zipfile模块练手。

zipfile是Python里用来做zip格式编码的压缩和解压缩的。

这里将大体的思路分解成四段代码,逐一完善功能;

第一段代码:解压zip

首先了解python解压zip文件的库

import zipfile

# 定义通用解压函数
def tryZipPwd(zFile,savePath,pw =None): # 如果密码是空就直接解压,使用异常判断
try:
# 如果密码为空就直接解压
if pw == None:
zFile.extractall(path=savePath)
else:
# 将密码转换为utf-8编码
zFile.extractall(path=savePath,pwd=pw.encode('utf-8'))
print('[+] ZIp文件解压成功,密码:%s' %(pw))
return True
except:
print('[-]Zip文件解压失败,密码:%s' % (pw))
return False

第二段 解压zip函数的使用

将通用解压zip的函数,传入参数引用就可以了

# 指定密码打开Zip文件,密码是123qwer
#with zipfile.ZipFile('C:/Users/Windows32/Desktop/untitled/sucess.zip') as zFile:
# tryZipPwd(zFile,'C:/Users/Windows32/Desktop/untitled/','1234qwer')

第三段代码 读取文件内容

python逐行读取文件内容的三种方法;

方法1:

f = open("foo.txt")             # 返回一个文件对象
line = f.readline() # 调用文件的 readline()方法
while line:
print line, # 后面跟 ',' 将忽略换行符
# print(line, end = '')   # 在 Python 3中使用
line = f.readline() f.close()

方法2:

for line in open("foo.txt"):
print line,

方法3:

f = open("c:\\1.txt","r")
lines = f.readlines()#读取全部内容
for line in lines
print line

第四段代码-读取密码文本,批量传入密码尝试解压zip文件

综合以上的代码就可以实现zip压缩包的密码破解了,pass.txt是CSDN泄露的TOP100常用密码,写了for循环与while循环的代码;

# -*- coding: utf-8 -*-
import zipfile # 定义通用解压函数
def tryZipPwd(zFile,savePath,pw =None): try:
if pw == None:
zFile.extractall(path=savePath)
else:
zFile.extractall(path=savePath,pwd=pw.encode('utf-8'))
print('[+] ZIp文件解压成功,密码:%s' %(pw))
return True
except:
# print('[-]Zip文件解压失败,密码:%s' % (pw))
return False # 指定密码打开Zip文件
#with zipfile.ZipFile('C:/Users/Windows32/Desktop/untitled/sucess.zip') as zFile:
# tryZipPwd(zFile,'C:/Users/Windows32/Desktop/untitled/','1234qwer') # 逐行读取文本里的密码,然后传入通用解压函数中
passFile = open('C:/Users/Windows32/Desktop/untitled/pass1.txt') # for循环
# 当破解成功后退出程序与关闭文件流
for i in open('C:/Users/Windows32/Desktop/untitled/pass1.txt'):
# 将文本里的换行清除
password = i.strip('\n')
with zipfile.ZipFile('C:/Users/Windows32/Desktop/untitled/sucess.zip') as zFile:
# 传回函数执行状态,如果返回结果为真,就代表解压zip文件成功,输出当前的密码
flag = tryZipPwd(zFile,'C:/Users/Windows32/Desktop/untitled/',password)
if flag:
print("sucess pass is %s" % (i))
exit(0)
passFile.close()
i = passFile.readline()
passFile.close() # while循环
line = passFile.readline()
while line:
line = line.strip('\n')
with zipfile.ZipFile('C:/Users/Windows32/Desktop/untitled/sucess.zip') as zFile:
flag = tryZipPwd(zFile,'C:/Users/Windows32/Desktop/untitled/',line)
if flag:
print("sucess pass is %s" % (line))
exit(0)
passFile.close()
line = passFile.readline()
passFile.close()

【Python】zip文件密码破解的更多相关文章

  1. python zip文件密码爆破

    #!/usr/bin/env # coding=UTF-8 import zipfile import threading import os import sys class CrackZip: d ...

  2. 有个计算机专业的学妹问我:我这个zip文件密码破解运行起来为什么内存爆了?

    1.这篇博文的由来 2.跑下错误代码,找病根 先把学妹发给我的错误代码放上,能发现他为了提高速度加了多线程的代码,很聪明哦: import zipfile import itertools from ...

  3. Python与Hack之Zip文件口令破解

    1.需要的库: **import zipfile**import optparse**from threading import Thread(1)zipfile:1.1 zipfile.ZipFil ...

  4. 12.持久性后门----Ettercap之ARP中毒----RAR/ZIP & linux密码破解----kali上检测rootkits

    持久性后门 生成PHP shell weevely generate 密码 /root/Desktop/404.php 靶机IP/404.php weevely http://192.168.1.10 ...

  5. 暴力破解ZIP文件密码

    Python 的标准库提供了 ZIP 文件的提取压缩模块 zipfile,现在让我们试着用这个模块,暴力破解出加密的 ZIP 文件!我们可以用 extractall()这个函数抽取文件,密码正确则返回 ...

  6. 【pyhon】黑客用字典暴力破解Zip文件密码原理性展示

    基本原理:用程序把字典文件里拟定好的密码一个个提取出来,去测试zip能否打开 字典文件pass.txt内容: 1224 2121 asdf abcd1234 dwsdsd dssds 程序代码: # ...

  7. zip压缩包密码破解

    有一种破解方法叫做Known plaintext attack.市面上的密码破解软件几乎都带有这个功能.操作方法就是找到加密压缩包中的任意一个文件,用同样的压缩软件同样的压缩方式压缩成一个不加密的包, ...

  8. office文件密码破解方法及软件

    今天会用到3个软件 1.Office Password Remover 说明:这个软件可以很快破解.doc   .xls的密码 使用方法:参考百度经验里面的文章http://jingyan.baidu ...

  9. python zip文件压缩和解压

    压缩 import shutil zipOutputName = "1234" # 输出1234.zip fileType = "zip" # 文件类型zip ...

随机推荐

  1. day5 if else elif 判断语句

    age_of_princal = 56 guess_age = int( input(">>:") ) '''伪代码,提供思路用 if guess_age == age ...

  2. Linux 系统免密码登陆远程服务器

    在当前Linux生成公钥私钥ssh-keygen公钥私钥存放路径为:~/root/.ssh/id_rsa id_rsa.pub 登陆被远程主机,进入目录~/root/.ssh/是否存在authoriz ...

  3. 自学Linux Shell3.6-文件查看命令file cat more less tail head

    点击返回 自学Linux命令行与Shell脚本之路 3.6-文件查看命令file cat more less tail head 1.参看文件类型file 该命令用来识别文件类型,也可用来辨别一些文件 ...

  4. # BZOJ5300 [CQOI2018]九连环 题解 | 高精度 FFT

    今天做了传说中的CQOI六道板子题--有了一种自己很巨的错觉(雾 题面 求n连环的最少步数,n <= 1e5. 题解 首先--我不会玩九连环-- 通过找规律(其实是百度搜索)可知,\(n\)连环 ...

  5. (转)搭建Maven私服(使用Nexus)

    搭建私服可以做什么? 1.如果公司开发组的开发环境全部内网,这时如何连接到在互联网上的Maven中央仓库呢? 2.如果公司经常开发一些公共的组件,如何共享给各个开发组,使用拷贝方式吗?如果这样,公共库 ...

  6. chrome 显示图片遇到的问题,与 淘宝图片服务器 缓存 有关系

    最近发现使用淘宝的jae环境,一个 abc.jsp 地址,随机跳转到淘宝图片空间里任意的一张图片. 但在chrome浏览器发现一个奇怪的问题: 用户第一次访问 abc.jsp  -> 302 f ...

  7. Node.js npm uuid

    nodejs 提供了一个 node-uuid 模块用于生成 uuid 使用方法为 const uuidV1 = require('uuid/v1'); uuidV1(); 或者为 const uuid ...

  8. apigateway-kong(五)集群搭建部署

    kong 集群将使得系统通过增加更多机器,从而实现水平扩展,承接更多的请求流量.它们将共享同样的配置且使用同一个数据库.kong 集群中的的所有节点都连接同一个数据库. 你需要在 kong 集群的上一 ...

  9. POJ - 3122 Pie(二分)

    http://poj.org/problem?id=3122 题意 主人过生日,m个人来庆生,有n块派,m+1个人(还有主人自己)分,问每个人分到的最大体积的派是多大,PS每 个人所分的派必须是在同一 ...

  10. VS新建项目工具箱图标丢失问题

    (1)在电脑里搜索*.tbd文件(2)建一个项目,把需要的工具箱图标加载上,退出 VS. (3)复制一份toolbox.tbd,重命名为toolbox_reset.tbd 然后以后新建项目就可以了.这 ...