SlideShare a Scribd company logo
1 of 31
Download to read offline
Attacking your “Trusted Core”
Exploiting TrustZone on Android
Di Shen (@returnsme)
BlackHat USA 15
• Background
- About Huawei Ascend Mate 7
- TEE architecture of Huawei Hisilicon
- Attack Surface
• Vulnerability in Normal World
- technical details
- gain root privilege
• Vulnerabilities in Secure World (TEE)
- technical details
- read fingerprint image from sensor / bypass sec features
• Conclusion
Agenda
•Security researcher from Qihoo 360
•Mainly focus on Android
•Always like console games and manga/anime
Who am I
Background
Huawei Ascend Mate 7
•HiSilicon Kirin 925 SoC chipset
•HiSilicon implemented its own TEE kernel(Trusted
Core)
•the world s first Android smartphone with touch
fingerprint sensor, featuring FPC1020
•1 million units sold by Huawei in the first month
Fingerprint: protected by SecureOS
TEE architecture of Huawei
SMC
PWNED
PWNED
PWNED
• TZDriver
- accepting malformed ioctl command may allow installed application to execute
arbitrary code in Linux Kernel.
• Trusted Application
- mistake in input structure bound-check may lead to an arbitrary code execution
vulnerability in TEE
• TEE kernel
- system call bugs may allow a malicious TA to escalate privilege
Attack Surface
Attack “TrustedCore”
Attack TZdriver
installed
application
Attack TA
Attack TEE kernel
Send ioctl command
execute SMC instructions
system call
Vulnerability in Normal World
• Accessible to any installed applications
• provide communication APIs between NW and SW
• provide an ioctl interface to both user space clients and other
kernel module
- for user clients,use copy_to_user/copy_from_user to copy
input /output param buffer
- for kernel modules, use memcpy directly
TZDriver: /dev/tc_ns_client
TC_NS_ClientContext
typedef struct {
unsigned char uuid[16];
unsigned int session_id;
unsigned int cmd_id;
TC_NS_ClientReturn returns;
TC_NS_ClientLogin login;
unsigned int paramTypes;//type of input param
TC_NS_ClientParam params[4];//address or value of input
bool started;
} TC_NS_ClientContext;
TC_NS_ClientParam
typedef union {
struct {
unsigned int buffer; //ptr of buffer
unsigned int offset; //size of buffer
unsigned int size_addr;
} memref;
struct {
unsigned int a_addr; //ptr of a 4-bytes buffer
unsigned int b_addr; //ptr of a 4-bytes buffer
} value;
} TC_NS_ClientParam;
What if user client send a kernel pointer to driver?
Kernel memory overwriting
static int TC_NS_SMC_Call(TC_NS_ClientContext *client_context,TC_NS_DEV_File
*dev_file, bool is_global){
....
// build a TC_NS_SMC_CMD struct
....
// execute SMC instruction
TC_NS_SMC(smc_cmd_phys);
// copy result from smc_cmd.operation_phys to callers' buffer(client_param.value)
if(client_operation->params[0].value.a> 0xbfffffff){
//driver think caller is from kernel space
*(u32 *)client_param->value.a_addr = operation->params[i].value.a;
}
else{
//driver think caller is from user space
copy_to_user(....);
}
if(client_operation->params[0].value.b > 0xbfffffff){
*(u32 *)client_param->value.b_addr = operation->params[i].value.b;
}
else{
copy_to_user(....);
}
....
}
CVE ID : CVE-2015-4421
ret2user
•Extract TEE image from firmware.Using
HuaweiUpdateExtractor.exe
•TEEOS.img is not encrypted.Drag into IDA.
•Find a interface provided by TA will return a
stable “TZvalue”.
How to find a stable “TZValue”
Time querying interface in
TEEGlobalTask
int get_sys_time()
{
int result; // r0@1
tag_TC_NS_Operation *v1; // r3@1
unsigned int v2; // [sp+0h] [bp-10h]@1
int v3; // [sp+4h] [bp-Ch]@1
get_time((int)&v2);
result = 0;
v1 = dword_5E2E0->operation_phys;
v1->params[0].value.a = v2; //second from startup
v1->params[0].value.b = 1000 * v3; //millisecond
return result;
}
Vulnerabilities in Secure World
• now I can execute SMC instruction by TZDriver ret2user
exploit

