Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different...

92
Not all IoT Devices are Created Equal: Reverse Engineering of Xiaomi's IoT ecosystem beVX Conference 2018 – Dennis Giese

Transcript of Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different...

Page 1: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

Not all IoT Devices are Created Equal: Reverse Engineering of Xiaomi's IoT ecosystembeVX Conference 2018 – Dennis Giese

Page 2: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

2beVX Conference 2018 – Dennis Giese

About me

• Researcher at Northeastern University, USA

– Working with Prof. Guevara Noubir@CCIS

• Grad student at TU Darmstadt, Germany

– Working with Prof. Matthias Hollick@SEEMOO

• Worked for >6 Years for Deutsche Telekom/T-Systems CERT

• Interests: Reverse engineering of interesting devices

– IoT, Smart Locks

– Physical Locks ;)

Page 3: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

3beVX Conference 2018 – Dennis Giese

Let’s talk about Cyber security

• Long time experience and well researched field

– Lots of security mechanisms in hardware

• Secure boot, Firmware signatures, Attestation

• Best practices are applied in industry

– Security Development Lifecycles

– Programming guidelines

Page 4: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

4beVX Conference 2018 – Dennis Giese

Outline

• Motivation

• Xiaomi Cloud

• Overview of devices

• How to approach

• Reverse Engineering of devices

Page 5: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

5beVX Conference 2018 – Dennis Giese

MOTIVATION

Page 6: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

6beVX Conference 2018 – Dennis Giese

Why reverse IoT?

• (Find and exploit bugs to hack other people)

• De-attach devices from the vendor

• Enhance functionality

– Add new features

– Localization (e.g. Sound files)

– Defeat Geo blocking

• Supporting other researchers

Page 7: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

7beVX Conference 2018 – Dennis Giese

Mon(IoT)or Lab@NEU

htt

ps:

//m

on

iotr

lab

.cci

s.n

eu

.ed

u/

Page 8: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

8beVX Conference 2018 – Dennis Giese

“Responsible disclosure”?

• Ethical question: “Responsible disclosure”?

– Conflict:

• Root-ability vs. Device security

• “Service for the Community” vs. Bug Bounty Program

• contacted Xiaomi security team

– Professional reaction

– Confirmation of flaws

– Bug Bounty program exists

• (did not apply to me, as I published it before reporting it)

Page 9: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

9beVX Conference 2018 – Dennis Giese

How we started

May 2017Mi Band 2Vacuum Robot Gen 1

June 2017Lumi Smart Home Gateway + Sensors

July 2017Yeelink Lightbulbs (Color+White)Yeelink LED Strip

Res

earc

h in

co

op

erat

ion

wit

h D

anie

l Weg

emer

Page 10: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

10beVX Conference 2018 – Dennis Giese

How we continued

Yeelink Desk lampPhilips Eyecare Desk lampXiaomi Wi-Fi router

Yeelink/Philips Ceiling LightsPhilips Smart LED Bulb

Vacuum Robot Gen 2Yeelink Bedside LampXiaomi (Ninebot) M365

Lumi Aqara CameraYeelink Smart LED Bulb (v2)Smart Power strip

Page 11: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

11beVX Conference 2018 – Dennis Giese

Why Vacuum Robots?

Source: Xiaomi advertisment

Page 12: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

12beVX Conference 2018 – Dennis Giese

THE XIAOMI CLOUD

Page 13: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

13beVX Conference 2018 – Dennis Giese

Xiaomi Cloud

• They claim to have the biggest IoT ecosystem worldwide

– 85 Million Devices, 800 different models 1

• Different Vendors, one ecosystem

– Same communication protocol

– Different technologies supported

– Implementation differs from manufacturer to manufacturer

• Software quality very different

• Xiaomi do not have source code of third-party vendors

htt

ps:

//gi

thu

b.c

om

/MiE

cosy

stem

/miio

_op

en

htt

ps:

//io

t.m

i.co

m/i

