zip 伪加密 Python处理脚本

26 篇文章 2 订阅

一个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.csdn.net/ETF6996/article/details/51946250

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

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值