ZIP格式分析

ZIP格式分析

2023年6月24日发(作者:)

ZIP格式分析本⽂同步更新在我的个⼈博客,欢迎访问:最近遇到⼀道CTF题是和zip格式编码相关的,正好我⼀直以来就对各⽂件格式编码没有⼀个系统的认知,就趁这个机会好好学习⼀下。简介ZIP⽂件格式是⼀种数据压缩和⽂档储存的⽂件格式,原名Deflate,发明者为菲尔·卡茨(Phil Katz),他于1989年1⽉公布了该格式的资料。ZIP通常使⽤后缀名“.zip”,它的MIME格式为application/zip。当前,ZIP格式属于⼏种主流的压缩格式之⼀,其竞争者包括RAR格式以及开放源码的7z格式。从性能上⽐较,RAR及7z格式较ZIP格式压缩率较⾼,⽽7-Zip由于提供了免费的压缩⼯具⽽逐渐在更多的领域得到应⽤。Microsoft从Windows ME操作系统开始内置对zip格式的⽀持,即使⽤户的计算机上没有安装解压缩软件,也能打开和制作zip格式的压缩⽂件,OS X和流⾏的Linux操作系统也对zip格式提供了类似的⽀持。因此如果在⽹络上传播和分发⽂件,zip格式往往是最常⽤的选择。官⽅⽂档如果想要准确系统的了解整个zip格式,最好还是查看官⽅⽂档,链接如下:格式分析根据官⽅⽂档,我们可以得知,⼀个标准的zip格式⽂件由以下结构组成: [local file header 1] [file data 1] [data descriptor 1] .

. . [local file header n] [file data n] [data descriptor n] [archive decryption header] (EFS) [archive extra data record] (EFS) [central directory] [zip64 end of central directory record] [zip64 end of central directory locator]

[end of central directory record]在这⾥我们只考虑

local file header +

file data +

data descriptor +

central directory +

end of central directory record.⽂件头(Local file header) local file header signature 4 bytes (0x04034b50) version needed to extract 2 bytes general purpose bit flag 2 bytes compression method 2 bytes last mod file time 2 bytes last mod file date 2 bytes crc-32 4 bytes compressed size 4 bytes uncompressed size 4 bytes file name length 2 bytes extra field length 2 bytes file name (variable size) extra field (variable size)为了演⽰的⽅便,以下我们以⼀个包含了⽂本内容为26个英⽂字母的⽂本⽂件的压缩包做对照分析。1. ⽂件头位置即为灰⾊区域,⾸先是本地⽂件头标识位(local file header signature),值为固定的0x04034b50(需要注意的是单个字节数据在内存中的存储是低位在前,⾼位在后)。2. 解压⽂件所需pkware的最低版本(version needed to extract):0x000a,⼀般不需要考虑。3. 通⽤⽐特标志位(general purpose bit flag):0x0000,通常只需要考虑当bit 0为1时表⽰⽂件被加密。4. 压缩⽅式(compression method):0x0000,当值为:0x0000时表⽰⽆压缩。5. ⽂件最后修改时间(last mod file time):0x4e5a,以standard MS-DOS格式编码。6. ⽂件最后修改⽇期(last mod file date):0x531d,同上。7. CRC32校验码(crc-32):0x4c2750bd.8. 压缩后⼤⼩(compressed size):0x0000001a,单位为byte,由此我们可以推断出标准ZIP格式最⼤压缩容量为:16^8 - 1 bytes≈ 4 GB,⽽ZIP64格式最⼤压缩容量为 2^64 - 1 bytes ≈ 16EB。9. 未压缩的⼤⼩(uncompressed size):0x0000001a,可见该⽂件并没有被压缩,这也与压缩⽅式为0x0000相吻合。10. ⽂件名长度(file name length):0x0008.11. 扩展区长度(extra field length):0x0000.12. ⽂件名(file name):0x7478742e74736574.13. 扩展区(extra field):⽆⽂件数据(File data)存储被压缩⽂件的数据:本例中即为26个英⽂字母,图中的⿊⾊区域。数据描述符(Data descriptor) crc-32 4 bytes compressed size 4 bytes uncompressed size 4 bytes该区域只有在⽂件头的通⽤⽐特标志位的第3位(0x0008)为1时才存在,紧跟在压缩⽂件的数据区之后,只⽤在不能对输出的 ZIP ⽂件进⾏检索时使⽤。核⼼⽬录(Central directory) [file header 1] . . .

