Python暴力破解zip文件密码

21次阅读
没有评论

共计 599 个字符,预计需要花费 2 分钟才能阅读完成。

import os
import time
from zipfile import ZipFile
import itertools as its

def create_pwd(words, len):
    for i in range(1, len + 1):
        base = its.product(words, repeat=i)
        for b in base:
            yield "".join(b)

def crack_zip(path, pwd):
    type_ = os.path.splitext(path)[-1][1:]
    if type_ == "zip":
        with ZipFile(path, "r") as zip:
            try:
                zip.extractall("./unzip", pwd=str(pwd).encode("utf-8"))
                end_time = time.time()
                print(f" 解压密码:{pwd}")
                print(f" 花费时间:{round(end_time-start_time, 2)} 秒 ")
                return True
            except Exception as e:
                print(pwd, e)

if __name__ == "__main__":
    start_time = time.time()
    words = "1234567890abc"
    length = 6
    for p in create_pwd(words, length):
        flag = crack_zip("./pdl1.zip", p)
        if flag:
            break

正文完
post-qrcode
 0
三毛
版权声明:本站原创文章,由 三毛 于2023-10-23发表,共计599字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)