SlideShare uma empresa Scribd logo
1 de 37
Baixar para ler offline
08/04/2022
Ange Albertini
G2
D2
E1
T1
A1
E1
B3
G2
Z10
I1
P3
L1
I1
F4
Relations between
archive formats
G
2
D2
E1
T1
A1
E1
B3
G2
Z10
I1
P3
L1
I1
F4
A presentation by
A.K.A.
Ange
Albertini
- reverse engineering since 1989
- author of Corkami
- File Formats For Ever
at PoC or GTFO
- malware analysis
- infosec engineer
About the author
my license plate is a CPU,
my phone case is a PDF doc,
my PDF resume is a SNES/MD rom.
My own views
and opinions.
3
Tl:Dr;
A lot of confusion regarding Zlib/Gzip/Zip/Deflate.
Is Deflate “Zip’s algorithm” ?
This deck is not about explaining compression algorithms.
THE CURRENT SLIDE IS AN
A CORKAMI ORIGINAL PRODUCTION
HONEST TALK TRAILER
zlib — Compression compatible with gzip
4
Standards timeline
1989-2020 Zip file format (AppNote)
1996/05 - RFC 1950 - Zlib Compressed Data Format Specification
1996/05 - RFC 1951 - Deflate Compressed Data Format Specification
1996/05 - RFC 1952 - Gzip file format
Zip is much older.
All related RFCs were submitted together, which is confusing.
5
Zip timeline
Supported Compressions (cf AppNote archive)
1990 v1.0 {Store, Shrunk, Reduce1/2/3/4, Implode}
1993 v2.0 +{Tokenize, Deflate}
2001 v4.5.0 +{Deflate64, Imploding}
2003 v5.2.0 +{Res11, Bzip2}
2006 v6.3.0 +{Res13, LZMA, Res15-17, IBM Terse, Lz77, PPMd}
2020 v6.3.9 +{Zstd, Mp3, XZ, Jpeg, WavPack}
CF Hans Wennborg blog post
Deflate: CompressionMethod = 8
8
6
0 1
2 3 4 5 6
8
7
Zip supports a lot more than Deflate
Since 1992,
Deflate is ZIP’s standard ‘generic’ compression.
Some tools only support Deflate (and reject other methods):
-> using older compressions is an easy security bypass.
7
Ok, we know that Deflate is
one of Zip’s algorithm
The standard one
8
Let’s not deep-dive
into Deflate
Let’s just pick one example
9
The minimal Deflate stream
Deflate stream of an empty stream:
Tiny, but already complex for empty data!
03 00
Deflate data:
- Last/Type
- Length
True/Dynamic Huffman
0
00 01
01 00 00 FF FF
Deflate data:
- Last/Type
- Length
- !Length
True/No Compression
0
-1
00 01 02 03 04
Compressed form
Raw form
10
Zip Store method
Pure raw data - the original file as-is.
(useful to keep payloads still useable)
Zip Storing is not the same as
Deflate with no compression.
Last/Type
Length
!Length
True/NC
0
0xFFFF
Zip-Stored empty string “”
Deflate-stored empty string: 01 00 00 FF FF
The other standard ZIP method.
“No Compression”.
11
What about Gzip and Zlib?
12
A minimal Zlib stream (simplified)
78 DA 03 00 00 00 00 01
00 01 02 03 04 05 06 07
[4 bits]
Method
[1 byte]
Deflate data
[4 bytes]
Simplified contents:
- Some parameters
- including the Compression Method
- Deflate data
- a footer
Always 2 bytes before, 4 bytes after.
13
A minimal Zlib stream
78 DA 03 00 00 00 00 01
00 01 02 03 04 05 06 07
Window Size
Method
Flags
Checksum
Deflate data:
- Last/Type
- Length
Adler32
7 = 32Kb
8 = Deflate
No Dictionary Extra
0x78DA % 31 = 0
True/Dynamic Huffman
0
0x00000001
CM (Compression method)
This identifies the compression method used in the file. CM = 8
denotes the "deflate" compression method with a window size up
to 32K. This is the method used by gzip and PNG (see
references [1] and [2] in Chapter 3, below, for the reference
documents). CM = 15 is reserved. It might be used in a future
version of this specification to indicate the presence of an
extra field before the compressed data.
14
0x
1x
1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00
00 00 00 00
0 1 2 3 4 5 6 7 8 9 A B C D E F
[2 bytes]
Compression Method
[variable]
Deflate data
[8 bytes]
A minimal Gzip archive
Compression method is always 08 (Deflate).
15
1F 8B
8 = Deflate
CM (Compression Method)
This identifies the compression method used in the file. CM
= 0-7 are reserved. CM = 8 denotes the "deflate"
compression method, which is the one customarily used by
gzip and which is documented elsewhere.
In details…
0x
1x
1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00
00 00 00 00
0 1 2 3 4 5 6 7 8 9 A B C D E F
Magic
Method
Flags
ModTime
Extra Flags
OS
Deflate data:
- Last/Type
- Length
CRC32
lenUncomp
Some fixed length information is required before and after the Deflate data.
FileName, Comments, Extra Field are variable and optional (not used here).
16
1F 8B
8 = Deflate
None
0/0/1980 00:00
Max compression
Unknown
True/Dynamic Huffman
0
0x00000000
0
Zlib <-> Gzip
2 different ways to store a Deflate data stream.
Both with data before and after.
The compressed data can be tranferred,
but both formats aren’t compatible.
17
78 DA 03 00 00 00 00 01
0 1 2 3 4 5 6 7
[4 bits]
Method
[1 byte]
Deflate data
[4 bytes]
8 = Deflate
0x
1x
1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00
00 00 00 00
0 1 2 3 4 5 6 7 8 9 A B C D E F
[2 bytes]
Method
[variable]
Deflate data
[8 bytes]
8 = Deflate
Zlib data stream
GZip “member”
Deflate data
18
78 DA 03 00 00 00 00 01
0 1 2 3 4 5 6 7
Window Size
Method
Flags
Checksum
Deflate data:
- Last/Type
- Length
Adler32
7 = 32Kb
8 = Deflate
No Dictionary Extra
0x78DA % 31 = 0
True/Dynamic Huffman
0
0x00000001
0x
1x
1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00
00 00 00 00
0 1 2 3 4 5 6 7 8 9 A B C D E F
Magic
Method
Flags
ModTime
Extra Flags
OS
Deflate data:
- Last/Type
- Length
CRC32
lenUncomp
1F 8B
8 = Deflate
None
0/0/1980 00:00
Max compression
Unknown
True/Dynamic Huffman
0
0x00000000
0
Zlib data stream
GZip “member”
Deflate data
19
Signature .
MadeVersion
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileCommentLen
DiskNumberStart
InternalAttr
ExternalAttr
LFHOffset .
FileName .
ExtraField
FileComment
00
04
06
08
0A
0C
0E
12
16
1A
1C
1E
27
34
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
P K 05 06 00 00 00 00
00 00 01 00 33 00 00 00 25 00 00 00 00 00
Start
PK34 .
10
None
8=Deflate .
00:00
0/0/1980
0x00000000
2 .
0 .
5 .
0
empty .
03 00 .
n/a
Signature .
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileName .
Content .
ExtraField
4
2
2
2
2
2
4
4
4
2
2
?
?
?
P K 03 04 0A 00 00 00 08 00 00 00 00 00 00 00>
<00 00 02 00 00 00 00 00 00 00 05 00 00 00 e m>
< p t y 03 00
34
38
3A
3C
3E
40
42
44
48
4C
50
52
54
56
58
5A
5E
62
6B
6B
PK12 .
0
10
None
8=Deflate .
00:00
0/0/1980
0x00000000
2 .
0 .
5 .
0
0
0
0
0
0 .
empty .
n/a
n/a
4
2
2
2
2
2
2
4
4
4
2
2
2
2
2
4
4
?
?
?
PK56 .
0
0
0
1 .
33 .
25 .
0
n/a
6B
6F
71
73
75
77
7B
7F
81
Signature .
ThisDiskNumber
StartDiskNumber
ThisDiskEntries
StartDiskEntries .
Size .
CDOffset .
CommentLen
Comment
4
2
2
2
2
4
4
2
?
1. End of Central Directory
2. Central Directory
3. Local File Header
A complete ZIP archive with empty deflated data
0x
1x
2x
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
2x
3x
4x
5x
5x
6x
P K 01 02 00 00 0A 00 00 00 08>
<00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00>
<00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
<00 00 00 e m p t y
20
Signature
MadeVersion
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32
CompressSize
UncompSize
FileNameLen
ExtraFieldLen
FileCommentLen
DiskNumberStart
InternalAttr
ExternalAttr
LFHOffset
FileName
ExtraField
FileComment
00
04
06
08
0A
0C
0E
12
16
1A
1C
1E
27
34
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
P K 05 06 00 00 00 00
00 00 01 00 33 00 00 00 25 00 00 00 00 00
PK34
10
None
8=Deflate .
00:00
0/0/1980
0x00000000
2
0
5
0
empty
03 00 .
n/a
Signature
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32
CompressSize
UncompSize
FileNameLen
ExtraFieldLen
FileName
Content .
ExtraField
4
2
2
2
2
2
4
4
4
2
2
?
?
?
P K 03 04 0A 00 00 00 08 00 00 00 00 00 00 00
00 00 02 00 00 00 00 00 00 00 05 00 00 00 e m
p t y 03 00
34
38
3A
3C
3E
40
42
44
48
4C
50
52
54
56
58
5A
5E
62
6B
6B
PK12
0
10
None
8=Deflate .
00:00
0/0/1980
0x00000000
2
0
5
0
0
0
0
0
0
empty
n/a
n/a
4
2
2
2
2
2
2
4
4
4
2
2
2
2
2
4
4
?
?
?
PK56
0
0
0
1
33
25
0
n/a
6B
6F
71
73
75
77
7B
7F
81
Signature
ThisDiskNumber
StartDiskNumber
ThisDiskEntries
StartDiskEntries
Size
CDOffset
CommentLen
Comment
4
2
2
2
2
4
4
2
?
1. End of Central Directory
2. Central Directory
3. Local File Header
Compression method and compressed data
0x
1x
2x
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
2x
3x
4x
5x
5x
6x
P K 01 02 00 00 0A 00 00 00 08>
<00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00
00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 e m p t y
21
Disambiguation
Deflate is a compression algorithm.
Zip usually uses Deflate, but not necessarily.
Zlib and Gzip are both wrapping only Deflate,
but in a different way.
Same exchangeable data, but no direct compatibility.
22
Conclusion
23
3 different wrappers around Deflate
Zlib GZIP
member
ZIP
Local
File
Header
Store
Deflate64
Bzip2…
Deflate
Conclusion
Deflate is a very standard compression algorithm.
Zip can use Deflate, but other algorithms too (Storing…)
Zip can use a different compression per file.
Zlib is a wrapper around a Deflate stream.
A Gzip member is a wrapper around a Deflate stream.
A Gzip file is one or more members.
25
Moving data around
Deflate data can be moved from/to:
- Zlib
- Gzip
- Zip using Deflate
2 bytes before // 4 bytes after.
Variable header // 8 bytes after.
26
Thank you!
Questions, suggestions…
27
Extra pictures
28
a ZIP archive with some stored content
P K 05 06 00>
<00 00 00 00 00 01 00 37 00 00 00 34 00 00 00 00>
<00
Signature .
MadeVersion
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileCommentLen
DiskNumberStart
InternalAttr
ExternalAttr
LFHOffset .
FileName .
ExtraField
FileComment
00
04
06
08
0A
0C
0E
12
16
1A
1C
1E
27
34
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
Start
PK34 .
10
None
0=Store .
00:00
0/0/1980
0x7D14DDDD .
13 .
13 .
9 .
0
hello.txt .
Hello Worldn .
n/a
Signature .
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileName .
Content .
ExtraField
4
2
2
2
2
2
4
4
4
2
2
?
?
?
P K 03 04 0A 00 00 00 00 00 00 00 00 00 DD DD>
<14 7D 0D 00 00 00 0D 00 00 00 09 00 00 00 h e>
< l l o . t x t H e l l o W o r>
< l d ! n
34
38
3A
3C
3E
40
42
44
48
4C
50
52
54
56
58
5A
5E
62
6B
6B
PK12 .
0
10
None
0=Store .
00:00
0/0/1980
0x7D14DDDD .
13 .
13 .
9 .
0
0
0
0
0
0 .
hello.txt .
n/a
n/a
4
2
2
2
2
2
2
4
4
4
2
2
2
2
2
4
4
?
?
?
PK56 .
0
0
0
1 . .
37 .
34 .
0
n/a
6B
6F
71
73
75
77
7B
7F
81
Signature .
ThisDiskNumber
StartDiskNumber
ThisDiskEntries
StartDiskEntries . .
Size .
CDOffset .
CommentLen
Comment
4
2
2
2
2
4
4
2
?
1. End of Central Directory
2. Central Directory
3. Local File Header
0x
1x
2x
3x
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
3x
4x
5x
6x
P K 01 02 00 00 0A 00 00 00 00 00
00 00 00 00 DD DD 14 7D 0D 00 00 00 0D 00 00 00
09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
<00 00 h e l l o . t x t
6x
7x
8x
a ZIP archive with empty stored content
Signature .
MadeVersion
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileCommentLen
DiskNumberStart
InternalAttr
ExternalAttr
LFHOffset .
FileName .
ExtraField
FileComment
00
04
06
08
0A
0C
0E
12
16
1A
1C
1E
23
23
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
P K 05 06 00 00 00 00 00 00
01 00 33 00 00 00 23 00 00 00 00 00
Start
PK34 .
10
None
0=Store .
00:00
0/0/1980
0x00000000
0 .
0 .
5 .
0
empty .
n/a
n/a
Signature .
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileName .
Contents
ExtraField
4
2
2
2
2
2
4
4
4
2
2
?
?
?
P K 03 04 0A 00 00 00 00 00 00 00 00 00 00 00>
<00 00 00 00 00 00 00 00 00 00 05 00 00 00 e m>
< p t y
23
27
29
2B
2D
2F
31
33
37
3B
3F
41
43
45
47
49
4D
51
56
56
PK12 .
0
10
None
0=Store .
00:00
0/0/1980
0x00000000
0 .
0 .
5 .
0
0
0
0
0
0 .
empty .
n/a
n/a
4
2
2
2
2
2
2
4
4
4
2
2
2
2
2
4
4
?
?
?
PK56 .
0
0
0
1 . .
33 .
23 .
0
n/a
56
5A
5C
5E
60
62
66
6A
6C
Signature .
ThisDiskNumber
StartDiskNumber
ThisDiskEntries
StartDiskEntries . .
Size .
CDOffset .
CommentLen
Comment
4
2
2
2
2
4
4
2
?
1. End of Central Directory
2. Central Directory
3. Local File Header
0x
1x
2x
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
2x
3x
4x
5x
5x
6x
P K 01 02 00 00 0A 00 00 00 00 00 00>
<00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05>
<00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
<00 e m p t y
a ZIP archive with empty deflated content
Signature .
MadeVersion
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileCommentLen
DiskNumberStart
InternalAttr
ExternalAttr
LFHOffset .
FileName .
ExtraField
FileComment
00
04
06
08
0A
0C
0E
12
16
1A
1C
1E
23
25
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
P K 05 06 00 00 00 00
00 00 01 00 33 00 00 00 25 00 00 00 00 00
Start
PK34 .
10
None
8=Deflate .
00:00
0/0/1980
0x00000000
2 .
0 .
5 .
0
empty .
03 00 .
n/a
Signature .
NeededVersion
Flags
CompMethod .
ModTime
ModDate
CRC32 .
CompressSize .
UncompSize .
FileNameLen .
ExtraFieldLen
FileName .
Content .
ExtraField
4
2
2
2
2
2
4
4
4
2
2
?
?
?
P K 03 04 0A 00 00 00 08 00 00 00 00 00 00 00>
<00 00 02 00 00 00 00 00 00 00 05 00 00 00 e m>
< p t y 03 00
25
29
2B
2D
2F
31
33
35
39
3D
41
43
45
47
49
4B
4F
53
58
58
PK12 .
0
10
None
8=Deflate .
00:00
0/0/1980
0x00000000
2 .
0 .
5 .
0
0
0
0
0
0 .
empty .
n/a
n/a
4
2
2
2
2
2
2
4
4
4
2
2
2
2
2
4
4
?
?
?
PK56 .
0
0
0
1 . .
33 .
25 .
0
n/a
58
5C
5E
60
62
64
68
6C
6E
Signature .
ThisDiskNumber
StartDiskNumber
ThisDiskEntries
StartDiskEntries . .
Size .
CDOffset .
CommentLen
Comment
4
2
2
2
2
4
4
2
?
1. End of Central Directory
2. Central Directory
3. Local File Header
0x
1x
2x
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
2x
3x
4x
5x
5x
6x
P K 01 02 00 00 0A 00 00 00 08>
<00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00>
<00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00>
<00 00 00 e m p t y
A Gzip file (with a filename before the Deflate data) 32
Magic
Method
Flags
ModTime
Extra Flags
OS
Extra Field:
- Size16
- SubField:
- Type
- Size16
- Data
Filename
- Data
Comment
- Data
Deflate data:
- Last/Type
- Length
- !Length
- Data
CRC32
lenUncomp
1F 8B 08 1C 26 F7 4F 62 00 FF 14 00 G Z 10 00
e x t r a  f i e l d  d a t a
f i l e n a m e 0 c o m m e n t
0 01 0C 00 F3 FF H e l l o W o r l
d ! A3 1C 29 1C 0C 00 00 00
Extra Field, Filename, Comment: set in Flags
stored between OS and Deflate data.
Filename & Comment: Null-terminated.
Extra field: Size16 first, then SubFields
0x
1x
2x
3x
4x
+0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F
1F 8B
8 = Deflate
Extra Field, Filename, Comment
1980/4/8 10:49
None
Unknown
20
GZ
16
“extra field data”
“filename0”
“comment0”
True/Raw
12
0xFFF3
Hello World!
0x1c291ca3
12
33
A full-featured GZIP 4 8 10
TEXT and CRC16 are
not usually supported
A PNG image
(PNG is an image format using Zlib)
34
One more thing…
35
How can you prove
that it’s the same data?
Make files that are both simultaneously,
with the Deflate data in common 😱😉
ZGip: Zip/Gzip polyglots, with shared Deflate data.
36
∂ ∂ ∂ ∂ ∂ ∂ ∂ ∂ ∂
The End G
2
D2
E1
T1
A1
E1
B3
G2
Z10
I1
P3
L1
I1
F4

