SlideShare a Scribd company logo
1 of 28
Download to read offline
Behind the PWN of a TrustZone
from untrusted app to trustzone kernel code exec
Nick Stephens
Bio
- Nick from Shellphish
- Worked on the Cyber Grand Challenge and research papers
- Automated Bug Finding and Exploitation
- TrustZone and Android bugs
- Played a lot of CTF
- Submitted TrustZone research to GeekPwn 2016
The Goal
Complete compromise of a smartphone
From an untrusted app compromise the ‘TEE’
Trusted Execution Environment
Disable the Fingerprint Sensor the TEE controls
The exploit chain
Android TEE
EL0 - Userland
EL1 - Kernel
Secure EL0 - Trusted Apps
Secure EL1 - TEE OS
Secure Storage
Secure Payment
Biometric Sensors
Trusted UI
Trusted Core
Start executing
code here
Get code execution here
The modern mobile security architecture
Android TEE
EL0 - Userland
EL1 - Kernel
Secure EL0 - Trusted Apps
Secure EL1 - TEE OS
Secure Storage
Secure Payment
Biometric Sensors
Trusted UI
Trusted Core
Disclaimer - Chipset determines the TEE
- The TEE implementation is closely tied to the chipset of the phone
- Qualcomm, Samsung, etc have their own implementations
- All bugs discussed are tied to one chipset line in particular
TrustZone system architecture
Android App
teecd
tc_ns_client
TEE Connection Daemon
TEE Global Task
Secure Storage
Keymaster
ta_finger
Trusted
Core
ioctls to driver
smc to trustlets*
svc calls to trusted kernel
retrieve tc_ns_client fd
TEE kernel driver
Trustlets
Step 1 - Userland to Kernel
- Target the Trustzone driver
- ‘Logs in’ userland apps, maintains a form of session management
- Relies on teecd to perform the ‘log in’ before giving app control
- Proxy calls to trustlets from userland
- Manages messaging primitives for trustlet communication
- Support for passing ‘memory references’ and integer values
- Sanitizes parameters sent to trustlets
- Two vulnerabilities, CVE-2016-8762 and CVE-2016-8763
Android App
tc_ns_client
ioctls to driver
- The TrustZone kernel, known as the Trusted Core, has a virtual address space which is 1-to-1 with physical addresses
- Trustlets need to have these physical addresses translated for them as they exist in their own virtual address space (with
ASLR )
- But the normal kernel has no insight into where destination trustlets are mapped
Into CVE-2016-8762 - The TEE address space
Normal
World
Kernel
Destination Trustlet
Trusted
Core
Pass Parameters
expressed as
physical
addresses
Pass Parameters
as virtual
addresses
Translates and maps in pages from
the normal world to the destination’s
address space
- Occurs when preparing an app’s parameters for trustzone translation
- No sanitization on memref.offset parameter
CVE-2016-8762 - An OOB with a Twist
- shared_mem->kernel_addr + client_param->memref.offset
- We can pass the physical address of any page mapped in
- Our goal: overwrite a file’s operations table pointer
file operations *
fd rop lseek
rop ioctl
Exploitation
offset
permissions
...
User
Kernel
ext4_read
ext4_ioctl
ext4_lseek
rop gadgets
str x1, [x2];
ret;
ldr x0, [x1];
ret;
- Find a Trustlet function which will write a value to the address we provide
Exploitation - Redirecting the fops table
GLOBAL_CMD_ID_NEED_LOAD_APP handler, writes a 32-bit 1 or 0
- Issue several calls, writing the a 32-bit 0x1 over the 64-bit fops pointer
Exploitation - Redirecting the fops table
0xff 0xff 0xff 0xc0 0x02 0x12 0xa1 0xc0
0x00 0x00 0x00 0x01 0x02 0x12 0xa1 0xc0
0x00 0x00 0x00 0x00 0x00 0x00 0x01 0xc0
0x00 0x00 0x00 0x00 0x01 0x00 0x01 0xc0
ext4_file_operations
userland memory
- Now overwrite cred struct members with arbitrary write, becoming root
- Target Secure File Storage Trustlet
- Only HiDisk can talk to this, with root the authentication can be bypassed
- Transparently encrypts and decrypts files
- Kernel doesn’t (shouldn’t!) know the key
- Used by the HiDisk application, the ‘Safe’ feature of the Files app
- Type confusion, CVE-2016-8764
Step 2 - Kernel to Trustlet tc_ns_client
Secure Storage
smc to trustlets
TEE kernel driver
Trustlets
Into CVE-2016-8764 - Passing params to a Trustlet
- Support for passing both buffer and integer values to up to TEE
paramTypes encoded here, allows for type
checking inside TEE
CVE-2016-8764 - Read and Write in a Trustlet
- The Secure Storage trustlet never checks paramTypes
- An integer can be confused with a memory reference
- We can write to any address in the trustlet with controlled data and size!
- Similarly, STORAGE_CMD_ID_WRITE can be used to read arbitrarily
Exploitation - Hijacking TEE_Malloc
- TEE_Malloc uses a function pointer table to handle different size classes
- Write to a new secure file with our desired function pointer value, then ‘read’ that over TEE_Malloc’s function pointer
table
- Remember… the Trusted Core takes care of remapping memory references into our trustlet…
- Let’s put our shellcode in a memref and jump there!
Trustlet .text
r-x
Trustlet .bss
rw-
Trusted Core
---
Passed Memrefs
rwx
lower addresses higher addresses
Address space of a Trustlet
Exploitation - One problem… ASLR
- New phones use some OS-level mitigations trustlet loading now implements ASLR
One byte of entropy
- Randomization takes place once, not re-randomized on a reload
Exploitation - Defeating ASLR
- We could bruteforce, 1 byte means at most 256 attempts
- But root can read anything on disk…
- Information leak in /dev/hisi_teelog
Step 3 - Trustlet to the Trusted Core
- Target System calls in the TrustZone kernel
- Provides IPC primitive for message passing between trustlets
- Supports memory address translation
- Directs calls from normal world to requested trustlets
- Has all trustlets in its address space
- One big vulnerability, no CVE :(
Secure Storage
Trusted
Core
svc calls to trusted kernel
One big bug...
NO POINTER SANITIZATION
- Mostly a reverse engineering task
- Find a sequence of system calls which give us arbitrary write
- Don’t need a direct understanding of the syscalls, just primitives
Trusted Core Environment
- No ASLR, other access checks require a hardcoded bounds
- PXN, can’t jump to userspace, but no PAN, can access userspace
- No DEP, kernel heap is executable
- Supports over 300 system calls, some behind permission checks
Trusted Core - Finding Primitives
- No magical ‘write arg 1 to arg 0’ system calls
- We do have system calls to
- 0xf1c8 - Write an allocated pointer, points to a 16-byte string we control
- 0xf079 - Allocate an arbitrary size kernel heap buffer and return its address
- 0xf0c3 - Write an uncontrolled dynamic value from a linked list in the kernel
- 0xf04a - Copy the trustlet’s process name to an arbitrary address
- 0xc0d8 - Leak arbitrarily via an int overflow
Trusted Core - Combining the Pieces
Use 0xf079 to allocate a kernel buffer for our trusted core shellcode
Use 0xc0d8 to leak addresses of string table pointers
Use 0xf1c8 to write over 0xf0c3’s linked-list pointer to a string containing our stack pointer
0xf0c3 can now write the address of our stack anywhere - write over the process name string table
0xf04a can now be used to write our stack contents anywhere - update our stack to change value
Write in our kernel shellcode, write over a function pointer, trigger function pointer call
Step 4 - Disable Fingerprint Auth
- Find trustlet responsible for recognizing fingerprints
- Reverse and hot patch it
- But where is it?
- Fingerprint checking logic should be complex, larger than 100K
Follow the userland daemon
- Reverse fingerprintd
- It has lib_fpc_tac_shared.so mapped in… what’s that?
- lib_fpc_tac_shared.so requests to load /system/bin/fd1bbfb2-9a62-4b27-8fdb-a503529076af.sec?
- Encrypted trustlet
Finding and patching
- With TrustedCore code exec we can dump the decrypted memory
- Crawl TEE memory for ARM instructions, dump surrounding areas to disk
- Check dumps for any references to fingerprints
- fpc, fingerprint, fingerprintd
- Now just reverse and patch!
Questions?

More Related Content

What's hot

Understanding &Troubleshooting the Windows Logon Process
Understanding &Troubleshooting the Windows Logon ProcessUnderstanding &Troubleshooting the Windows Logon Process
Understanding &Troubleshooting the Windows Logon ProcessControlUp
 
LCU14-103: How to create and run Trusted Applications on OP-TEE
LCU14-103: How to create and run Trusted Applications on OP-TEELCU14-103: How to create and run Trusted Applications on OP-TEE
LCU14-103: How to create and run Trusted Applications on OP-TEELinaro
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Jarod Wang
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android EmulatorSamael Wang
 
Linux Kernel Crashdump
Linux Kernel CrashdumpLinux Kernel Crashdump
Linux Kernel CrashdumpMarian Marinov
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
SFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driverSFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driverLinaro
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3Linaro
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtAnne Nicolas
 
SFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEESFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEELinaro
 
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制裝機安 Angelo
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in LinuxAdrian Huang
 
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !Pierre-jean Texier
 
OpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-ServiceOpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-ServiceRamon Acedo Rodriguez
 
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEEBKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEELinaro
 
Android起動周りのノウハウ
Android起動周りのノウハウAndroid起動周りのノウハウ
Android起動周りのノウハウchancelab
 
Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updatedCsw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updatedCanSecWest
 
UEFI Firmware Rootkits: Myths and Reality
UEFI Firmware Rootkits: Myths and RealityUEFI Firmware Rootkits: Myths and Reality
UEFI Firmware Rootkits: Myths and RealitySally Feller
 
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysDaniel Bryant
 

What's hot (20)

Understanding &Troubleshooting the Windows Logon Process
Understanding &Troubleshooting the Windows Logon ProcessUnderstanding &Troubleshooting the Windows Logon Process
Understanding &Troubleshooting the Windows Logon Process
 
LCU14-103: How to create and run Trusted Applications on OP-TEE
LCU14-103: How to create and run Trusted Applications on OP-TEELCU14-103: How to create and run Trusted Applications on OP-TEE
LCU14-103: How to create and run Trusted Applications on OP-TEE
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
 
Linux Kernel Crashdump
Linux Kernel CrashdumpLinux Kernel Crashdump
Linux Kernel Crashdump
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
SFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driverSFO15-200: Linux kernel generic TEE driver
SFO15-200: Linux kernel generic TEE driver
 
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
LAS16-111: Easing Access to ARM TrustZone – OP-TEE and Raspberry Pi 3
 
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven RostedtKernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
Kernel Recipes 2017 - Understanding the Linux kernel via ftrace - Steven Rostedt
 
SFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEESFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEE
 
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
【VM保護備份專題】Dell Power Protect Data Manager (PPDM) 詳解TSDM機制
 
malloc & vmalloc in Linux
malloc & vmalloc in Linuxmalloc & vmalloc in Linux
malloc & vmalloc in Linux
 
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
Diving into SWUpdate: adding new platform support in 30minutes with Yocto/OE !
 
OpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-ServiceOpenStack Ironic - Bare Metal-as-a-Service
OpenStack Ironic - Bare Metal-as-a-Service
 
Kernel Debugging & Profiling
Kernel Debugging & ProfilingKernel Debugging & Profiling
Kernel Debugging & Profiling
 
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEEBKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
BKK16-110 A Gentle Introduction to Trusted Execution and OP-TEE
 
Android起動周りのノウハウ
Android起動周りのノウハウAndroid起動周りのノウハウ
Android起動周りのノウハウ
 
Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updatedCsw2017 bazhaniuk exploring_yoursystemdeeper_updated
Csw2017 bazhaniuk exploring_yoursystemdeeper_updated
 
UEFI Firmware Rootkits: Myths and Reality
UEFI Firmware Rootkits: Myths and RealityUEFI Firmware Rootkits: Myths and Reality
UEFI Firmware Rootkits: Myths and Reality
 
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API GatewaysITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
ITKonekt 2023: The Busy Platform Engineers Guide to API Gateways
 

Similar to Nick Stephens-how does someone unlock your phone with nose

LAS16 111 - Raspberry pi3, op-tee and jtag debugging
LAS16 111 - Raspberry pi3, op-tee and jtag debuggingLAS16 111 - Raspberry pi3, op-tee and jtag debugging
LAS16 111 - Raspberry pi3, op-tee and jtag debugging96Boards
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware
 
Computer network (4)
Computer network (4)Computer network (4)
Computer network (4)NYversity
 
Looking into trusted and encrypted keys
Looking into trusted and encrypted keysLooking into trusted and encrypted keys
Looking into trusted and encrypted keysSUSE Labs Taipei
 
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT TalksMykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT TalksVadym Muliavka
 
SREcon Europe 2016 - Full-mesh IPsec network at Hosted Graphite
SREcon Europe 2016 - Full-mesh IPsec network at Hosted GraphiteSREcon Europe 2016 - Full-mesh IPsec network at Hosted Graphite
SREcon Europe 2016 - Full-mesh IPsec network at Hosted GraphiteHostedGraphite
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and sslMohd Arif
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualFreyrSCADA Embedded Solution
 
Oleksyk applied-anti-forensics
Oleksyk   applied-anti-forensicsOleksyk   applied-anti-forensics
Oleksyk applied-anti-forensicsDefconRussia
 
client-server communication using socket IPC
client-server communication using socket IPCclient-server communication using socket IPC
client-server communication using socket IPCNarayanlalMenariya
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack webhostingguy
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Cysinfo Cyber Security Community
 
Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?Jérôme Petazzoni
 
Securing Cassandra The Right Way
Securing Cassandra The Right WaySecuring Cassandra The Right Way
Securing Cassandra The Right WayDataStax Academy
 
How to exploit heartbleed vulnerability demonstration
How to exploit heartbleed vulnerability demonstrationHow to exploit heartbleed vulnerability demonstration
How to exploit heartbleed vulnerability demonstrationPankaj Rane
 
Cisco Router and Switch Security Hardening Guide
Cisco Router and Switch Security Hardening GuideCisco Router and Switch Security Hardening Guide
Cisco Router and Switch Security Hardening GuideHarris Andrea
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1 securityxploded
 

Similar to Nick Stephens-how does someone unlock your phone with nose (20)

LAS16 111 - Raspberry pi3, op-tee and jtag debugging
LAS16 111 - Raspberry pi3, op-tee and jtag debuggingLAS16 111 - Raspberry pi3, op-tee and jtag debugging
LAS16 111 - Raspberry pi3, op-tee and jtag debugging
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor
 
Computer network (4)
Computer network (4)Computer network (4)
Computer network (4)
 
Looking into trusted and encrypted keys
Looking into trusted and encrypted keysLooking into trusted and encrypted keys
Looking into trusted and encrypted keys
 
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT TalksMykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks
Mykhailo Zarai "Be careful when dealing with C++" at Rivne IT Talks
 
SREcon Europe 2016 - Full-mesh IPsec network at Hosted Graphite
SREcon Europe 2016 - Full-mesh IPsec network at Hosted GraphiteSREcon Europe 2016 - Full-mesh IPsec network at Hosted Graphite
SREcon Europe 2016 - Full-mesh IPsec network at Hosted Graphite
 
Ip sec and ssl
Ip sec and  sslIp sec and  ssl
Ip sec and ssl
 
LINUX Device Drivers
LINUX Device DriversLINUX Device Drivers
LINUX Device Drivers
 
IEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manualIEC 60870-5 101 Protocol Server Simulator User manual
IEC 60870-5 101 Protocol Server Simulator User manual
 
Oleksyk applied-anti-forensics
Oleksyk   applied-anti-forensicsOleksyk   applied-anti-forensics
Oleksyk applied-anti-forensics
 
client-server communication using socket IPC
client-server communication using socket IPCclient-server communication using socket IPC
client-server communication using socket IPC
 
SQL Server Security - Attack
SQL Server Security - Attack SQL Server Security - Attack
SQL Server Security - Attack
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1
 
Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?Docker, Linux Containers, and Security: Does It Add Up?
Docker, Linux Containers, and Security: Does It Add Up?
 
Securing Cassandra The Right Way
Securing Cassandra The Right WaySecuring Cassandra The Right Way
Securing Cassandra The Right Way
 
How to exploit heartbleed vulnerability demonstration
How to exploit heartbleed vulnerability demonstrationHow to exploit heartbleed vulnerability demonstration
How to exploit heartbleed vulnerability demonstration
 
ENFS
ENFSENFS
ENFS
 
Cisco Router and Switch Security Hardening Guide
Cisco Router and Switch Security Hardening GuideCisco Router and Switch Security Hardening Guide
Cisco Router and Switch Security Hardening Guide
 
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1  Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
Advanced Malware Analysis Training Session 2 - Botnet Analysis Part 1
 
Mmp hotos2003-slides
Mmp hotos2003-slidesMmp hotos2003-slides
Mmp hotos2003-slides
 

More from GeekPwn Keen

PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...
PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...
PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...GeekPwn Keen
 
THE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGE
THE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGETHE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGE
THE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGEGeekPwn Keen
 
TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...
TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...
TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...GeekPwn Keen
 
TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team - DEF CON 26 CAA...
TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team -  DEF CON 26 CAA...TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team -  DEF CON 26 CAA...
TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team - DEF CON 26 CAA...GeekPwn Keen
 
ADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGE
ADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGEADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGE
ADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGEGeekPwn Keen
 
HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...
HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...
HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...GeekPwn Keen
 
BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...
BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...
BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...GeekPwn Keen
 
RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...
RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...
RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...GeekPwn Keen
 
WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...
WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...
WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...GeekPwn Keen
 
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...GeekPwn Keen
 
Huiming Liu-'resident evil' of smart phones--wombie attack
Huiming Liu-'resident evil' of smart phones--wombie attackHuiming Liu-'resident evil' of smart phones--wombie attack
Huiming Liu-'resident evil' of smart phones--wombie attackGeekPwn Keen
 
Zhiyun Qian-what leaves attacker hijacking USA Today site
Zhiyun Qian-what leaves attacker hijacking USA Today siteZhiyun Qian-what leaves attacker hijacking USA Today site
Zhiyun Qian-what leaves attacker hijacking USA Today siteGeekPwn Keen
 
Bo Li-they’ve created images that reliably fool neural network
Bo Li-they’ve created images that reliably fool neural networkBo Li-they’ve created images that reliably fool neural network
Bo Li-they’ve created images that reliably fool neural networkGeekPwn Keen
 
Alexey kurakin-what's new in adversarial machine learning
Alexey kurakin-what's new in adversarial machine learningAlexey kurakin-what's new in adversarial machine learning
Alexey kurakin-what's new in adversarial machine learningGeekPwn Keen
 

More from GeekPwn Keen (14)

PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...
PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...
PRACTICAL ADVERSARIAL ATTACKS AGAINST CHALLENGING MODELS ENVIRONMENTS - Moust...
 
THE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGE
THE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGETHE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGE
THE VANISHING TRICK FOR SELF-DRIVING CARS - Weilin Xu - DEF CON 26 CAAD VILLAGE
 
TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...
TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...
TARGETED ADVERSARIAL EXAMPLES FOR BLACK BOX AUDIO SYSTEMS - Rohan Taori, Amog...
 
TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team - DEF CON 26 CAA...
TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team -  DEF CON 26 CAA...TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team -  DEF CON 26 CAA...
TRANSFERABLE ADVERSARIAL PERTURBATIONS - Tencent Blade Team - DEF CON 26 CAA...
 
ADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGE
ADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGEADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGE
ADVERSARIAL^2 TRAINING - Yao Zhao, Yuzhe Zhao - DEF CON 26 CAAD VILLAGE
 
HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...
HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...
HOW TO LEVERAGE THE OPEN-SOURCE INFORMATION TO MAKE AN EFFECTIVE ADVERSARIAL ...
 
BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...
BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...
BOOSTING ADVERSARIAL ATTACKS WITH MOMENTUM - Tianyu Pang and Chao Du, THU - D...
 
RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...
RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...
RECENT PROGRESS IN ADVERSARIAL DEEP LEARNING ATTACK AND DEFENSE - Wenbo Guo a...
 
WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...
WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...
WEAPONS FOR DOG FIGHT:ADAPTING MALWARE TO ANTI-DETECTION BASED ON GAN - Zhuan...
 
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...
Hardware Trojan Attacks on Neural Networks - Joseph Clements - DEF CON 26 CAA...
 
Huiming Liu-'resident evil' of smart phones--wombie attack
Huiming Liu-'resident evil' of smart phones--wombie attackHuiming Liu-'resident evil' of smart phones--wombie attack
Huiming Liu-'resident evil' of smart phones--wombie attack
 
Zhiyun Qian-what leaves attacker hijacking USA Today site
Zhiyun Qian-what leaves attacker hijacking USA Today siteZhiyun Qian-what leaves attacker hijacking USA Today site
Zhiyun Qian-what leaves attacker hijacking USA Today site
 
Bo Li-they’ve created images that reliably fool neural network
Bo Li-they’ve created images that reliably fool neural networkBo Li-they’ve created images that reliably fool neural network
Bo Li-they’ve created images that reliably fool neural network
 
Alexey kurakin-what's new in adversarial machine learning
Alexey kurakin-what's new in adversarial machine learningAlexey kurakin-what's new in adversarial machine learning
Alexey kurakin-what's new in adversarial machine learning
 

Nick Stephens-how does someone unlock your phone with nose

  • 1. Behind the PWN of a TrustZone from untrusted app to trustzone kernel code exec Nick Stephens
  • 2. Bio - Nick from Shellphish - Worked on the Cyber Grand Challenge and research papers - Automated Bug Finding and Exploitation - TrustZone and Android bugs - Played a lot of CTF - Submitted TrustZone research to GeekPwn 2016
  • 3. The Goal Complete compromise of a smartphone From an untrusted app compromise the ‘TEE’ Trusted Execution Environment Disable the Fingerprint Sensor the TEE controls
  • 4. The exploit chain Android TEE EL0 - Userland EL1 - Kernel Secure EL0 - Trusted Apps Secure EL1 - TEE OS Secure Storage Secure Payment Biometric Sensors Trusted UI Trusted Core Start executing code here Get code execution here
  • 5. The modern mobile security architecture Android TEE EL0 - Userland EL1 - Kernel Secure EL0 - Trusted Apps Secure EL1 - TEE OS Secure Storage Secure Payment Biometric Sensors Trusted UI Trusted Core
  • 6. Disclaimer - Chipset determines the TEE - The TEE implementation is closely tied to the chipset of the phone - Qualcomm, Samsung, etc have their own implementations - All bugs discussed are tied to one chipset line in particular
  • 7. TrustZone system architecture Android App teecd tc_ns_client TEE Connection Daemon TEE Global Task Secure Storage Keymaster ta_finger Trusted Core ioctls to driver smc to trustlets* svc calls to trusted kernel retrieve tc_ns_client fd TEE kernel driver Trustlets
  • 8. Step 1 - Userland to Kernel - Target the Trustzone driver - ‘Logs in’ userland apps, maintains a form of session management - Relies on teecd to perform the ‘log in’ before giving app control - Proxy calls to trustlets from userland - Manages messaging primitives for trustlet communication - Support for passing ‘memory references’ and integer values - Sanitizes parameters sent to trustlets - Two vulnerabilities, CVE-2016-8762 and CVE-2016-8763 Android App tc_ns_client ioctls to driver
  • 9. - The TrustZone kernel, known as the Trusted Core, has a virtual address space which is 1-to-1 with physical addresses - Trustlets need to have these physical addresses translated for them as they exist in their own virtual address space (with ASLR ) - But the normal kernel has no insight into where destination trustlets are mapped Into CVE-2016-8762 - The TEE address space Normal World Kernel Destination Trustlet Trusted Core Pass Parameters expressed as physical addresses Pass Parameters as virtual addresses Translates and maps in pages from the normal world to the destination’s address space
  • 10. - Occurs when preparing an app’s parameters for trustzone translation - No sanitization on memref.offset parameter CVE-2016-8762 - An OOB with a Twist - shared_mem->kernel_addr + client_param->memref.offset - We can pass the physical address of any page mapped in
  • 11. - Our goal: overwrite a file’s operations table pointer file operations * fd rop lseek rop ioctl Exploitation offset permissions ... User Kernel ext4_read ext4_ioctl ext4_lseek rop gadgets str x1, [x2]; ret; ldr x0, [x1]; ret;
  • 12. - Find a Trustlet function which will write a value to the address we provide Exploitation - Redirecting the fops table GLOBAL_CMD_ID_NEED_LOAD_APP handler, writes a 32-bit 1 or 0
  • 13. - Issue several calls, writing the a 32-bit 0x1 over the 64-bit fops pointer Exploitation - Redirecting the fops table 0xff 0xff 0xff 0xc0 0x02 0x12 0xa1 0xc0 0x00 0x00 0x00 0x01 0x02 0x12 0xa1 0xc0 0x00 0x00 0x00 0x00 0x00 0x00 0x01 0xc0 0x00 0x00 0x00 0x00 0x01 0x00 0x01 0xc0 ext4_file_operations userland memory - Now overwrite cred struct members with arbitrary write, becoming root
  • 14. - Target Secure File Storage Trustlet - Only HiDisk can talk to this, with root the authentication can be bypassed - Transparently encrypts and decrypts files - Kernel doesn’t (shouldn’t!) know the key - Used by the HiDisk application, the ‘Safe’ feature of the Files app - Type confusion, CVE-2016-8764 Step 2 - Kernel to Trustlet tc_ns_client Secure Storage smc to trustlets TEE kernel driver Trustlets
  • 15. Into CVE-2016-8764 - Passing params to a Trustlet - Support for passing both buffer and integer values to up to TEE paramTypes encoded here, allows for type checking inside TEE
  • 16. CVE-2016-8764 - Read and Write in a Trustlet - The Secure Storage trustlet never checks paramTypes - An integer can be confused with a memory reference - We can write to any address in the trustlet with controlled data and size! - Similarly, STORAGE_CMD_ID_WRITE can be used to read arbitrarily
  • 17. Exploitation - Hijacking TEE_Malloc - TEE_Malloc uses a function pointer table to handle different size classes - Write to a new secure file with our desired function pointer value, then ‘read’ that over TEE_Malloc’s function pointer table - Remember… the Trusted Core takes care of remapping memory references into our trustlet… - Let’s put our shellcode in a memref and jump there! Trustlet .text r-x Trustlet .bss rw- Trusted Core --- Passed Memrefs rwx lower addresses higher addresses Address space of a Trustlet
  • 18. Exploitation - One problem… ASLR - New phones use some OS-level mitigations trustlet loading now implements ASLR One byte of entropy - Randomization takes place once, not re-randomized on a reload
  • 19. Exploitation - Defeating ASLR - We could bruteforce, 1 byte means at most 256 attempts - But root can read anything on disk… - Information leak in /dev/hisi_teelog
  • 20. Step 3 - Trustlet to the Trusted Core - Target System calls in the TrustZone kernel - Provides IPC primitive for message passing between trustlets - Supports memory address translation - Directs calls from normal world to requested trustlets - Has all trustlets in its address space - One big vulnerability, no CVE :( Secure Storage Trusted Core svc calls to trusted kernel
  • 21. One big bug... NO POINTER SANITIZATION - Mostly a reverse engineering task - Find a sequence of system calls which give us arbitrary write - Don’t need a direct understanding of the syscalls, just primitives
  • 22. Trusted Core Environment - No ASLR, other access checks require a hardcoded bounds - PXN, can’t jump to userspace, but no PAN, can access userspace - No DEP, kernel heap is executable - Supports over 300 system calls, some behind permission checks
  • 23. Trusted Core - Finding Primitives - No magical ‘write arg 1 to arg 0’ system calls - We do have system calls to - 0xf1c8 - Write an allocated pointer, points to a 16-byte string we control - 0xf079 - Allocate an arbitrary size kernel heap buffer and return its address - 0xf0c3 - Write an uncontrolled dynamic value from a linked list in the kernel - 0xf04a - Copy the trustlet’s process name to an arbitrary address - 0xc0d8 - Leak arbitrarily via an int overflow
  • 24. Trusted Core - Combining the Pieces Use 0xf079 to allocate a kernel buffer for our trusted core shellcode Use 0xc0d8 to leak addresses of string table pointers Use 0xf1c8 to write over 0xf0c3’s linked-list pointer to a string containing our stack pointer 0xf0c3 can now write the address of our stack anywhere - write over the process name string table 0xf04a can now be used to write our stack contents anywhere - update our stack to change value Write in our kernel shellcode, write over a function pointer, trigger function pointer call
  • 25. Step 4 - Disable Fingerprint Auth - Find trustlet responsible for recognizing fingerprints - Reverse and hot patch it - But where is it? - Fingerprint checking logic should be complex, larger than 100K
  • 26. Follow the userland daemon - Reverse fingerprintd - It has lib_fpc_tac_shared.so mapped in… what’s that? - lib_fpc_tac_shared.so requests to load /system/bin/fd1bbfb2-9a62-4b27-8fdb-a503529076af.sec? - Encrypted trustlet
  • 27. Finding and patching - With TrustedCore code exec we can dump the decrypted memory - Crawl TEE memory for ARM instructions, dump surrounding areas to disk - Check dumps for any references to fingerprints - fpc, fingerprint, fingerprintd - Now just reverse and patch!