zip 偽加密 Python處理指令碼

2021-07-27 16:38:27 字數 2724 閱讀 8613

乙個zip檔案沒有設定密碼,但是你可以讓它看起來有密碼

原理

加密標誌位在general purpose bit flag中,從後向前數,第乙個bit為1,表示有加密

查詢zip的加密標誌位,將其置為0即可恢復

4.3.7  local file header:

local file header signature 4 bytes (0x04034b50)

version needed to extract 2 bytes

general purpose bit flag 2 bytes

4.3.12 central directory structure:

[central directory header 1]..

. [central directory header n]

[digital signature]

file header:

central file header signature 4 bytes (0x02014b50)

version made by 2 bytes

version needed to extract 2 bytes

general purpose bit flag 2 bytes

4.4.4 general purpose bit flag: (2 bytes)

bit 0: if set, indicates that the file is encrypted.

可以用winhex等16進製制編輯器來修改(010editor可能比較方便),也可以通過指令碼處理回沒有偽加密的狀態

python處理指令碼如下

# coding:utf8

'''zip偽加密去除指令碼

'''import sys

import re

def removefade(para1):

# 讀取原zip檔案

zipfile = open(para1,'rb')

zipfile_content = zipfile.read().encode('hex')

zipfile.close()

# 定位加密標誌位並清零

# local file header

about_global_enc_flag_re = r'504b0304.'

match_contents = re.findall(about_global_enc_flag_re, zipfile_content)

if match_contents:

print '[*] modify local file header flag:'

for match_content in match_contents:

modified_content = match_content[:12] + hex(int(match_content[12:14], 16) & 0b11111110)[2:].zfill(2) + match_content[14:]

print ' ' + match_content + ' --> ' + modified_content

zipfile_content = zipfile_content.replace(match_content, modified_content)

# central directory header

about_file_enc_flag_re = r'504b0102.'

match_contents = re.findall(about_file_enc_flag_re, zipfile_content)

if match_contents:

print '[*] modify central directory header flag:'

for match_content in match_contents:

modified_content = match_content[:16] + hex(int(match_content[16:18], 16) & 0b11111110)[2:].zfill(2) + match_content[18:]

print ' ' + match_content + ' --> ' + modified_content

zipfile_content = zipfile_content.replace(match_content, modified_content)

# 將處理後內容寫入新檔案

newzip = open(para1[:-4] + '_repair.zip','wb')

newzip.write(zipfile_content.decode('hex'))

newzip.close()

print('done')

if __name__ == '__main__':

if(len(sys.argv) != 2):

print('\nusage example:')

print(' python dzipfade.py a.zip\n')

else:

para = sys.argv

removefade(para[1])

參考**:

zip格式檔案偽加密

實踐是檢驗真理的唯一標準 zip檔案是一種壓縮檔案,可進行加密,也可不加密。而偽加密是在未加密的zip檔案基礎上修改了它的壓縮源檔案目錄區里的全域性方式位標記的位元值,使得壓縮軟體開啟它的時候識別為加密檔案,提示輸入密碼,而在這個時候,不管你用什麼軟體對其進行密碼破解,都無法開啟它!這就是它存在的意...

Zip壓縮包偽加密原理

壓縮原始檔資料區 壓縮源檔案目錄區 壓縮源檔案目錄結束標誌 壓縮原始檔資料區 壓縮源檔案目錄區 壓縮源檔案目錄結束標誌 如何識別真偽加密 1.無加密 2.偽加密 3.真加密 下面以攻防世界的的題目base64stego為例,實際講解 如下,開始附件開啟要求輸入密碼,使用360解壓縮可以自動破解這種偽...

python暴力破解加密zip文件

由參加的乙個安全大賽來的。flag檔案在乙個加密的zip檔案裡面,金鑰為6 8位的數字。寫了個python指令碼進行暴力解壓縮。其中暴力破解的密碼生成採用itertools庫提供的函式來產生。即product函式,product函式為求迭代器的笛卡爾積。如下 list1 1,2,3 list2 a,...