Mais conteúdo relacionado

Semelhante a Relations between archive formats

Optimizing Parallel Reduction in CUDA : NOTES
Optimizing Parallel Reduction in CUDA : NOTESOptimizing Parallel Reduction in CUDA : NOTES
Optimizing Parallel Reduction in CUDA : NOTESSubhajit Sahu
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Jian-Hong Pan
 
Happy To Use SIMD
Happy To Use SIMDHappy To Use SIMD
Happy To Use SIMDWei-Ta Wang
 
A New Framework for Detection
A New Framework for DetectionA New Framework for Detection
A New Framework for DetectionSourcefire VRT
 
A Brief Introduction of TiDB (Percona Live)
A Brief Introduction of TiDB (Percona Live)A Brief Introduction of TiDB (Percona Live)
A Brief Introduction of TiDB (Percona Live)PingCAP
 
Open Enea Linux workshop at the Embedded Conference Scandinavia 2014
Open Enea Linux workshop at the Embedded Conference Scandinavia 2014Open Enea Linux workshop at the Embedded Conference Scandinavia 2014
Open Enea Linux workshop at the Embedded Conference Scandinavia 2014EneaSoftware
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_worldfantasy zheng
 
OSSNA 2017 Performance Analysis Superpowers with Linux BPF
OSSNA 2017 Performance Analysis Superpowers with Linux BPFOSSNA 2017 Performance Analysis Superpowers with Linux BPF
OSSNA 2017 Performance Analysis Superpowers with Linux BPFBrendan Gregg
 
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...linuxlab_conf
 
