reflash: what’s the cve? · instrumentation • works by injecting code to the flash opcode...

18
REFLASH: WHAT’S THE CVE? Jarkko Turkulainen / F-Secure / AVAR 2016

Upload: others

Post on 20-Mar-2020

20 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

REFLASH: WHAT’S THE CVE?

Jarkko Turkulainen / F-Secure / AVAR 2016

Page 2: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20162

ABOUT ME

• Senior Researcher, working on prevalent threats

• Joined F-Secure in 2004

• Background in R&D (engine dev) and malware analysis

• Reflash background: what’s the CVE?

Page 3: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20163

ADOBE FLASH• Flash platform: rich graphics for web, games, videos, music

• Been around since 90’s (FutureSplash Animator -95, sold to MacroMedia)

• Current platform: ActionScript 3, ActionScript Virtual Machine 2 (AVM2)

• Flash Player 9 (AS3, AVM2) released June 2006

• Plagued by bugs, several major zero days 2010-2016

• Flash still around, mainly because of money in the ads

Page 4: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20164

PROBLEMS WITH FLASH RESEARCH

• Lack of flash debugging tools

• Obfuscations, protection systems

• Inline loading of embedded flash content (usually several layers)

Page 5: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20165

REFLASH?

• Framework for assembly-level flash analysis

• Record-and-replay debugging

• Works by instrumenting flash files “on the wire”

Exploit Kit Reflash proxyInjected bytecode

Stack frames, inline SWF

Record analysis

HTTP(S) HTTP(S)

Page 6: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20166

AVM2• Runs ActionScript3

• Open sourced (Tamarin / Mozilla)

• Stack VM

• Runs Just-in-Time compiled bytecode (JIT major problem)

• No official tools for assembly-level debugging

Page 7: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20167

TYPICAL AVM2 OPCODE

Closure call (opcode 0x41)

• stack: function, receiver, args …

• function: closure being called

• receiver: object for “this” value

• args: arguments passed for the function

• After function call: stack is cleared, and result is pushed onto the stack

• Example: flash.display.Loader::loadBytes

Page 8: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20168

INSTRUMENTATION• Works by injecting code to the flash opcode stream

• Three types of code injection:• Method entry hook

• Generic opcode hook for collecting stack frames

• Generic post-opcode hook

• Flash files are disassembled, and assembled back after instrumentation

• Analogous to Intel x86 inline hooking (a’la Detours static PE modification)

• No signatures or other integrity measures in flash! (like java)

Page 9: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 20169

INSTRUMENTATION

• Injected opcodes change branch targets

• Targets are absolute within the method frame• If target is before injection, it remains the same

• If target is after injection, it needs to be adjusted

branch 1 -> 0

branch 2 -> X

branch 2 -> X+N

branch 1 -> 0

offset 0

offset X

offset X+N

N opcodes

offset 0

Page 10: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201610

PROXY

• Driver for instrumentation, result gathering, database creation

• Implementation: python mitmproxy

• Track incoming flash files real-time

• Flash files coming from two directions: from the network and from the loadBytes hooks

Page 11: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201611

GENERIC STACK FRAME HOOK

• Arbitrary opcode can be hooked

• Hooks pack stack frames prior to opcode execution

• Also the type of stack frame data (as known by AVM2) is packed

• Data is sent to proxy with asynchronous TCP connection

Page 12: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201612

LOADBYTES HOOK• Application of generic stack frame hook

• All call hooks are examined further:• Called object: flash.display::Loader?

• First argument: ByteArray with flash file?

• If inline flash file is detected, it is sent back to proxy synchronously

• Stack argument replaced by received (re)flash(ed) file

• Stealthy instrumentation of inline flash files

Page 13: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201613

POST-OPCODE HOOK

• Opcodes can also be hooked for manipulating resulting stack values

• Reflash implements one specific post-opcode hook, getproperty:• Modify flash.system::Capabilites: flash version, example: “WIN 15,0,0,203”

• Modify flash.system::Capabilites: OS version, example: “Windows XP”

• Purpose of getproperty post-hook is to add flexibility for Exploit Kit testing

Page 14: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201614

RECORD-AND-REPLAY

• Generic hooks send stack frames back to the proxy

• Stack frames are packed with AMF (ActionScript Message Format)

• Proxy records stack frames in SQL database

• Static stack frame meta-data also written to the database (disassemblies)

• With the database, coherent view of execution can be formed afterwards

Page 15: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

© F-Secure Confidential15

RECORD-AND-REPLAY

Page 16: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201616

CVE DETECTION: HYBRID APPROACH

• Usually exploits abuse function arguments

• Reflash features running YARA against stack frame data

• Fully generic solution is not possible (what’s the CVE?)

• Static CVE signatures cannot be used without heavy dynamic processing (protection systems, inline flash files...)

Page 17: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201617

SO WHAT’S THE CVE?

© MMPC blog June 2016

Page 18: REFLASH: WHAT’S THE CVE? · INSTRUMENTATION • Works by injecting code to the flash opcode stream • Three types of code injection: • Method entry hook • Generic opcode hook

Reflash / Jarkko Turkulainen / AVAR 201618

RELATED WORK

• FlashHacker (Jeong Wook Oh)

• JPEXS debugging support

• Timo Hirvonen’s Sulo