• SMC param: a pointer to structure TC_NS_SMC_CMD
Send malformed request to TA
typedef struct tag_TC_NS_SMC_CMD{
unsigned int uuid_phys;
unsigned int cmd_id;
unsigned int dev_file_id;
unsigned int context_id;
unsigned int agent_id;
unsigned int operation_phys;
unsigned int login_method;
unsigned int login_data;
unsigned int err_origin;
bool started;
} TC_NS_SMC_CMD;
review:Time querying interface in
TEEGlobalTask
int get_sys_time()
{
int result; // r0@1
tag_TC_NS_Operation *v1; // r3@1
unsigned int v2; // [sp+0h] [bp-10h]@1
int v3; // [sp+4h] [bp-Ch]@1
get_time((int)&v2);
result = 0;
operation_phys = dword_5E2E0->operation_phys;
*(int*)(operation_phys+4) = v2;
*(int*)(operation_phys+8) = 1000 * v3;
return result;
}
CVE ID : CVE-2015-4422
• no security checking on operation_phys
• if second = 0xAABBCCDD,every time we can write 4 byte
“DD,CC,BB,AA” at operation_phys + 4
• The “DD” is the last byte of second and cycle from 0x00 to
0xFF.
• Write a byte you want at a right second ——arbitrary
physical address overwriting
arbitrary physical memory overwriting
• Main idea
- patch text code of TEEGlobalTask,call TEE function and
return to my shellcode

• Good news:
- few mitigation in RTOSck, the kernel of TEE
- No ASLR , XN or “unwritable Text code”.
• Bad news:
- I don’t know where to patch without base address of
TEEGlobalTask
• Don’t give up:
- try to find a backdoor which may leak some address by
reverse engineering :)
Code execution in TEE
• send an invalid operation_phys from
Normal world.

• RTOSck may write register value to
shared memory when task crashed.

• estimate base of “TEEGlobalTask” by
crashed $pc 

• PC = 0x2E103050 base = 0x2E100000
Leak register value when task crash
Patch 4 bytes
before patch after patch
• alloc buffer for shellcode via kmalloc
• Normal world : send request to TEE
- cmd = GLOBAL_CMD_ID_ALLOC_EXCEPTION_MEM
- with param (0,shellcode_physical_addr)
• TEE call syscall_f084(0,kernel_pool_phy)
Trigger the exploit
• Modify physical memory of Linux Kernel
- e.g. patch “avc_has_perm" to bypass SELinux for Android
• Modify memory of TEE
- disable hash checking for Modem image
- disable TA signature checking in TEE and load unsigned TA from
normal world
• Call TEE API
- read encrypted data from sec-storage
- read fingerprint image from sensor
- read/write efuse data
• Install a rootkit
- hook Linux kernel
- hook TEE API
What we can do with a TEE exploit
• “__FPC_readImage” is a syscall in TEE kernel(RTOSck)
- Provided by FPC1020 driver
- Only can be used by TA_Fingerprint task
- Unfortunately my code execution exploit is under
“TEE_GlobalTask” context. :(
• Patch TEE kernel to bypass this restriction.
- Need another vulnerability to modify TEE kernel memory.
Read fingerprint from sensor
<- TEE error log
Overwriting TEE kernel
signed int __fastcall sys_call_overwrite(int a1, int a2) {
signed int v2; // r3@2

int v4; // [sp+0h] [bp-14h]@1 int v5; // [sp+4h] [bp-10h]@1 v5 = a1;

v4 = a2;
if ( *(_DWORD *)a1 == 0x13579BDF ) {
// write (*(int*)(arg1 + 0x18C) + 7) >> 3 to arg2
*(_WORD *)v4 = (unsigned int)(*(_DWORD *)(v5 + 0x18C) + 7) >> 3;
v2 = 0; }
return v2;
} }
*(uint16*)r1 = (*(int*)(r0 + 0x18C) + 7) >> 3
Read fingerprint image from sensor
DEMO!
github.com/retme7/mate7_TZ_exploit
Thank you
retme7@gmail.com
@returnsme