Funky file formats - 31c3
Funky file formats - 31c3Funky file formats - 31c3
Funky file formats - 31c3Ange Albertini
 
Lustre Generational Performance Improvements & New Features
Lustre Generational Performance Improvements & New FeaturesLustre Generational Performance Improvements & New Features
Lustre Generational Performance Improvements & New Featuresinside-BigData.com
 
Trying and evaluating the new features of GlusterFS 3.5
Trying and evaluating the new features of GlusterFS 3.5Trying and evaluating the new features of GlusterFS 3.5
Trying and evaluating the new features of GlusterFS 3.5Keisuke Takahashi
 
HKG15-401: Ceph and Software Defined Storage on ARM servers
HKG15-401: Ceph and Software Defined Storage on ARM serversHKG15-401: Ceph and Software Defined Storage on ARM servers
HKG15-401: Ceph and Software Defined Storage on ARM serversLinaro
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuEstelaJeffery653
 

Semelhante a Relations between archive formats (20)

Optimizing Parallel Reduction in CUDA : NOTES
Optimizing Parallel Reduction in CUDA : NOTESOptimizing Parallel Reduction in CUDA : NOTES
Optimizing Parallel Reduction in CUDA : NOTES
 
Log
LogLog
Log
 
Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021Let's trace Linux Lernel with KGDB @ COSCUP 2021
Let's trace Linux Lernel with KGDB @ COSCUP 2021
 