[file 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 compression method 2 bytes last mod file time 2 bytes last mod file date 2 bytes crc-32 4 bytes compressed size 4 bytes uncompressed size 4 bytes file name length 2 bytes extra field length 2 bytes file comment length 2 bytes disk number start 2 bytes internal file attributes 2 bytes external file attributes 4 bytes relative offset of local header 4 bytes file name (variable size) extra field (variable size) file comment (variable size)1. 核⼼⽂件头标识位(central file header signature):0x02014b50,为固定数值。2. 压缩所⽤pkware版本(version mad by):0x003f.3. 解压所需的pkware最低版本(version needed to extract):0x000a.4. 通⽤⽐特标志位(general purpose bit flag):0x0000.5. 压缩⽅式(compression method):0x0000.6. ⽂件最后修改时间(last mod file time):0x4e5a.7. ⽂件最后修改⽇期(last mod file date):0x531d.8. CRC32校验码(crc-32):0x4c2750bd.9. 压缩后⼤⼩(compressed size):0x0000001a.10. 未压缩的⼤⼩(uncompressed size):0x0000001a.11. ⽂件名长度(file name length):0x0008.12. 扩展区长度(extra field length):0x0024.13. ⽂件注释长度(file comment length):0x0000.14. ⽂件开始位置的磁盘编号(disk number start):0x0000.15. 内部⽂件属性(internal file attributes):0x0000.16. 外部⽂件属性(external file attributes):0x00000002,外部属性的映射取决于主机系统,对于MS-DOS,低位字节是MS-DOS⽬录属性字节,如果输⼊来⾃于标准输⼊,该区域置为零。17. 本地⽂件头的相互偏移(relative offset of local header):0x00000000.18. ⽂件名(file name):0x7478742e74736574.19. 扩展区(extra field):即⽂件名后的36个字节数据。20. ⽂件注释(file comment):⽆数字签名(Digital signature) header signature 4 bytes (0x05054b50) size of data 2 bytes signature data (variable size)本区域不是必须的,在此不多赘述,感兴趣可以查看官⽅⽂档。⽬录结束标识(End of central directory record) end of central dir signature 4 bytes (0x06054b50) number of this disk 2 bytes number of the disk with the start of the central directory 2 bytes total number of entries in the central directory on this disk 2 bytes total number of entries in the central directory 2 bytes size of the central directory 4 bytes offset of start of central directory with respect to the starting disk number 4 bytes .ZIP file comment length 2 bytes .ZIP file comment (variable size)1. 核⼼⽬录结束标识位(end of central dir signature):0x06054b50,为固定数值。2. 该磁盘编号(number of this disk):0x0000.3. 核⼼⽬录开始位置的磁盘编号(number of the disk with the start of the central directory):0x0000.4. 该磁盘所记录的核⼼⽬录总数(total number of entries in the central directory on this disk):0x0001.5. 核⼼⽬录结构总数(total number of entries in the central directory on this disk):0x0001.6. 核⼼⽬录⼤⼩(size of the central directory):0x0000005a.7. 核⼼⽬录开始位置相较于起始磁盘号的偏移量(offset of start of central directory with respect to the starting disk number):0x00000040.8. ZIP⽂件注释长度(.ZIP file comment length):0x0000.9. ZIP⽂件注释(.ZIP file comment):⽆例题题⽬链接分析与解答由于对ZIP格式编码不熟悉,刚看到这⼀串字符以为是某种加密⽅式,在学习过本⽂后在看,很明显504B0304为ZIP格式的⽂件头标识位,因此我们打开010Editor,导⼊这⼀串16进制编码,并保存为ZIP格式。解压时发现设置了密码,考虑密码应该不会太复杂,直接暴⼒破解得到结果。

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1687582947a22056.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信