nd

ex.h

tml

1: https://www.espressif.com/en/media_overview/news/espressif-systems-integrated-xiaomis-plans-iot-development

Page 14: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

14beVX Conference 2018 – Dennis Giese

Xiaomi Ecosystem

HTTPS

ZigBee

Xiaomi Cloud(Mi)

Gateway

WiFi

* There could be more connections (e.g. P2P, FDS)

Page 15: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

15beVX Conference 2018 – Dennis Giese

Device to Cloud Communication

• DeviceID

– Unique per device

• AES Keys

– Cloud key

• Is used for cloud communication

• Static, is not changed by update or provisioning

– Token

• Is used for app communication

• Dynamic, is generated at provisioning (connecting to new Wi-Fi)

DID + Cloud Key: not bound to specific server location

Page 16: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

16beVX Conference 2018 – Dennis Giese

BeVX exclusive slide

Page 17: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

17beVX Conference 2018 – Dennis Giese

Cloud protocol

• Data

– JSON-formatted messages

• Example of “Device registration”

– {'id’: 123, 'params': {'ap': {'ssid’: ‘myWifi', 'bssid': 'F8:1A:67:CC:BB:AA', 'rssi': -30}, 'hw_ver': 'Linux', 'model': 'rockrobo.vacuum.v1', 'netif': {'localIp': '192.168.1.205', 'gw': '192.168.1.1', 'mask': '255.255.255.0'}, 'fw_ver': '3.3.9_003077', 'mac': '34:CE:00:AA:BB:DD', 'token': 'xxx'}, 'method': '_otc.info'}

Page 18: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

18beVX Conference 2018 – Dennis Giese

Protocol for Firmware updates

• APP Updates– {"method":"miIO.ota","params":{"app_url":"http://cdn.cnbj0.fds.api.mi-img.com

/miio_fw/upd_lumi.gateway.v3.bin?...","file_md5":"063df95bd5….cf11e","install":"1","proc":"dnld install","mode":"normal"},"id":123}

• MCU/WiFi Updates– {"method":"miIO.ota","params":{"mcu_url":"http://cdn.cnbj0.fds.api.mi-img.com/

miio_fw/mcu_lumi.gateway.v3.bin? ...","install":"1","proc":"dnld install", "mode":"normal"},"id":123}

• Subdevice Updates– {"crc32":"9460d9f0","image_type":"0101","manu_code":"115F","md5":"e9d62…a74d

8","model":"lumi.plug.v1","size":"186978","url":"http://cdn.cnbj2.fds.api.mi-img.com /lumi-ota/aiot-ota/LM15_SP_mi_V1.3.22_..._OTA_v22_withCRC.ota"}

No Integrity provided

Many devices do not actually check for MD5 (e.g. lumi.gateway.v3, yeelight lightbulbs)

Page 19: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

19beVX Conference 2018 – Dennis Giese

Xiaomi Ecosystem

HTTPS

ZigBee

XiaomiCloud

Gateway

WiFi

Page 20: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

20beVX Conference 2018 – Dennis Giese

App to Cloud communication

• Authentication via OAuth

• Layered encryption

– Outside: HTTPS

– Inside: AES using a session key

• Message format: JSON RPC

Page 21: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

21beVX Conference 2018 – Dennis Giese

App to Cloud communication

Mi Home Core App(Dev: Xiaomi)

Gen1 Vacuum Plugin(Dev: Rockrobo)

Aqara Cam Plugin(Dev: Lumi)

Core functionality:• Device add, delete• Device list• Device Updates via Cloud• Plugin Management• Permission Management

Device specific functionality:• Device commands• Map download and presentation

Device specific functionality:• Device commands• Camera feed view (via P2P)• Zigbee device control

Controlled by region whitelist for SSIDs

Page 22: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

22beVX Conference 2018 – Dennis Giese

App to Cloud communication

• REQ: api.io.mi.com/home/device_list method:POST params:[]

• RES: {"message":"ok","result":{"list":[{"did":"65981234","token":“abc…zzz","name":"Mi PlugMini","localip":"192.168.99.123", "mac":"34:CE:00:AA:BB:CC","ssid":"IoT","bssid":"FA:1A:67:CC:DD:EE","model":"chuangmi.plug.m1", "longitude":“-71.0872248","latitude":"42.33794500“, "adminFlag":1,"shareFlag":0,"permitLevel":16,"isOnline":true,"desc":"Power plug on ","rssi":-47}

Page 23: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

23beVX Conference 2018 – Dennis Giese

App to Cloud communication

• "longitude":"-71.0872248","latitude":"42.33794500”

Source: Openstreetmaps

Page 24: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

24beVX Conference 2018 – Dennis Giese

Robot intern

Example of Communication relations

Miio_client

0.0.0.0:54321 (udp)(local):54322 (tcp)

player0.0.0.0:6665

RoboController

AppProxy

wifimgr

*.fds.api.xiaomi.com (https)maps,logs->

<-soundpackages, firmwareuart_mcuuart_ldscompass

IPCplain json (tcp)enc(key) json (tcp/udp)enc(token) json (udp)

Android/iPhone App

<-commands,reports->

ott.io.mi.com:80(tcp)ot.io.mi.com:8053(udp)

AES encrypted

device.conf:DID, Key

*.api.io.mi.com(https)

Page 25: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

25beVX Conference 2018 – Dennis Giese

How to gain Independence

Xiaomi Cloud

Copyright: 20th Century Fox

Page 26: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

26beVX Conference 2018 – Dennis Giese

Robot intern

player0.0.0.0:6665

RoboController

AppProxy

wifimgr

uart_mcuuart_ldscompass

Proxy cloud communication

Miio_client

0.0.0.0:54321 (udp)(local):54322 (tcp)

ot.io.mi.com:80(tcp)ott.io.mi.com:8053(udp)

IPCplain json (tcp)enc(key) json (tcp/udp)enc(token) json (udp)

Android/iPhone App

/etc/hosts

130.83.x.x ot.io.mi.com 130.83.x.x ott.io.mi.com

Dustcloud

*.fds.api.xiaomi.com (https)

<-commands,reports->

Page 27: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

27beVX Conference 2018 – Dennis Giese

What is Dustcloud?

• Proxy or endpoint server for devices

– Acts as Xiaomi Cloud emulation

– Reads traffic in plaintext

– May send commands to the device

• Change or suppress commands (e.g. Updates)

• Requirements: Device ID, Cloud Key, DNS Redirection

htt

ps:

//gi

thu

b.c

om

/dgi

ese/

du

stcl

ou

dh

ttp

s://

gith

ub

.co

m/d

gies

e/d

ust

clo

ud

-do

cum

enta

tio

n

Page 28: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

28beVX Conference 2018 – Dennis Giese

LETS TAKE A LOOK AT THE PRODUCTS

Page 29: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

29beVX Conference 2018 – Dennis Giese

Products

• ~260 different models supported (WiFi + Zigbee + BLE)

• Depending on selected server location

– Mainland China

– Hong Kong

– US

– …

– models not always compatible

• My inventory: ~46 different models

– 130 devices in total

Lumi16%

Xiaomi11%

Zhimi9%

Yeelink6%

Philips (Yeelink)4%

Chungmi6%

Yunmi4%

Rockrobo2%

Viomi2%

iSmart2%

others38%

Values estimated, Mi Home 5.3.13, Mainland China Server

Page 30: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

30beVX Conference 2018 – Dennis Giese

Products

Different architectures

• ARM Cortex-A

• ARM Cortex-M

– Marvell 88MW30X (integrated WiFi)

– Mediatek MT7687N (integrated WiFi + BLE)

• MIPS

• Xtensa

– ESP8266, ESP32 (integrated WiFi)

Most performant

Less performance,Difficult to patch

Try to avoid these!

Page 31: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

31beVX Conference 2018 – Dennis Giese

Products

AR

M C

ort

ex-A

AR

M C

ort

ex-M

Xte

nsa

Page 32: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

32beVX Conference 2018 – Dennis Giese

Operation Systems

• „Full Linux“ e.g. Ubuntu 14.04

– Vacuum cleaning robots

• OpenWRT

– Xiaomi Wifi Speaker, Routers, Minij washing machine

• Embedded Linux

– IP cameras

• RTOS

– Lightbulbs, ceiling lights, light strips

ARM Cortex-A, MIPS

ARM Cortex-M, Xtensa

Page 33: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

33beVX Conference 2018 – Dennis Giese

Good news (for us)

• Vendors/Developers are lazy

• Assumed development of firmware:

– Take SDK/toolchain

– Modify sample that the product runs

– If it works: publish firmware

All firmwares very similar (memory layout, functions, strings, etc)

Page 34: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

34beVX Conference 2018 – Dennis Giese

Lazy developers example:Lumi Aqara Gateway

• Based on NXP „imx6ull14x14evk“ Board

– Arm Cortex-A, 256MB RAM, 256MB Flash

• Baseimage: Demo Yocto Image

– Changes:

• Lumi executables, Soundfiles, modules

• Disabled SSH

– Garbage: Camera sensor modules, NFC, Cracklib, ofono

• Only one copy of OS --> no recovery possible

Ap

plie

s to

: lu

mi.g

atew

ay.m

itw

01

, lu

mi.g

atew

ay.m

ihk0

1, l

um

i.gat

eway

.mie

u0

1,

lum

i.gat

eway

.aq

cn0

1

Page 35: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

35beVX Conference 2018 – Dennis Giese

Common Mistakes by developers

• Cortex-M:

– No SSL stack implemented

– Even if implemented: Certificates are not checked

– Undocumentated commands/interfaces

• Cortex-A:

– Lots of debug/production tools and unused software in firmware

– Debug symbols in binaries

– Excessive logging

• General Problem: No sufficient quality control

Page 36: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

36beVX Conference 2018 – Dennis Giese

HOW TO APPROACH

Page 37: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

37beVX Conference 2018 – Dennis Giese

How we stay undetected?

• Multiple smartphones/tablets

– Different Xiaomi accounts

– Different server location

– Spoofed GPS coordinates

• WiFi Network

– Seperate WiFi access points

– VPNs to Hong Kong, China

– TOR

• No mixture between different accounts and devices

Page 38: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

38beVX Conference 2018 – Dennis Giese

Device selection

• Avoid Xtensa

• Multiple devices for each model

– One reference

– One to disassemble and root

• Selection by usefulness and size

– No fridges, washing machines, ...

Page 39: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

39beVX Conference 2018 – Dennis Giese

Workflow

• Preparation: Check for FCC documentation, tear down pictures

1. Get the device

2. Before first power on:

– Disassemble

– unsolder the flash, dump the content

3. Analyze the firmware

4. Patch the firmware

– For ARM Cortex-A/MIPS: enable SSH/Telnet/reverse shell

– For ARM Cortex-M: use Nexmon to insert debug functions

htt

ps:

//gi

thu

b.c

om

/se

emo

o-l

ab/n

exm

on

Nexmon: Watch my talk at DEFCON 26 IoT Village if you want to know how this black magic exactly works.

Page 40: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

40beVX Conference 2018 – Dennis Giese

How to get the Firmware?

• Dumping SPI Flash memory

– JTAG, SWD or desolder Flash

– (e.g.Raspberry Pi with OpenOCD/flashrom)

• Intercepting traffic while Firmware Update

– It is advised to actually block the Update

• Sneaky: If DNS fails then direct IP is used

– Goal: Retrieve special URL for Firmware update

Page 41: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

41beVX Conference 2018 – Dennis Giese

Firmware downloads

• Filenames not easy guessable

• CDN is using URL authentication

– Authentications seems to be valid for months

– Multiple queries return same authentication values

http://cdn.cnbj0.fds.api.mi-img.com/miio_fw/063df95bd538a9cfa22c7c8664XXXXXX_upd_lumi.gateway.v3.bin?GalaxyAccessKeyId=5721718111234&Expires=1539055099000&Signature=KtIxawkpAdggz3IEuu6ygXXXXX==&uniqRequestId=21234123

MD5

Model

Authentication

Page 42: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

42beVX Conference 2018 – Dennis Giese

BeVX exclusive slide

Page 43: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

43beVX Conference 2018 – Dennis Giese

LETS GET ACCESS TO THE DEVICES

Page 44: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

44beVX Conference 2018 – Dennis Giese

Warranty seal?

Page 45: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

45beVX Conference 2018 – Dennis Giese

XIAOMI M365 ELECTRIC SCOOTERDEVELOPED BY: NINEBOT

Ap

plie

s to

: nin

ebo

t.sc

oo

ter.v

1

Page 46: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

46beVX Conference 2018 – Dennis Giese

Overview Hardware

• CPU: STM32F103C8T6

• Battery-MCU: STM32F103C8T6

• Communication: nRF51822

– BLE, no WiFi

Source: FCC documentation

Source: FCC documentation

Page 47: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

47beVX Conference 2018 – Dennis Giese

Same platform used by Bird

Page 48: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

48beVX Conference 2018 – Dennis Giese

Rooting

• Patching with Nexmon Framework

• Firmware updates not authenticated/signed

• Communication over BLE

– Update possible while driving the scooter

– Authentication not required for updates

• (Theft protection gets disabled when scooter is charged or MCU is restarted, e.g. Firmware Update)

Update: New firmware version 1.4.1 deploys a new method of

obfuscated encryption + downgrade protection

Page 49: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

49beVX Conference 2018 – Dennis Giese

AQARA SMART IP CAMERADEVELOPED BY: LUMI

Ap

plie

s to

: lu

mi.c

amer

a.aq

1

Page 50: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

50beVX Conference 2018 – Dennis Giese

Overview Hardware

• CPU: Hi3518EV200

– ARM Cortex-A

• RAM: 64MB

• Flash: 16MByte

• Wi-Fi: Mediatek MT7601UN via USB

• OS: Embedded Linux

• Zigbee-MCU: NXP JN5169

Page 51: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

51beVX Conference 2018 – Dennis Giese

Devices connected via Zigbee

Zigbee (NXP JN5169) based

• Motion Sensor

• Temperature sensors

• Power Plug

• Smoke Detectors

• Smart Door Lock

• …

Page 52: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

52beVX Conference 2018 – Dennis Giese

Serial port after bricking device

Page 53: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

53beVX Conference 2018 – Dennis Giese

Leaked information

• JFFS2 filesystem not properly cleaned

• 3 different credentials from development devices leaked0004cc10 e3 b5 3b e8 00 2c 23 20 63 61 74 20 2f 65 74 63 |..;..,# cat /etc|0004cc20 2f 6d 69 69 6f 2f 64 65 76 69 63 65 2e 63 6f 6e |/miio/device.con|0004cc30 66 0a 23 20 64 69 64 20 6d 75 73 74 20 62 65 20 |f.# did must be |0004cc40 61 20 75 6e 73 69 67 6e 65 64 20 69 6e 74 0a 23 |a unsigned int.#|0004cc50 20 6b 65 79 29 70 00 00 4e 73 74 72 69 6e 67 0a | key)p..Nstring.|0004cc60 23 0a 64 69 64 3d 35 30 36 30 33 36 35 XX 0a 6b |#.did=5060365X.k|0004cc70 65 79 3d 4e 41 37 4e 69 6d 4b 6f XX XX XX XX XX |ey=NA7NimKoXXXXX|0004cc80 69 58 6e 0a 6d 61 63 3d 32 38 3a 36 43 3a 30 37 |iXn.mac=28:6C:07|0004cc90 3a 32 45 3a XX XX 3a XX XX 0a 76 65 6e 64 6f 72 |:2E:XX:XX.vendor|0004cca0 3d 6c 75 6d 69 0a 23 20 6d 6f 64 65 6c 20 6d 61 |=lumi.# model ma|0004ccb0 78 20 6c 65 6e 20 32 33 0a 80 02 94 03 00 02 2e |x len 23........|0004ccc0 63 61 6d 65 72 61 2e 61 71 31 0a 70 32 70 5f 69 |camera.aq1.p2p_i|0004ccd0 64 3d 41 2c 00 00 03 30 31 31 31 41 0a 11 00 00 |d=A,...0111A....

Page 54: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

54beVX Conference 2018 – Dennis Giese

Rooting

• Serial was not necessary

– open telnet server (port 23)

– hardcoded root password in /etc/shadow

• “root:IIfCcCAiKWPNs:17333:0:99999:7::”

• DES-Crypt -> password truncated to 8 chars

• Password: “lumi-201”

– Same credentials for all cameras

Page 55: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

55beVX Conference 2018 – Dennis Giese

Modifications

• Replace Chinese sound files

• Replace telnetd by dropbear (SSH)

• Change root password

• Replace Camera Software

Problem:Only one copy of base system (squashfs)Tricky to update/modify

Page 56: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

56beVX Conference 2018 – Dennis Giese

VACUUM CLEANING ROBOTSDEVELOPED BY: ROCKROBO

Res

earc

h in

co

op

erat

ion

wit

h D

anie

l Weg

emer

rock

rob

o.v

acu

um

.v1

(En

d o

f 2

01

6),

ro

bo

rock

.vac

uu

m.s

5 (E

nd

of

20

17

)

Page 57: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

57beVX Conference 2018 – Dennis Giese

Gen 1 Device Overview

Source: Xiaomi advertisment

Page 58: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

58beVX Conference 2018 – Dennis Giese

Teardown

Page 59: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

59beVX Conference 2018 – Dennis Giese

Frontside layout mainboard

512 MB RAM

R16SOC

4GBeMMCFlash

WiFi Module

STM32 MCU

Page 60: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

60beVX Conference 2018 – Dennis Giese

Backside layout mainboard

R16 UART(115200 baud)TxRx

STM UART (921600 baud)

Tx

LIDAR UART

Page 61: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

61beVX Conference 2018 – Dennis Giese

Rooting

• Usual (possibly destructive) way to retrieve the firmware

Page 62: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

62beVX Conference 2018 – Dennis Giese

Rooting

Our weapon of choice:

Page 63: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

63beVX Conference 2018 – Dennis Giese

Pin Layout CPU1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

A

MMC

Reset D6 D4 D2 D0 D2 D0 CLK TX UART1

B D7 D5 D3 D1 D3 D1 CMD RX

C CLK SDA TWI1

D RX TX CMD SCL

E

F

Recov

ery

Confir

m UART2

G RX TX

H

Line

IN L

J

LINE

IN R

K

PHO

NE IN

L

PHO

NE IN

M

PHO

NE

MIC1

P

N

PHO

NE

MIC2

P

P SDA SCK RESET RSB0

R

T LCD9 LCD7 LCD5 LCD3 LCD1USB-

DM0

USB-

DP0 USB 1

U LCD8 LCD6 LCD4 LCD2 LCD0USB

DRV

USB-

DM1

USB-

DP1 USB 2

DRAM VCC/VDD GND LCD

UART0 MMC2 MMC1

Page 64: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

64beVX Conference 2018 – Dennis Giese

Rooting (Gen1 + Gen2)

• Shortcut the MMC data lines

• SoC falls back to FEL mode

• Load + Execute tool in RAM

– Via USB connector

– Dump MMC flash

– Modify image

– Rewrite image to flash

Page 65: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

65beVX Conference 2018 – Dennis Giese

Software

• Ubuntu 14.04.3 LTS (Kernel 3.4.xxx)

– Mostly untouched, patched on a regular base

• Player 3.10-svn

– Open-Source Cross-platform robot device interface & server

• Proprietary software (/opt/rockrobo)

– Custom adbd-version

• iptables firewall enabled (IPv4!)

– Blocks Port 22 (SSHd) + Port 6665 (player)

– Fail: IPv6 not blocked at all

Page 66: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

66beVX Conference 2018 – Dennis Giese

Available data on device

• Data

– Logfiles (syslogs, stats, Wi-Fi credentials)

– Maps

• Data is uploaded to cloud

• Factory reset

– Does not delete data: Maps, Logs still exist

~100 Gbytewrites per Year

Page 67: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

67beVX Conference 2018 – Dennis Giese

Available data on device

Page 68: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

68beVX Conference 2018 – Dennis Giese

Update process

miIO.ota {"mode":"normal“, "install":"1", "app_url":"https://[URL]/v11_[version].pkg", "file_md5":“[md5]",”proc":"dnld install“}

2. Download [app_url]

system_a

system_b

Download

Data

MD5 ok?Decrypt + image OK?

Unpack + dd

dd

Activecopy

dd

rebooting…

Update root pwin /etc/shadow

Page 69: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

69beVX Conference 2018 – Dennis Giese

Firmware updates

• Integrity– MD5 provided by cloud

• Full images– Encrypted tar.gz archives– Contains disk.img with 512 Mbyte ext4-filesystem

• Encryption– Ccrypt [256-bit Rijndael encryption (AES)]– Static password: “rockrobo” Sound Packages

Static password: “r0ckrobo#23456”

Page 70: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

70beVX Conference 2018 – Dennis Giese

Page 71: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

71beVX Conference 2018 – Dennis Giese

Lets root remotely

• Preparation: Rebuild Firmware

– Include authorized_keys

– Remove iptables rule for sshd

• Send „miIO.ota“ command to vacuum

– Token can be used here

– Pointing to own http server

Page 72: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

72beVX Conference 2018 – Dennis Giese

Lets root remotely

„miIO.ota“

unprovisioned state

„Get Token“

Webserver

Page 73: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

73beVX Conference 2018 – Dennis Giese

SSH

Page 74: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

74beVX Conference 2018 – Dennis Giese

Page 75: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

75beVX Conference 2018 – Dennis Giese

Page 76: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

76beVX Conference 2018 – Dennis Giese

Possible Countermeasures

• Changing the firmware key

– Useless -> we will figure out ;)

• Encrypting/Obfuscating the log-files and maps

– Recently introduced

– Here is the AES128CBC-key: “RoCKR0B0@BEIJING”Copyright: 20th Century Fox

Page 77: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

77beVX Conference 2018 – Dennis Giese

How to get the log and map AES key?

• RRlogd uses AES encryption functions from OpenSSL library

– Imported as dynamic library

– Interesting function: EVP_EncryptInit_ex(...)

• Helpful tool: ltrace

– Intercepts library calls

– Shows contents arguments of function calls

Page 78: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

78beVX Conference 2018 – Dennis Giese

Persistance

• Patch the recovery partition

• Disable updates

• Extract credentials

– Content of “vinda.conf” = root password (XOR 0x37)

– DID, cloud key

Page 79: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

79beVX Conference 2018 – Dennis Giese

Side note about Entropy

• Recap: Token is AES256 key

– Method used for Generation:

• Initialization: srand(seed)

– seed has 231 states

• 16 times rand()

Res

earc

h in

co

op

erat

ion

wit

h J

an R

uge

Page 80: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

80beVX Conference 2018 – Dennis Giese

Summary of the Vacuum

• Rooting

– Remote! (No „foil attack“ required anymore)

• Cloud Connection

– Run without cloud

• Support by third-party tools (e.g. FloleVac, FHEM, etc)

– Run with your own cloud

htt

ps:

//xi

aom

i.flo

le.d

e/

Page 81: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

81beVX Conference 2018 – Dennis Giese

Connection to the Dark Side

• Idea by Prof. Noubir: Let’s run Tor hidden services on IoT

– Paper from 2015: OnionBots, a stealthy botnet with compromised IoT devices

• Easy to install in Ubuntu

– Make SSH accessible via TOR

– No need for NAT ;)

htt

ps:

//ar

xiv.

org

/pd

f/1

50

1.0

33

78

.pd

f

Page 82: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

82beVX Conference 2018 – Dennis Giese

SUMMARY

Page 83: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

83beVX Conference 2018 – Dennis Giese

Conclusion

• Basic best practices not used

– firmware signatures

– HTTPS, certificate verification

– Hardware security features

• Difficult/impossible to patch

• Good

– We can modify the devices

• Bad

– Someone else can do too

Page 84: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

84beVX Conference 2018 – Dennis Giese

One word of warning…

• Never leave your devices unprovisioned

– Someone else can provision it for you

• Install malicious firmware

• Be careful with used devices

– e.g. Amazon Marketplace, Ebay, etc.

– Some malicious software may be installed

• Never install rooted firmware from untrusted sources !!!!

– Expecially not from russian forums!

Page 85: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

85beVX Conference 2018 – Dennis Giese

Acknowledgements

• Daniel Wegemer (aka DanielAW)

• Prof. Guevara Noubir (CCIS, Northeastern University)

• Secure Mobile Networking (SEEMOO) Labs and CROSSING S1

• Andrew Sellars and Team (Boston University Technology & Cyberlaw Clinic)

htt

p:/

/ww

w.c

cs.n

eu

.ed

u/h

om

e/n

ou

bir

/h

ttp

s://

ww

w.s

eem

oo

.info

rmat

ik.t

u-d

arm

stad

t.d

e/

htt

ps:

//si

tes.

bu

.ed

u/t

clc/

Page 86: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

86beVX Conference 2018 – Dennis Giese

Questions?

Contact:See: http://dontvacuum.meTelegram: https://t.me/kuchenmonsterTwitter: dgi_DEMeet me in Boston/@DC617

Page 87: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

87beVX Conference 2018 – Dennis Giese

WI-FI NETWORK SPEAKERDEVELOPED BY: XIAOMI

Ap

plie

s to

: xia

om

i.wif

isp

eake

r.v1

, bas

ic id

ea a

lso

fo

r xi

aom

i.ro

ute

r.*

For reference

Page 88: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

88beVX Conference 2018 – Dennis Giese

Overview Hardware

• CPU: Amlogic Meson3

– ARM Cortex-A

• RAM: 128MB

• Flash: 8GByte

• WI-Fi+BT: Broadcom BCM4345

• OS: OpenWRT

– Samba 3.x

• Released: End 2016

Page 89: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

89beVX Conference 2018 – Dennis Giese

Serial Port

Page 90: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

90beVX Conference 2018 – Dennis Giese

Rooting

• Teardown of device not necessary

• Classic vulnerability: no input validation

http://{ip}:9999/{ssdp id}/Upnp/resource/sys?command=nslookup&host=`echo 192.168.0.2`&dns_server=`/etc/init.d/ssh start`

Update (08.08.2018): Xiaomi claims this was fixed in an

internal release in April 2018

Res

earc

h in

co

op

erat

ion

wit

h “

tep

rrr”

Page 91: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

91beVX Conference 2018 – Dennis Giese

Firmware updates

• Query Update Information over HTTP

– http://soundbar.pandora.xiaomi.com/XXXXXXX/XXXXXX

• Firmware updates over HTTP

– packed LZMA in XML format

– EXT2 images

– No signatures

Page 92: Not all IoT Devices are Created Equal: Reverse Engineering ... · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland

92beVX Conference 2018 – Dennis Giese