Debugging TV Frame 0x0D
Debugging TV Frame 0x0DDebugging TV Frame 0x0D
Debugging TV Frame 0x0D
 
Happy To Use SIMD
Happy To Use SIMDHappy To Use SIMD
Happy To Use SIMD
 
A New Framework for Detection
A New Framework for DetectionA New Framework for Detection
A New Framework for Detection
 
A Brief Introduction of TiDB (Percona Live)
A Brief Introduction of TiDB (Percona Live)A Brief Introduction of TiDB (Percona Live)
A Brief Introduction of TiDB (Percona Live)
 
Debug generic process
Debug generic processDebug generic process
Debug generic process
 
Open Enea Linux workshop at the Embedded Conference Scandinavia 2014
Open Enea Linux workshop at the Embedded Conference Scandinavia 2014Open Enea Linux workshop at the Embedded Conference Scandinavia 2014
Open Enea Linux workshop at the Embedded Conference Scandinavia 2014
 
The true story_of_hello_world
The true story_of_hello_worldThe true story_of_hello_world
The true story_of_hello_world
 
OSSNA 2017 Performance Analysis Superpowers with Linux BPF
OSSNA 2017 Performance Analysis Superpowers with Linux BPFOSSNA 2017 Performance Analysis Superpowers with Linux BPF
OSSNA 2017 Performance Analysis Superpowers with Linux BPF
 
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
Valerio Di Giampietro - Introduction To IoT Reverse Engineering with an examp...
 
