您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“怎么利用python破解zip加密文件”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來(lái)帶大家學(xué)習(xí)“怎么利用python破解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
本文介紹的zip文件知道密碼一共是4位的,密碼字符的范圍是a-z1-0。并且不存在重復(fù)字符的,不會(huì)有“aabb”的密碼。zip壓縮時(shí)是選擇了zip傳統(tǒng)加密!
導(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
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):
查過(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í)!
免責(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)容。