Top Banner
Hacking Cell Phone Embedded Systems Keegan Ryan RECON 2017
44

Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Jun 19, 2018

Download

Documents

HoàngLiên
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Hacking Cell Phone Embedded Systems

Keegan Ryan – RECON 2017

Page 2: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

The Target

Page 3: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

The Target

brendangates

Page 4: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

The Target

Meriac (2010), Churchill

Page 5: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Legacy ICLASS

• Introduced in 2007

• Broken in 2010

• Master key on every

reader

• Security of card reader

broken

• Protocol reverse

engineered

• New version of iCLASS

released, but many still

use Legacy iCLASS

• Uses ISO15693

Meriac (2010), Inside Contactless (2004)

Page 6: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Nexus S

• Introduced in 2010

• One of earliest to support NFC, including ISO15693

• Android source code available

• Cheap

Page 7: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Nexus S

Android

Application

libnfc Library

Kernel Driver

NFC Controller

• Try Android app first

• Transceive raw bytes

• CRC added automatically,

but we don’t want a CRC

• Not added by libraries

• Not added by kernel

• Must be added by NFC

controller chip

Page 8: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

PN544

• Separate from Nexus S CPU

• Powered by host or external field

• Supports ISO 15693, Mifare, FeliCa

• Supports firmware upgrades

• Uses 80C51MX Processor

NXP (2010), Wharton (1980)

DATA

CODE

Page 9: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Investigating the PN544

Page 10: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Firmware Recovery

• PHDNLD_CMD_READ

• Pull from update file

• Code signing

• Protected with SHA1 and RSA-1024

• Introduced after first devices shipped

• Need a device never updated past GingerbreadLibnfc-nxp

Page 11: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 12: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Reverse Engineering

There aren’t any.

They don’t exist.

No help.

• Look for strings.

• Look for CRC constants.

• Look for usage of the XOR instruction.

• Just start reversing until we find something

useful.

Page 13: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 14: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Reverse Engineering

• Reverse commonly called functions

• Find switch function

• Find command switching

• Trace known command IDs through code

Page 15: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Reverse Engineering

Libnfc-nxp

Page 16: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem:

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 17: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem: Missing Code

???

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 18: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem: Missing Code

KERNEL_CODE

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 19: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Kernel Recovery

• We understand and can modify FW_CODE

• FW_CODE doesn’t have access to kernel

• We can modify PATCH_CODE

• Don’t know how to trigger PATCH_CODE

• Want to maximize chances of executing our

code

Page 20: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Kernel Recovery

PATCH_CODE

Page 21: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Kernel Recovery

PATCH_CODE

Page 22: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Kernel Recovery

Page 23: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem: Missing Code

KERNEL_CODE

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 24: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem: Missing Code

KERNEL_CODE

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 25: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Reverse Engineering KernelReverse Engineering

Still aren’t any.

Still don’t exist.

No help.

• Look for strings.

• Look for CRC constants.

• Look for usage of the XOR instruction.

• CRC creation is done by hardware

• Still not impossible, but we need a new approach

Page 26: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Wireless Protocols

Page 27: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

SDR Setup

Antenna

Upconverter

Radio

Signal Source

Page 28: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

SDR Setup

<s> 10 01 10 00 01 00 00 00…

Page 29: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Transfer Speed

• ISO15693 has two modes:

• Slow (1.65 kbps)

• Fast (26.48 kbps)

• Nexus S uses slow mode

• ICLASS only uses fast mode

Inside Contactless (2004)

Page 30: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem: Transfer Speed

• Capability probably

exists, but is unused.

• Find transmission code

• Loads settings from EEPROM/CFG

• Only uses one set of

values

• Swap around values in EEPROM/CFG

• Fast mode!

Page 31: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Mifare

Libnfc-nxp

Page 32: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Problem: Checksum Generation

FW_CODE Command Handler

RF Transmit

MIFARE Setup

(CRC)

MIFARE Setup

(No CRC)ISO15693 Setup

(CRC)

Android

Find differences

here

Apply difference

here

Page 33: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Patching the Kernel

KERNEL_CODE

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 34: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Exploitation

Page 35: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Patching Checksum Generation

KERNEL_CODE

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 36: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller
Page 37: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Putting It All Together

KERNEL_CODE

FW_CODE

PATCH_TABLE

PATCH_CODE

EEPROM/CFG

Page 38: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Demo

Page 39: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Demo

Page 40: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Future Research

What can be done with a hacked NFC

controller?

• Surreptitiously read a badge

• Information storage

• Information exfiltration

Page 41: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Future Research

• What other embedded systems do we carry

everywhere?

• Bluetooth

• USB controller

• Baseband radio

• Camera

• Fingerprint reader

• What could you make these systems do?

Page 42: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

The End

Keegan Ryan

[email protected]

@inf_0_

Page 43: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Bypassing Firmware Signing?

doSecureDownload();

if (*flag == 0xa55a)

doInsecureDownload();

else

Page 44: Hacking Cell Phone Embedded Systems - RECON.CX · Hacking Cell Phone Embedded Systems Keegan Ryan –RECON 2017. ... • CRC creation is done by hardware ... “NXP NFC controller

Bibliography

Brendangates. “Badge reader.” Licensed under a Creative Commons

Attribution 2.0 Generic (CC BY-NC-ND 2.0). Accessed 11 June 2017.

https://www.flickr.com/photos/brendangates/2384518688.

Churchill, Sam. “nfc.phone.” Licensed under a Creative Commons Attribution

2.0 Generic (CC BY 2.0). Accessed 11 June 2017.

https://www.flickr.com/photos/samchurchill/5181496553

Inside Contactless. "Datasheet PicoPass 2KS." Rapport technique (2004).

Libnfc-nxp Library. Accessed June 11, 2017.

https://android.googlesource.com/platform/external/libnfc-nxp.

Meriac, Milosch. "Heart of darkness-exploring the uncharted backwaters of

hid iclass (TM) security." In 27th Chaos Communication Congress. 2010.

NXP. “NXP NFC controller PN544 for mobile phones and portable

equipment." On Line:

http://www.nxp.com/documents/leaflet/75016890.pdf (2010).

Wharton, John. "An Introduction to the Intel-MCS-51 Single-Chip

Microcomputer Family." Intel Corporation (1980).