zip 伪加密 Python处理脚本

本文介绍了一种去除ZIP文件伪加密的方法。通过修改ZIP文件头中的加密标志位,可以取消文件的伪加密状态,使其能够正常解压。文章提供了详细的步骤说明,并附带了一个Python脚本来实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一个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.{8}'
	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.{12}'
	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])


 

参考网址:

http://blog.youkuaiyun.com/ETF6996/article/details/51946250

https://pkware.cachefly.net/webdocs/APPNOTE/APPNOTE-6.2.0.txt

### ZIP伪加密解码方法 ZIP文件的伪加密是一种简单的保护机制,其设计初衷是为了防止无意中的数据泄露,而不是为了提供高强度的安全保障。这种加密方式可以通过特定的技术手段绕过。以下是关于ZIP伪加密解码的具体方法: #### 工具支持 可以使用一些专门的工具来处理ZIP文件的伪加密问题。例如ARCHPR工具被广泛应用于此类场景中[^3]。该工具能够通过对ZIP文件头结构的分析,识别并提取未真正加密的数据部分。 #### 手动解析过程 如果希望手动实现ZIP伪加密的解码,则需了解以下几个关键点: 1. **全局加密标志** 压缩源文件数据区和目录区的全局加密方式位标记应分别为`09 00`,这表明文件采用了标准的ZIP伪加密模式[^3]。 2. **数据区域定位** 使用十六进制编辑器(如WinHex)打开ZIP文件,找到实际存储压缩数据的部分。这些数据通常位于文件头部之后,并遵循一定的偏移规律[^3]。 3. **解密逻辑** - 对于每一段受保护的内容,读取对应的初始化向量(IV)字段; - 应用逆向XOR操作恢复原始字节流;此步骤依赖已知固定长度的秘密键值串作为输入参数参与计算得出最终明文形式的结果集[]^3]^. ```python def xor_decrypt(data, key): """执行简单异或解密""" decrypted = bytearray() for i in range(len(data)): decrypted.append(data[i] ^ ord(key[i % len(key)])) return bytes(decrypted) # 示例调用 encrypted_data = b'\x1a\x2b...' # 替换为真实的加密数据 key = 'secret' # 替换为真实使用的秘钥字符串 plain_text = xor_decrypt(encrypted_data, key) print(plain_text.decode('utf-8')) ``` 以上脚本展示了如何基于给定钥匙材料完成基础层面的信息还原工作流程演示[^3]. #### 注意事项 尽管存在多种途径可突破传统意义上的"弱化版"安全防护措施,但在实际应用过程中仍需谨慎行事,确保行为合法合规,尊重知识产权及相关法律法规约束条件下的合理范围内的技术探索活动开展下去才是正道所在之处.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值