HPDC'23 Rapidgzip
HPDC'23 RapidgzipHPDC'23 Rapidgzip
HPDC'23 Rapidgzip
 
Funky file formats - 31c3
Funky file formats - 31c3Funky file formats - 31c3
Funky file formats - 31c3
 
Lustre Generational Performance Improvements & New Features
Lustre Generational Performance Improvements & New FeaturesLustre Generational Performance Improvements & New Features
Lustre Generational Performance Improvements & New Features
 
Trying and evaluating the new features of GlusterFS 3.5
Trying and evaluating the new features of GlusterFS 3.5Trying and evaluating the new features of GlusterFS 3.5
Trying and evaluating the new features of GlusterFS 3.5
 
HKG15-401: Ceph and Software Defined Storage on ARM servers
HKG15-401: Ceph and Software Defined Storage on ARM serversHKG15-401: Ceph and Software Defined Storage on ARM servers
HKG15-401: Ceph and Software Defined Storage on ARM servers
 
Hotsos Advanced Linux Tools
Hotsos Advanced Linux ToolsHotsos Advanced Linux Tools
Hotsos Advanced Linux Tools
 
Chapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structuChapter 1SyllabusCatalog Description Computer structu
Chapter 1SyllabusCatalog Description Computer structu
 
Cram
CramCram
Cram
 

Mais de Ange Albertini

Technical challenges with file formats
Technical challenges with file formatsTechnical challenges with file formats
Technical challenges with file formatsAnge Albertini
 
Abusing archive file formats
Abusing archive file formatsAbusing archive file formats
Abusing archive file formatsAnge Albertini
 
You are *not* an idiot
You are *not* an idiotYou are *not* an idiot
You are *not* an idiotAnge Albertini
 
Improving file formats
Improving file formatsImproving file formats
Improving file formatsAnge Albertini
 
An introduction to inkscape
An introduction to inkscapeAn introduction to inkscape
An introduction to inkscapeAnge Albertini
 
The challenges of file formats
The challenges of file formatsThe challenges of file formats
The challenges of file formatsAnge Albertini
 
Exploiting hash collisions
Exploiting hash collisionsExploiting hash collisions
Exploiting hash collisionsAnge Albertini
 
Connecting communities
Connecting communitiesConnecting communities
Connecting communitiesAnge Albertini
 
TASBot - the perfectionist
TASBot - the perfectionistTASBot - the perfectionist
TASBot - the perfectionistAnge Albertini
 
Caring for file formats
Caring for file formatsCaring for file formats
Caring for file formatsAnge Albertini
 
Trusting files (and their formats)
Trusting files (and their formats)Trusting files (and their formats)
Trusting files (and their formats)Ange Albertini
 
Let's write a PDF file
Let's write a PDF fileLet's write a PDF file
Let's write a PDF fileAnge Albertini
 
An overview of potential leaks via PDF
An overview of potential leaks via PDFAn overview of potential leaks via PDF
An overview of potential leaks via PDFAnge Albertini
 

Mais de Ange Albertini (20)

Technical challenges with file formats
Technical challenges with file formatsTechnical challenges with file formats
Technical challenges with file formats
 
Abusing archive file formats
Abusing archive file formatsAbusing archive file formats
Abusing archive file formats
 
You are *not* an idiot
You are *not* an idiotYou are *not* an idiot
You are *not* an idiot
 
Improving file formats
Improving file formatsImproving file formats
Improving file formats
 
KILL MD5
KILL MD5KILL MD5
KILL MD5
 
No more dumb hex!
No more dumb hex!No more dumb hex!
No more dumb hex!
 
Beyond your studies
Beyond your studiesBeyond your studies
Beyond your studies
 
An introduction to inkscape
An introduction to inkscapeAn introduction to inkscape
An introduction to inkscape
 
The challenges of file formats
The challenges of file formatsThe challenges of file formats
The challenges of file formats
 
Exploiting hash collisions
Exploiting hash collisionsExploiting hash collisions
Exploiting hash collisions
 
Infosec & failures
Infosec & failuresInfosec & failures
Infosec & failures
 
Connecting communities
Connecting communitiesConnecting communities
Connecting communities
 
TASBot - the perfectionist
TASBot - the perfectionistTASBot - the perfectionist
TASBot - the perfectionist
 
Caring for file formats
Caring for file formatsCaring for file formats
Caring for file formats
 
Hacks in video games
Hacks in video gamesHacks in video games
Hacks in video games
 
Trusting files (and their formats)
Trusting files (and their formats)Trusting files (and their formats)
Trusting files (and their formats)
 
Let's write a PDF file
Let's write a PDF fileLet's write a PDF file
Let's write a PDF file
 
PDF: myths vs facts
PDF: myths vs factsPDF: myths vs facts
PDF: myths vs facts
 
An overview of potential leaks via PDF
An overview of potential leaks via PDFAn overview of potential leaks via PDF
An overview of potential leaks via PDF
 
Advanced Pdf Tricks
Advanced Pdf TricksAdvanced Pdf Tricks
Advanced Pdf Tricks
 

Último

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Último (20)

Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

