溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么利用python破解zip加密文件

發(fā)布時(shí)間:2022-05-23 09:17:45 來(lái)源:億速云 閱讀:419 作者:iii 欄目:開(kāi)發(fā)技術(shù)

本篇內(nèi)容主要講解“怎么利用python破解zip加密文件”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么利用python破解zip加密文件”吧!

一、破解zip加密文件的思路

  • 準(zhǔn)備一個(gè)加密的zip文件。

  • zipfile模塊可以解壓zip文件。

解壓時(shí)可以提供密碼zfile.extractall("./", pwd=password.encode("utf8"))

  • itertools.permutations實(shí)現(xiàn)全字符的全排列。

通過(guò)函數(shù)itertools.permutations("abc", 3)實(shí)現(xiàn)全字符的全排列:abc/acb/bca/bac/cab/cba

二、實(shí)例代碼演示

0、zip的壓縮方式

本文介紹的zip文件知道密碼一共是4位的,密碼字符的范圍是a-z1-0。并且不存在重復(fù)字符的,不會(huì)有“aabb”的密碼。zip壓縮時(shí)是選擇了zip傳統(tǒng)加密!

1、解壓zip文件

導(dǎo)入zipfile模塊,使用其中的extractall()函數(shù)。

import itertools
filename = "readme.zip"
# 創(chuàng)建一個(gè)解壓的函數(shù),入?yún)槲募兔艽a
# 并使用try-except,避免報(bào)錯(cuò)中斷程序。
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False

2、實(shí)現(xiàn)密碼字符的全排列

import zipfile
import itertools
filename = "readme.zip"
# 創(chuàng)建一個(gè)解壓的函數(shù),入?yún)槲募兔艽a
# 并使用try-except,避免報(bào)錯(cuò)中斷程序。
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False
# chars是密碼可能的字符集
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
for c in itertools.permutations(chars, 4):
    password = ''.join(c)
    print(password)
    result = uncompress(filename, password)
    if not result:
        print('解壓失敗。', password)
    else:
        print('解壓成功。', password)
        break

文件壓縮時(shí),一些注意的事項(xiàng): 

怎么利用python破解zip加密文件

三、密碼是幾位未知,也可以破解密碼

查過(guò)一些資料,zip壓縮文件密碼最長(zhǎng)為12位,在原來(lái)的程序上增加上一個(gè)for循環(huán)就可以實(shí)現(xiàn)破解密碼了。

import zipfile
import itertools
filename = "readme.zip"
def uncompress(file_name, pass_word):
    try:
        with zipfile.ZipFile(file_name) as z_file:
            z_file.extractall("./", pwd=pass_word.encode("utf-8"))
        return True
    except:
        return False
chars = "abcdefghijklmnopqrstuvwxyz0123456789"
for i in range(12):
    for c in itertools.permutations(chars, i):
        password = ''.join(c)
        print(password)
        result = uncompress(filename, password)
        if not result:
            print('解壓失敗。', password)
        else:
            print('解壓成功。', password)
            break

到此,相信大家對(duì)“怎么利用python破解zip加密文件”有了更深的了解,不妨來(lái)實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI