bypassing the maginot line: remotely exploit the hardware ... · •reverse engineering...

41
Bypassing the Maginot Line: Remotely Exploit the Hardware Decoder on Smartphone Xiling Gong Tencent Blade Team

Upload: others

Post on 09-Jul-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Bypassing the Maginot Line: Remotely Exploit the Hardware Decoder on Smartphone

• Xiling Gong

• Tencent Blade Team

Page 2: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Bypassing the Maginot Line: Remotely Exploit the Hardware Decoder

on SmartphoneXiling Gong

Tencent Blade Team

Page 3: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

About Me

Xiling Gong (@GXiling)

Senior security researcher at Tencent Blade Team.

Vulnerability Hunter.

Focus on Android Security, Qualcomm Firmware Security.

Speaker of BlackHat, CanSecWest.

Page 4: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

About Tencent Blade Team

• Founded by Tencent Security Platform Department in 2017

• Focus on security research in the areas of AIoT, Mobile devices, Cloud

virtualization, Blockchain, etc

• Report 200+ vulnerabilities to vendors such as Google, Apple, Microsoft, Amazon

• We talked about how to break Amazon Echo at DEFCON26

• Blog: https://blade.tencent.com

Page 5: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Agenda

• Background• Motivation• Stagefright Vulnerabilities• Hardware Decode• Attack Vector • Roadmap for Attack

• Debug Venus

• Reverse Engineering

• Vulnerability and Exploitation

Page 6: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Motivations

To improve the overall state of mobile security • From attacker’s view• Discover new critical (remote) attack surface • Discover weakness of mitigations

Page 7: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Android Media Architecture

https://source.android.com/devices/media/

Page 8: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Stagefright Summary

Parse FileFetch Data Demux

Decode Video

Decode Audio

Source Extractor Demuxer Decoder

Software Decoder

Hardware Decoder

sample.mp4https://sample.url

Mpeg4Extrator

video/avc

AAC Decoder

OMX.google.h264.encoder

OMX.qcom.video.decoder.avc

Page 9: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Stagefright Vulnerabilities

200+Parse FileFetch Data Demux

Decode Video

Decode Audio

Software Decoder

Hardware Decoder

video/avc

AAC Decoder

OMX.google.h264.encoder

Page 10: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Hardening Media-Stack

Bomb Clearance

Page 11: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Stagefright Summary

Parse FileFetch Data Demux

Decode Video

Decode Audio

Source Extractor Demuxer Decoder

Software Decoder

Hardware Decoder

sample.mp4https://sample.url

Mpeg4Extrator

video/avc

AAC Decoder

OMX.google.h264.encoder

OMX.qcom.video.decoder.avc

Page 12: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Android Media – Hardware Codec

Page 13: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Decoder - Software vs Hardware

platform/frameworks/av/media/stagefright

Software Decoder Hardware Decoder

cat /vendor/etc/media_codec.xml

Page 14: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Hardware Decoder - High Priority

Page 15: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Hardware Decoder Overview

Stagefright

OMX Hardware Decoder Components

Venus

Android/Linux

Hardware Decoder

Page 16: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Overall Roadmap - RCE in Venus

Linux KernelVenus

Page 17: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Remote Attack Vector

Browser MMS Instant Message App

Page 18: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Agenda

• Background

• Debug Venus

• Reverse Engineering

• Vulnerability and Exploitation

Page 19: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Debug Venus

• A – Secure Boot Vulnerability

• B – Local Venus Vulnerability

• C – Development Board

• D – Buy a phone with Secure Boot disable…

Page 20: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Venus Debugger

Page 21: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Agenda

• Background

• Debug Venus

• Venus Reverse Engineering• OMX Component and Driver (Linux Side)

• OMX Architecture• OMX Qualcomm Video

• Venus• Memory Layout• Registers• Modules• Attack Surfaces

• Vulnerability and Exploitation

Page 22: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Venus OverviewStagefright

OMX Hardware Decoder Components

/dev/video?

Venus Kernel Driver

Venus Firmware

Venus HFI (Host Firmware Interface)

ARM

Venus

Venus Hardware

Decoded Video

Compressed Raw Data

Page 23: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

OMX - Arch.

https://www.khronos.org/openmax/

MediaPlayerMediaCodec…

OMX.h

libOmxVdec.solibqomx_core.so

Page 24: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

OMX Qualcomm Video

MediaCodec

Command Q

OmxVdec Linux

V4L2create_instance /dev/video32

alloc_input_buffer

alloc_output_buffer/dev/ion

HFI

empty_this_buffer

fill_this_buffer

Venus

iova

empty_buffer_done

Bitstream

YUV fill_buffer_done

OMX IL

ION

Page 25: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Venus Hardware

Qualcomm Venus

Venus Firmware

HFI

Venus

FPGA?

ARM

ARM 32Bit

Shared Memory

Internal Registers

Control Registers

GetBits Engine

Compressed Data

Pre-Processing

Hardware Decode

Page 26: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Firmware & Memory Layout

Code

Heap StackGlobal Data

Static E0000000 E00FF000 Register Area

Dynamic 70800000 708F0000 Shared Memory (Message Queue)

Dynamic 70A00000 … Shared Memory (Input Buffers)

Dynamic 70A00000 … Shared Memory (Output Buffers)

Page 27: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Registers

• Control Registers• vidc_hfi_io.h

• GetBits Register

• Hardware Decoder Registers

Page 28: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Firmware Module

Linux Venus

Main Thread

Command Q

CreateDecoder

H264 Decoder

HandleSessionCmd

HandleSysCmd

Forward Task

HwSDE Task

Hw SP Task

BackwardTask

HW

CCE

Decoder

PostProc

Page 29: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Qualcomm Venus Attack Surface

Firmware

Venus

FPGA

ARM

Compressed Data Decoded Data

Hardware Decoding

Pre-ProcessingHead ParsingBuffer Management

Page 30: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Agenda

• Background

• Debug Venus

• Reverse Engineering

• Vulnerability and Exploitation

Page 31: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Mitigation Table

Mitigation Status

Heap ASLR N

Heap Cookie N

Stack Cookie Y

Code & Global Data ASLR N

W^X Y

CFI N

Page 32: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

The Vulnerability(CVE-2019-2256)

Parsing H264 SPS Head

Page 33: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

The Exploitation

Overwrite the decoderInstance on the heap

Page 34: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Control the PC and R0

Page 35: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Control the PC and R0 (Heap Spray)

Overflow…decoder1 decoder15

Linear Heap with First-Fit Algorithm

decoder1

decoder16

SPS Buffer15decoder15

Known

Page 36: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

ROP Chain (Key ROP Gadget)

Setup LR to 0x40854

Do job and jump back to 0x40854

Load R0, Next Gadget and Call

The final Gadget. Perfect, Setup all!

Page 37: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Demo

Page 38: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Conclusions and Future Works

Linux KernelVenus

We are here!

H264H265VPXVC1Mpeg2

Page 39: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

Future Works

• 1. Escaping into Linux?

• 2. Other File Formats• H265, VPx, VC1, Mpeg2…

• 3. Other Vendors

• 4. How to improve the security status?• NON-Open Source components• Fuzzing Venus?

Page 40: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

3-Takeaways

• The new remote attack surface• Hardware Decoder• Bypassing the protections• Deep into the heart!

• How Qualcomm Hardware Decoder works• Qualcomm Venus

• The vulnerability and exploitation of Venus

Page 41: Bypassing the Maginot Line: Remotely Exploit the Hardware ... · •Reverse Engineering •Vulnerability and Exploitation. Mitigation Table Mitigation Status Heap ASLR N Heap Cookie

THANK YOU

https://blade.tencent.com