Funky File Formats
Funky File Formats
Ange Albertini
2014/12 - 31C3
Funky
File
Ange Albertini
reverse engineering &
visual documentations
@angealbertini
[email protected]
http://www.corkami.com
So, this talk is about files what are the usual files categories?
However, the frontier between valid and corrupted is not straight and clear !
AES(
If you encrypt it with AES...
3DES(
If you decrypt it with Triple DES...
AESK (
2
If you encrypt the original file with AES again, but with a different key...
JPG
AESK
PNG
JAR
(ZIP + CLASS)
AESK
3DES
FLV
PDF
So, as you can see, Im just a normal guy (who likes to play with binary).
Identification
How do you identify a cow?
By its head?
By its body?
By sound?
in practice...
early filetype
identifier
Obvious
PE\0\0 \x7FELF BPG\xFB
\x89PNG\x0D\x0A\x1A\x0A
dex\n035\0 RAR\x1a\7\0 BZ
GIF89a BM RIFF
Not obvious
GZip 1F 8B
JPG
FF D8
Not obvious, but l33tsp34k ^_^
CAFEBABE Java / universal (old) Mach-O
DOCF11E0 Office
FEEDFACE Mach-O
FEEDFACF Mach-O (64b)
Egocentric
MZ (DOS header)
PK\3\4 (ZIP)
BPG\xFB
Mark Zbikowski
Philip Katz
Fabrice Bellard
Specific logic
TIFF:
II Intel (little) endianness
MM Motorola (big) endianness
Flash:
FWS ShockWave Flash (Flat)
CWS (zlib) compressed
ZWS LZMA compressed
Another common
yet important property
(useful for abuses)
Its a complete cow (you can see its whole body), with something next:
appending something doesnt invalidate the start.
Remember:
theres nothing to parse
after the terminator.
PE
PDF
HTML
by concatenation
ZIP
host/parasite polyglots
by Travis Goodspeed
by Alex Infhr
$ tar -tvf
-rw-r--r--rw-r--r--rw-r--r--
pocorgtfo06.pdf
Manul/Laphroaig
0 2014-10-06 21:33 %PDF-1.5
Manul/Laphroaig 525849 2014-10-06 21:33 1.png
Manul/Laphroaig 273658 2014-10-06 21:33 2.bmp
$ unzip -l pocorgtfo06.pdf
Archive: pocorgtfo06.pdf
warning [pocorgtfo06.pdf]: 10672929 extra bytes at...
(attempting to process anyway)
Length
Date
Time
Name
--------- ---------- -------4095 11/24/2014 23:44
64k.txt
818941 08/18/2014 23:28
acsac13_zaddach.pdf
4564 10/05/2014 00:06
burn.txt
342232 11/24/2014 23:44
davinci.tgz.dvs
3785 11/24/2014 23:44
davinci.txt
5111 09/28/2014 21:05
declare.txt
0 08/23/2014 19:21
ecb2/
unicode //
Java = JavaScript
Yes, your management was right all along ;)
Parsing
commented line
PDF viewer
PDF slides
$ du -h stringme
141
stringme
$ strings stringme
Segmentation fault (core dumped)
Extra problem: parsers can be present in unexpected places
http://lcamtuf.blogspot.de/2014/10/psa-dont-run-strings-on-untrusted-files.html (CVE-2014-8485)
metadata
Whos the owner?
so cattle is branded.
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
?
.T.E.X.T0A.t.h.i.s. .i.s. .a. .t
.e.x.t0A
We want to encrypt a DATA file to a TEXT file.
DATA tolerates appended data after its END marker
TEXT accepts /* */ comments chunk (think parasite in a host)
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
<random>
if we encrypt, we get random result. we cant control AES output & input together.
penguin = bad
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
+IV1
Encrypt with pure AES, then determine IV to control the output block
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
+IV2
.T.E.X.T./.*
<ignored random rest>
We cant control the rest of the garbage so lets put a comment start in the first block
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
.T.E.X.T./.*
<ignored random rest>
.*./0A.t.h.i.s. .i.s. .a. .t
.e.x.t0A
If we close the comment and append the target files data in the encrypted file.
then this file is valid and equivalent to our initial target.
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
<pre-decrypted ignored random>
+IV2
.T.E.X.T./.*
<ignored random rest>
.*./0A.t.h.i.s. .i.s. .a. .t
.e.x.t0A
...then we decrypt that file: we get the original source file,
with some random data, that will be ignored since its appended data.
.D.A.T.A.[.1.2.3.4.5.6.7.8.9.A.B
.C.D.E.F.].E.N.D
<pre-decrypted ignored random>
+IV2
.T.E.X.T./.*
<ignored random rest>
.*./0A.t.h.i.s. .i.s. .a. .t
.e.x.t0A
Since AES CBC only depends on previous blocks,
this DATA file will indeed encrypt to a TEXT file.
00:
10:
20:
30:
4441
4344
f6fe
2e8e
5441
4546
17cf
6996
5b31
5d45
0802
5854
3233
4e44
7449
824c
3435
0000
58de
c09c
3637
0000
cdf2
1b7d
3839
0000
f9c4
4898
4142
0000
45ce
a29e
DATA[123456789AB
CDEF]END........
......tIX.....E.
..i.XT.L...}H...
00:
10:
20:
30:
5445
3f81
2a2f
740a
5854
11a9
0a74
454e
2f2a
2540
6869
4400
0000
ded5
7320
0000
0000
096a
6973
0000
0000
83c9
2061
0000
0000
f191
2074
0000
0000
d8bb
6578
0000
TEXT/*..........
?...%@...j......
*/.this is a tex
t.END...........
Chimera
(if you skip identified bodies, youll miss other files)
image data
a Picture of Cat
(BMP ! uncompressed ! OMG)
Cerbero
same type of heads, one body
an RGB picture...
RGB picture data = bytes triplets for R, G, B colors
Hash collisions
Pwnie award for the best song! err what is it pwning exactly ?
Conclusion
Anges recipes :)
Never forget to:
open your PDFs in a hex editor
open your pictures in a sound player
run your documents in a console emulator
encrypt/decrypt with any cipher
double-check what you printed
Security advice:
DONT *
Its easy to blame others - new insecure paths appear everyday
Research advice:
DO *
PoC||GTFO ! stop the marketing! cheap blamers blatant marketers?
F.F.F. conclusion
many abuses of the specs
specs often are wrong or misleading
ACK
@doegox @pdfkungfoo @veorq @reversity
@travisgoodspeed @sergeybratus qkumba
@internot @gynvael @munin
@solardiz @0xabadidea @ashutoshmehra
lytron @JacobTorrey @thicenl
and anybody who gave me feedback!
Bonus
after the talk, we tried some PoCs on professional
(very expensive!) forensic softwares:
polyglot files
a single file format found + no warning whatsoever
schizophrenic files:
no warning yet different tabs of the same software showing
different content :D
**
*this is a valid..
**
Albertini
...TAR & Adobe PDF:
PoC or
____ _____ _____ ___
_
/ ___|_
_| ___/ _ \ | |
| | _ | | | |_ | | | ||_|
| |_| | | | | _|| |_| | _
\____| |_| |_|
\___/ |_|
%PDF-1.
trailer<</Root<</Pages<<>>>>>>
Solar Designer made a great keynote - thats actually a real game to play!
But one have to load and play through the game - not so accessible!
http://openwall.com/presentations/ZeroNights2014-Is-Infosec-A-Game/
a PDF:
containing the game as ZIP
hand-written
with walkthroughs screenshots
(in original resolution)
a lightweight title
while maintaining compatibility
a good way to distribute as a single file!
$ unzip -t ZeroNights2014-Is-Infosec-A-Game.pdf
Archive: ZeroNights2014-Is-Infosec-A-Game.pdf
warning [ZeroNights2014-Is-Infosec-A-Game.pdf]:
(attempting to process anyway)
testing: ZN14GAME/
OK
testing: ZN14GAME/COMMON/
OK
...
Quine
prints its own source
Quine Relay
A prints Bs source
B prints As source
A bit of everything
@angealbertini
corkami.com
Damn, that's the second time those alien bastards shot up my ride!