Relations between archive formats

  • 3. - reverse engineering since 1989 - author of Corkami - File Formats For Ever at PoC or GTFO - malware analysis - infosec engineer About the author my license plate is a CPU, my phone case is a PDF doc, my PDF resume is a SNES/MD rom. My own views and opinions. 3
  • 4. Tl:Dr; A lot of confusion regarding Zlib/Gzip/Zip/Deflate. Is Deflate “Zip’s algorithm” ? This deck is not about explaining compression algorithms. THE CURRENT SLIDE IS AN A CORKAMI ORIGINAL PRODUCTION HONEST TALK TRAILER zlib — Compression compatible with gzip 4
  • 5. Standards timeline 1989-2020 Zip file format (AppNote) 1996/05 - RFC 1950 - Zlib Compressed Data Format Specification 1996/05 - RFC 1951 - Deflate Compressed Data Format Specification 1996/05 - RFC 1952 - Gzip file format Zip is much older. All related RFCs were submitted together, which is confusing. 5
  • 6. Zip timeline Supported Compressions (cf AppNote archive) 1990 v1.0 {Store, Shrunk, Reduce1/2/3/4, Implode} 1993 v2.0 +{Tokenize, Deflate} 2001 v4.5.0 +{Deflate64, Imploding} 2003 v5.2.0 +{Res11, Bzip2} 2006 v6.3.0 +{Res13, LZMA, Res15-17, IBM Terse, Lz77, PPMd} 2020 v6.3.9 +{Zstd, Mp3, XZ, Jpeg, WavPack} CF Hans Wennborg blog post Deflate: CompressionMethod = 8 8 6 0 1 2 3 4 5 6 8 7
  • 7. Zip supports a lot more than Deflate Since 1992, Deflate is ZIP’s standard ‘generic’ compression. Some tools only support Deflate (and reject other methods): -> using older compressions is an easy security bypass. 7
  • 8. Ok, we know that Deflate is one of Zip’s algorithm The standard one 8
  • 9. Let’s not deep-dive into Deflate Let’s just pick one example 9
  • 10. The minimal Deflate stream Deflate stream of an empty stream: Tiny, but already complex for empty data! 03 00 Deflate data: - Last/Type - Length True/Dynamic Huffman 0 00 01 01 00 00 FF FF Deflate data: - Last/Type - Length - !Length True/No Compression 0 -1 00 01 02 03 04 Compressed form Raw form 10
  • 11. Zip Store method Pure raw data - the original file as-is. (useful to keep payloads still useable) Zip Storing is not the same as Deflate with no compression. Last/Type Length !Length True/NC 0 0xFFFF Zip-Stored empty string “” Deflate-stored empty string: 01 00 00 FF FF The other standard ZIP method. “No Compression”. 11
  • 12. What about Gzip and Zlib? 12
  • 13. A minimal Zlib stream (simplified) 78 DA 03 00 00 00 00 01 00 01 02 03 04 05 06 07 [4 bits] Method [1 byte] Deflate data [4 bytes] Simplified contents: - Some parameters - including the Compression Method - Deflate data - a footer Always 2 bytes before, 4 bytes after. 13
  • 14. A minimal Zlib stream 78 DA 03 00 00 00 00 01 00 01 02 03 04 05 06 07 Window Size Method Flags Checksum Deflate data: - Last/Type - Length Adler32 7 = 32Kb 8 = Deflate No Dictionary Extra 0x78DA % 31 = 0 True/Dynamic Huffman 0 0x00000001 CM (Compression method) This identifies the compression method used in the file. CM = 8 denotes the "deflate" compression method with a window size up to 32K. This is the method used by gzip and PNG (see references [1] and [2] in Chapter 3, below, for the reference documents). CM = 15 is reserved. It might be used in a future version of this specification to indicate the presence of an extra field before the compressed data. 14
  • 15. 0x 1x 1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00 00 00 00 00 0 1 2 3 4 5 6 7 8 9 A B C D E F [2 bytes] Compression Method [variable] Deflate data [8 bytes] A minimal Gzip archive Compression method is always 08 (Deflate). 15 1F 8B 8 = Deflate CM (Compression Method) This identifies the compression method used in the file. CM = 0-7 are reserved. CM = 8 denotes the "deflate" compression method, which is the one customarily used by gzip and which is documented elsewhere.
  • 16. In details… 0x 1x 1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00 00 00 00 00 0 1 2 3 4 5 6 7 8 9 A B C D E F Magic Method Flags ModTime Extra Flags OS Deflate data: - Last/Type - Length CRC32 lenUncomp Some fixed length information is required before and after the Deflate data. FileName, Comments, Extra Field are variable and optional (not used here). 16 1F 8B 8 = Deflate None 0/0/1980 00:00 Max compression Unknown True/Dynamic Huffman 0 0x00000000 0
  • 17. Zlib <-> Gzip 2 different ways to store a Deflate data stream. Both with data before and after. The compressed data can be tranferred, but both formats aren’t compatible. 17
  • 18. 78 DA 03 00 00 00 00 01 0 1 2 3 4 5 6 7 [4 bits] Method [1 byte] Deflate data [4 bytes] 8 = Deflate 0x 1x 1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00 00 00 00 00 0 1 2 3 4 5 6 7 8 9 A B C D E F [2 bytes] Method [variable] Deflate data [8 bytes] 8 = Deflate Zlib data stream GZip “member” Deflate data 18
  • 19. 78 DA 03 00 00 00 00 01 0 1 2 3 4 5 6 7 Window Size Method Flags Checksum Deflate data: - Last/Type - Length Adler32 7 = 32Kb 8 = Deflate No Dictionary Extra 0x78DA % 31 = 0 True/Dynamic Huffman 0 0x00000001 0x 1x 1F 8B 08 00 00 00 00 00 02 FF 03 00 00 00 00 00 00 00 00 00 0 1 2 3 4 5 6 7 8 9 A B C D E F Magic Method Flags ModTime Extra Flags OS Deflate data: - Last/Type - Length CRC32 lenUncomp 1F 8B 8 = Deflate None 0/0/1980 00:00 Max compression Unknown True/Dynamic Huffman 0 0x00000000 0 Zlib data stream GZip “member” Deflate data 19
  • 20. Signature . MadeVersion NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileCommentLen DiskNumberStart InternalAttr ExternalAttr LFHOffset . FileName . ExtraField FileComment 00 04 06 08 0A 0C 0E 12 16 1A 1C 1E 27 34 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F P K 05 06 00 00 00 00 00 00 01 00 33 00 00 00 25 00 00 00 00 00 Start PK34 . 10 None 8=Deflate . 00:00 0/0/1980 0x00000000 2 . 0 . 5 . 0 empty . 03 00 . n/a Signature . NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileName . Content . ExtraField 4 2 2 2 2 2 4 4 4 2 2 ? ? ? P K 03 04 0A 00 00 00 08 00 00 00 00 00 00 00> <00 00 02 00 00 00 00 00 00 00 05 00 00 00 e m> < p t y 03 00 34 38 3A 3C 3E 40 42 44 48 4C 50 52 54 56 58 5A 5E 62 6B 6B PK12 . 0 10 None 8=Deflate . 00:00 0/0/1980 0x00000000 2 . 0 . 5 . 0 0 0 0 0 0 . empty . n/a n/a 4 2 2 2 2 2 2 4 4 4 2 2 2 2 2 4 4 ? ? ? PK56 . 0 0 0 1 . 33 . 25 . 0 n/a 6B 6F 71 73 75 77 7B 7F 81 Signature . ThisDiskNumber StartDiskNumber ThisDiskEntries StartDiskEntries . Size . CDOffset . CommentLen Comment 4 2 2 2 2 4 4 2 ? 1. End of Central Directory 2. Central Directory 3. Local File Header A complete ZIP archive with empty deflated data 0x 1x 2x +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 2x 3x 4x 5x 5x 6x P K 01 02 00 00 0A 00 00 00 08> <00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00> <00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00> <00 00 00 e m p t y 20
  • 21. Signature MadeVersion NeededVersion Flags CompMethod . ModTime ModDate CRC32 CompressSize UncompSize FileNameLen ExtraFieldLen FileCommentLen DiskNumberStart InternalAttr ExternalAttr LFHOffset FileName ExtraField FileComment 00 04 06 08 0A 0C 0E 12 16 1A 1C 1E 27 34 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F P K 05 06 00 00 00 00 00 00 01 00 33 00 00 00 25 00 00 00 00 00 PK34 10 None 8=Deflate . 00:00 0/0/1980 0x00000000 2 0 5 0 empty 03 00 . n/a Signature NeededVersion Flags CompMethod . ModTime ModDate CRC32 CompressSize UncompSize FileNameLen ExtraFieldLen FileName Content . ExtraField 4 2 2 2 2 2 4 4 4 2 2 ? ? ? P K 03 04 0A 00 00 00 08 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 05 00 00 00 e m p t y 03 00 34 38 3A 3C 3E 40 42 44 48 4C 50 52 54 56 58 5A 5E 62 6B 6B PK12 0 10 None 8=Deflate . 00:00 0/0/1980 0x00000000 2 0 5 0 0 0 0 0 0 empty n/a n/a 4 2 2 2 2 2 2 4 4 4 2 2 2 2 2 4 4 ? ? ? PK56 0 0 0 1 33 25 0 n/a 6B 6F 71 73 75 77 7B 7F 81 Signature ThisDiskNumber StartDiskNumber ThisDiskEntries StartDiskEntries Size CDOffset CommentLen Comment 4 2 2 2 2 4 4 2 ? 1. End of Central Directory 2. Central Directory 3. Local File Header Compression method and compressed data 0x 1x 2x +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 2x 3x 4x 5x 5x 6x P K 01 02 00 00 0A 00 00 00 08> <00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e m p t y 21
  • 22. Disambiguation Deflate is a compression algorithm. Zip usually uses Deflate, but not necessarily. Zlib and Gzip are both wrapping only Deflate, but in a different way. Same exchangeable data, but no direct compatibility. 22
  • 24. 3 different wrappers around Deflate Zlib GZIP member ZIP Local File Header Store Deflate64 Bzip2… Deflate
  • 25. Conclusion Deflate is a very standard compression algorithm. Zip can use Deflate, but other algorithms too (Storing…) Zip can use a different compression per file. Zlib is a wrapper around a Deflate stream. A Gzip member is a wrapper around a Deflate stream. A Gzip file is one or more members. 25
  • 26. Moving data around Deflate data can be moved from/to: - Zlib - Gzip - Zip using Deflate 2 bytes before // 4 bytes after. Variable header // 8 bytes after. 26
  • 29. a ZIP archive with some stored content P K 05 06 00> <00 00 00 00 00 01 00 37 00 00 00 34 00 00 00 00> <00 Signature . MadeVersion NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileCommentLen DiskNumberStart InternalAttr ExternalAttr LFHOffset . FileName . ExtraField FileComment 00 04 06 08 0A 0C 0E 12 16 1A 1C 1E 27 34 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F Start PK34 . 10 None 0=Store . 00:00 0/0/1980 0x7D14DDDD . 13 . 13 . 9 . 0 hello.txt . Hello Worldn . n/a Signature . NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileName . Content . ExtraField 4 2 2 2 2 2 4 4 4 2 2 ? ? ? P K 03 04 0A 00 00 00 00 00 00 00 00 00 DD DD> <14 7D 0D 00 00 00 0D 00 00 00 09 00 00 00 h e> < l l o . t x t H e l l o W o r> < l d ! n 34 38 3A 3C 3E 40 42 44 48 4C 50 52 54 56 58 5A 5E 62 6B 6B PK12 . 0 10 None 0=Store . 00:00 0/0/1980 0x7D14DDDD . 13 . 13 . 9 . 0 0 0 0 0 0 . hello.txt . n/a n/a 4 2 2 2 2 2 2 4 4 4 2 2 2 2 2 4 4 ? ? ? PK56 . 0 0 0 1 . . 37 . 34 . 0 n/a 6B 6F 71 73 75 77 7B 7F 81 Signature . ThisDiskNumber StartDiskNumber ThisDiskEntries StartDiskEntries . . Size . CDOffset . CommentLen Comment 4 2 2 2 2 4 4 2 ? 1. End of Central Directory 2. Central Directory 3. Local File Header 0x 1x 2x 3x +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 3x 4x 5x 6x P K 01 02 00 00 0A 00 00 00 00 00 00 00 00 00 DD DD 14 7D 0D 00 00 00 0D 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> <00 00 h e l l o . t x t 6x 7x 8x
  • 30. a ZIP archive with empty stored content Signature . MadeVersion NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileCommentLen DiskNumberStart InternalAttr ExternalAttr LFHOffset . FileName . ExtraField FileComment 00 04 06 08 0A 0C 0E 12 16 1A 1C 1E 23 23 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F P K 05 06 00 00 00 00 00 00 01 00 33 00 00 00 23 00 00 00 00 00 Start PK34 . 10 None 0=Store . 00:00 0/0/1980 0x00000000 0 . 0 . 5 . 0 empty . n/a n/a Signature . NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileName . Contents ExtraField 4 2 2 2 2 2 4 4 4 2 2 ? ? ? P K 03 04 0A 00 00 00 00 00 00 00 00 00 00 00> <00 00 00 00 00 00 00 00 00 00 05 00 00 00 e m> < p t y 23 27 29 2B 2D 2F 31 33 37 3B 3F 41 43 45 47 49 4D 51 56 56 PK12 . 0 10 None 0=Store . 00:00 0/0/1980 0x00000000 0 . 0 . 5 . 0 0 0 0 0 0 . empty . n/a n/a 4 2 2 2 2 2 2 4 4 4 2 2 2 2 2 4 4 ? ? ? PK56 . 0 0 0 1 . . 33 . 23 . 0 n/a 56 5A 5C 5E 60 62 66 6A 6C Signature . ThisDiskNumber StartDiskNumber ThisDiskEntries StartDiskEntries . . Size . CDOffset . CommentLen Comment 4 2 2 2 2 4 4 2 ? 1. End of Central Directory 2. Central Directory 3. Local File Header 0x 1x 2x +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 2x 3x 4x 5x 5x 6x P K 01 02 00 00 0A 00 00 00 00 00 00> <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05> <00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> <00 e m p t y
  • 31. a ZIP archive with empty deflated content Signature . MadeVersion NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileCommentLen DiskNumberStart InternalAttr ExternalAttr LFHOffset . FileName . ExtraField FileComment 00 04 06 08 0A 0C 0E 12 16 1A 1C 1E 23 25 +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F P K 05 06 00 00 00 00 00 00 01 00 33 00 00 00 25 00 00 00 00 00 Start PK34 . 10 None 8=Deflate . 00:00 0/0/1980 0x00000000 2 . 0 . 5 . 0 empty . 03 00 . n/a Signature . NeededVersion Flags CompMethod . ModTime ModDate CRC32 . CompressSize . UncompSize . FileNameLen . ExtraFieldLen FileName . Content . ExtraField 4 2 2 2 2 2 4 4 4 2 2 ? ? ? P K 03 04 0A 00 00 00 08 00 00 00 00 00 00 00> <00 00 02 00 00 00 00 00 00 00 05 00 00 00 e m> < p t y 03 00 25 29 2B 2D 2F 31 33 35 39 3D 41 43 45 47 49 4B 4F 53 58 58 PK12 . 0 10 None 8=Deflate . 00:00 0/0/1980 0x00000000 2 . 0 . 5 . 0 0 0 0 0 0 . empty . n/a n/a 4 2 2 2 2 2 2 4 4 4 2 2 2 2 2 4 4 ? ? ? PK56 . 0 0 0 1 . . 33 . 25 . 0 n/a 58 5C 5E 60 62 64 68 6C 6E Signature . ThisDiskNumber StartDiskNumber ThisDiskEntries StartDiskEntries . . Size . CDOffset . CommentLen Comment 4 2 2 2 2 4 4 2 ? 1. End of Central Directory 2. Central Directory 3. Local File Header 0x 1x 2x +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 2x 3x 4x 5x 5x 6x P K 01 02 00 00 0A 00 00 00 08> <00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00> <00 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00> <00 00 00 e m p t y
  • 32. A Gzip file (with a filename before the Deflate data) 32
  • 33. Magic Method Flags ModTime Extra Flags OS Extra Field: - Size16 - SubField: - Type - Size16 - Data Filename - Data Comment - Data Deflate data: - Last/Type - Length - !Length - Data CRC32 lenUncomp 1F 8B 08 1C 26 F7 4F 62 00 FF 14 00 G Z 10 00 e x t r a f i e l d d a t a f i l e n a m e 0 c o m m e n t 0 01 0C 00 F3 FF H e l l o W o r l d ! A3 1C 29 1C 0C 00 00 00 Extra Field, Filename, Comment: set in Flags stored between OS and Deflate data. Filename & Comment: Null-terminated. Extra field: Size16 first, then SubFields 0x 1x 2x 3x 4x +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 1F 8B 8 = Deflate Extra Field, Filename, Comment 1980/4/8 10:49 None Unknown 20 GZ 16 “extra field data” “filename0” “comment0” True/Raw 12 0xFFF3 Hello World! 0x1c291ca3 12 33 A full-featured GZIP 4 8 10 TEXT and CRC16 are not usually supported
  • 34. A PNG image (PNG is an image format using Zlib) 34
  • 36. How can you prove that it’s the same data? Make files that are both simultaneously, with the Deflate data in common 😱😉 ZGip: Zip/Gzip polyglots, with shared Deflate data. 36
  • 37. ∂ ∂ ∂ ∂ ∂ ∂ ∂ ∂ ∂ The End G 2 D2 E1 T1 A1 E1 B3 G2 Z10 I1 P3 L1 I1 F4