More Related Content

What's hot

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
 
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...Marco Balduzzi
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackTomer Zait
 
LCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted FirmwareLCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted FirmwareLinaro
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programmingkozossakai
 
44CON London - Attacking VxWorks: from Stone Age to Interstellar
44CON London - Attacking VxWorks: from Stone Age to Interstellar44CON London - Attacking VxWorks: from Stone Age to Interstellar
44CON London - Attacking VxWorks: from Stone Age to Interstellar44CON
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniquesSatpal Parmar
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23DefconRussia
 
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
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewLinaro
 
Lcu14 306 - OP-TEE Future Enhancements
Lcu14 306 - OP-TEE Future EnhancementsLcu14 306 - OP-TEE Future Enhancements
Lcu14 306 - OP-TEE Future EnhancementsLinaro
 
Linux Timer device driver
Linux Timer device driverLinux Timer device driver
Linux Timer device driver艾鍗科技
 
Q2.12: Power Management Across OSs
Q2.12: Power Management Across OSsQ2.12: Power Management Across OSs
Q2.12: Power Management Across OSsLinaro
 
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareLinaro
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN
 
Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8Linaro
 
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru OtsukaTake a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru OtsukaCODE BLUE
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLinaro
 

What's hot (20)

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
 
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...
Lost in Translation: When Industrial Protocol Translation goes Wrong [CONFide...
 
Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The Stack
 
LCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted FirmwareLCU14 500 ARM Trusted Firmware
LCU14 500 ARM Trusted Firmware
 
Possibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented ProgrammingPossibility of arbitrary code execution by Step-Oriented Programming
Possibility of arbitrary code execution by Step-Oriented Programming
 
44CON London - Attacking VxWorks: from Stone Age to Interstellar
44CON London - Attacking VxWorks: from Stone Age to Interstellar44CON London - Attacking VxWorks: from Stone Age to Interstellar
44CON London - Attacking VxWorks: from Stone Age to Interstellar
 
Debugging linux kernel tools and techniques
Debugging linux kernel tools and  techniquesDebugging linux kernel tools and  techniques
Debugging linux kernel tools and techniques
 
Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23Advanced cfg bypass on adobe flash player 18 defcon russia 23
Advanced cfg bypass on adobe flash player 18 defcon russia 23
 
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
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
SPI Drivers
SPI DriversSPI Drivers
SPI Drivers
 
Lcu14 306 - OP-TEE Future Enhancements
Lcu14 306 - OP-TEE Future EnhancementsLcu14 306 - OP-TEE Future Enhancements
Lcu14 306 - OP-TEE Future Enhancements
 
Linux Timer device driver
Linux Timer device driverLinux Timer device driver
Linux Timer device driver
 
Serial Drivers
Serial DriversSerial Drivers
Serial Drivers
 
Q2.12: Power Management Across OSs
Q2.12: Power Management Across OSsQ2.12: Power Management Across OSs
Q2.12: Power Management Across OSs
 
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted FirmwareHKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
HKG15-505: Power Management interactions with OP-TEE and Trusted Firmware
 
Project ACRN GPIO mediator introduction
Project ACRN GPIO mediator introductionProject ACRN GPIO mediator introduction
Project ACRN GPIO mediator introduction
 
Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8
 
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru OtsukaTake a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
Take a Jailbreak -Stunning Guards for iOS Jailbreak- by Kaoru Otsuka
 
LCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted FirmwareLCU13: An Introduction to ARM Trusted Firmware
LCU13: An Introduction to ARM Trusted Firmware
 

Viewers also liked

Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Peter Hlavaty
 
Vulnerability desing patterns
Vulnerability desing patternsVulnerability desing patterns
Vulnerability desing patternsPeter Hlavaty
 
Software Security : From school to reality and back!
Software Security : From school to reality and back!Software Security : From school to reality and back!
Software Security : From school to reality and back!Peter Hlavaty
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school introPeter Hlavaty
 
When is something overflowing
When is something overflowingWhen is something overflowing
When is something overflowingPeter Hlavaty
 
Rainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could ExpectRainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could ExpectPeter Hlavaty
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelPeter Hlavaty
 
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesPeter Hlavaty
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" Peter Hlavaty
 

Viewers also liked (10)

Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!
 
Vulnerability desing patterns
Vulnerability desing patternsVulnerability desing patterns
Vulnerability desing patterns
 
Software Security : From school to reality and back!
Software Security : From school to reality and back!Software Security : From school to reality and back!
Software Security : From school to reality and back!
 
Hacking - high school intro
Hacking - high school introHacking - high school intro
Hacking - high school intro
 
When is something overflowing
When is something overflowingWhen is something overflowing
When is something overflowing
 
Attack on the Core
Attack on the CoreAttack on the Core
Attack on the Core
 
Rainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could ExpectRainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could Expect
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
 
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytesWindows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
 

Similar to Exploiting TrustZone on Android to Read Fingerprints

Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...Priyanka Aash
 
NSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch Protections
NSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch ProtectionsNSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch Protections
NSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch ProtectionsNoSuchCon
 
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3Raahul Raghavan
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptxssuserb4d806
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdfsupport58
 
Breaking hardware enforced security with hypervisors
Breaking hardware enforced security with hypervisorsBreaking hardware enforced security with hypervisors
Breaking hardware enforced security with hypervisorsPriyanka Aash
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver艾鍗科技
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityBrendan Gregg
 
FIPS 140-2 Validations in a Secure Enclave
FIPS 140-2 Validations in a Secure EnclaveFIPS 140-2 Validations in a Secure Enclave
FIPS 140-2 Validations in a Secure EnclavewolfSSL
 
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹GangSeok Lee
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Vincenzo Iozzo
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32HANCOM MDS
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiTakuya ASADA
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections Renaun Erickson
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver艾鍗科技
 
1032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.21032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.2Stanley Ho
 
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
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Brillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveBrillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveJalal Rohani
 

Similar to Exploiting TrustZone on Android to Read Fingerprints (20)

Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
Over-the-Air: How we Remotely Compromised the Gateway, BCM, and Autopilot ECU...
 
NSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch Protections
NSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch ProtectionsNSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch Protections
NSC #2 - D2 01 - Andrea Allievi - Windows 8.1 Patch Protections
 
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3ARM® Cortex™ M Bootup_CMSIS_Part_2_3
ARM® Cortex™ M Bootup_CMSIS_Part_2_3
 
Labs_BT_20221017.pptx
Labs_BT_20221017.pptxLabs_BT_20221017.pptx
Labs_BT_20221017.pptx
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
 
Breaking hardware enforced security with hypervisors
Breaking hardware enforced security with hypervisorsBreaking hardware enforced security with hypervisors
Breaking hardware enforced security with hypervisors
 
Linux SD/MMC device driver
Linux SD/MMC device driverLinux SD/MMC device driver
Linux SD/MMC device driver
 
LSFMM 2019 BPF Observability
LSFMM 2019 BPF ObservabilityLSFMM 2019 BPF Observability
LSFMM 2019 BPF Observability
 
FIPS 140-2 Validations in a Secure Enclave
FIPS 140-2 Validations in a Secure EnclaveFIPS 140-2 Validations in a Secure Enclave
FIPS 140-2 Validations in a Secure Enclave
 
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
[2007 CodeEngn Conference 01] dual5651 - Windows 커널단의 후킹
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor
 
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
Post Exploitation Bliss: Loading Meterpreter on a Factory iPhone, Black Hat U...
 
한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32한컴MDS_Virtual Target Debugging with TRACE32
한컴MDS_Virtual Target Debugging with TRACE32
 
SMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgiSMP implementation for OpenBSD/sgi
SMP implementation for OpenBSD/sgi
 
Building an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent ConnectionsBuilding an ActionScript Game Server with over 15,000 Concurrent Connections
Building an ActionScript Game Server with over 15,000 Concurrent Connections
 
用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver用Raspberry Pi 學Linux I2C Driver
用Raspberry Pi 學Linux I2C Driver
 
1032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.21032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.2
 
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
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Brillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveBrillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep Dive
 

Recently uploaded

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 

Recently uploaded (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 

Exploiting TrustZone on Android to Read Fingerprints

  • 1. Attacking your “Trusted Core” Exploiting TrustZone on Android Di Shen (@returnsme) BlackHat USA 15
  • 2. • Background - About Huawei Ascend Mate 7 - TEE architecture of Huawei Hisilicon - Attack Surface • Vulnerability in Normal World - technical details - gain root privilege • Vulnerabilities in Secure World (TEE) - technical details - read fingerprint image from sensor / bypass sec features • Conclusion Agenda
  • 3. •Security researcher from Qihoo 360 •Mainly focus on Android •Always like console games and manga/anime Who am I
  • 5. Huawei Ascend Mate 7 •HiSilicon Kirin 925 SoC chipset •HiSilicon implemented its own TEE kernel(Trusted Core) •the world s first Android smartphone with touch fingerprint sensor, featuring FPC1020 •1 million units sold by Huawei in the first month
  • 7. TEE architecture of Huawei SMC PWNED PWNED PWNED
  • 8. • TZDriver - accepting malformed ioctl command may allow installed application to execute arbitrary code in Linux Kernel. • Trusted Application - mistake in input structure bound-check may lead to an arbitrary code execution vulnerability in TEE • TEE kernel - system call bugs may allow a malicious TA to escalate privilege Attack Surface
  • 9. Attack “TrustedCore” Attack TZdriver installed application Attack TA Attack TEE kernel Send ioctl command execute SMC instructions system call
  • 11. • Accessible to any installed applications • provide communication APIs between NW and SW • provide an ioctl interface to both user space clients and other kernel module - for user clients,use copy_to_user/copy_from_user to copy input /output param buffer - for kernel modules, use memcpy directly TZDriver: /dev/tc_ns_client
  • 12. TC_NS_ClientContext typedef struct { unsigned char uuid[16]; unsigned int session_id; unsigned int cmd_id; TC_NS_ClientReturn returns; TC_NS_ClientLogin login; unsigned int paramTypes;//type of input param TC_NS_ClientParam params[4];//address or value of input bool started; } TC_NS_ClientContext;
  • 13. TC_NS_ClientParam typedef union { struct { unsigned int buffer; //ptr of buffer unsigned int offset; //size of buffer unsigned int size_addr; } memref; struct { unsigned int a_addr; //ptr of a 4-bytes buffer unsigned int b_addr; //ptr of a 4-bytes buffer } value; } TC_NS_ClientParam; What if user client send a kernel pointer to driver?
  • 14. Kernel memory overwriting static int TC_NS_SMC_Call(TC_NS_ClientContext *client_context,TC_NS_DEV_File *dev_file, bool is_global){ .... // build a TC_NS_SMC_CMD struct .... // execute SMC instruction TC_NS_SMC(smc_cmd_phys); // copy result from smc_cmd.operation_phys to callers' buffer(client_param.value) if(client_operation->params[0].value.a> 0xbfffffff){ //driver think caller is from kernel space *(u32 *)client_param->value.a_addr = operation->params[i].value.a; } else{ //driver think caller is from user space copy_to_user(....); } if(client_operation->params[0].value.b > 0xbfffffff){ *(u32 *)client_param->value.b_addr = operation->params[i].value.b; } else{ copy_to_user(....); } .... } CVE ID : CVE-2015-4421
  • 16. •Extract TEE image from firmware.Using HuaweiUpdateExtractor.exe •TEEOS.img is not encrypted.Drag into IDA. •Find a interface provided by TA will return a stable “TZvalue”. How to find a stable “TZValue”
  • 17. Time querying interface in TEEGlobalTask int get_sys_time() { int result; // r0@1 tag_TC_NS_Operation *v1; // r3@1 unsigned int v2; // [sp+0h] [bp-10h]@1 int v3; // [sp+4h] [bp-Ch]@1 get_time((int)&v2); result = 0; v1 = dword_5E2E0->operation_phys; v1->params[0].value.a = v2; //second from startup v1->params[0].value.b = 1000 * v3; //millisecond return result; }
  • 19. • now I can execute SMC instruction by TZDriver ret2user exploit • SMC param: a pointer to structure TC_NS_SMC_CMD Send malformed request to TA typedef struct tag_TC_NS_SMC_CMD{ unsigned int uuid_phys; unsigned int cmd_id; unsigned int dev_file_id; unsigned int context_id; unsigned int agent_id; unsigned int operation_phys; unsigned int login_method; unsigned int login_data; unsigned int err_origin; bool started; } TC_NS_SMC_CMD;
  • 20. review:Time querying interface in TEEGlobalTask int get_sys_time() { int result; // r0@1 tag_TC_NS_Operation *v1; // r3@1 unsigned int v2; // [sp+0h] [bp-10h]@1 int v3; // [sp+4h] [bp-Ch]@1 get_time((int)&v2); result = 0; operation_phys = dword_5E2E0->operation_phys; *(int*)(operation_phys+4) = v2; *(int*)(operation_phys+8) = 1000 * v3; return result; } CVE ID : CVE-2015-4422
  • 21. • no security checking on operation_phys • if second = 0xAABBCCDD,every time we can write 4 byte “DD,CC,BB,AA” at operation_phys + 4 • The “DD” is the last byte of second and cycle from 0x00 to 0xFF. • Write a byte you want at a right second ——arbitrary physical address overwriting arbitrary physical memory overwriting
  • 22. • Main idea - patch text code of TEEGlobalTask,call TEE function and return to my shellcode • Good news: - few mitigation in RTOSck, the kernel of TEE - No ASLR , XN or “unwritable Text code”. • Bad news: - I don’t know where to patch without base address of TEEGlobalTask • Don’t give up: - try to find a backdoor which may leak some address by reverse engineering :) Code execution in TEE
  • 23. • send an invalid operation_phys from Normal world. • RTOSck may write register value to shared memory when task crashed. • estimate base of “TEEGlobalTask” by crashed $pc • PC = 0x2E103050 base = 0x2E100000 Leak register value when task crash
  • 24. Patch 4 bytes before patch after patch
  • 25. • alloc buffer for shellcode via kmalloc • Normal world : send request to TEE - cmd = GLOBAL_CMD_ID_ALLOC_EXCEPTION_MEM - with param (0,shellcode_physical_addr) • TEE call syscall_f084(0,kernel_pool_phy) Trigger the exploit
  • 26. • Modify physical memory of Linux Kernel - e.g. patch “avc_has_perm" to bypass SELinux for Android • Modify memory of TEE - disable hash checking for Modem image - disable TA signature checking in TEE and load unsigned TA from normal world • Call TEE API - read encrypted data from sec-storage - read fingerprint image from sensor - read/write efuse data • Install a rootkit - hook Linux kernel - hook TEE API What we can do with a TEE exploit
  • 27. • “__FPC_readImage” is a syscall in TEE kernel(RTOSck) - Provided by FPC1020 driver - Only can be used by TA_Fingerprint task - Unfortunately my code execution exploit is under “TEE_GlobalTask” context. :( • Patch TEE kernel to bypass this restriction. - Need another vulnerability to modify TEE kernel memory. Read fingerprint from sensor <- TEE error log
  • 28. Overwriting TEE kernel signed int __fastcall sys_call_overwrite(int a1, int a2) { signed int v2; // r3@2
 int v4; // [sp+0h] [bp-14h]@1 int v5; // [sp+4h] [bp-10h]@1 v5 = a1;
 v4 = a2; if ( *(_DWORD *)a1 == 0x13579BDF ) { // write (*(int*)(arg1 + 0x18C) + 7) >> 3 to arg2 *(_WORD *)v4 = (unsigned int)(*(_DWORD *)(v5 + 0x18C) + 7) >> 3; v2 = 0; } return v2; } } *(uint16*)r1 = (*(int*)(r0 + 0x18C) + 7) >> 3
  • 29. Read fingerprint image from sensor DEMO!