hitcon community 2018 dennis giese · products • ~260 different models supported (wifi + zigbee +...

85
Reverse Engineering 101 of the Xiaomi IoT ecosystem HITCON Community 2018 – Dennis Giese

Upload: others

Post on 12-Aug-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

Reverse Engineering 101 of the Xiaomi IoT ecosystemHITCON Community 2018 – Dennis Giese

Page 2: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

2HITCON Community 2018 – Dennis Giese

Outline

• Motivation

• Xiaomi Cloud

• Overview of devices

• Reverse Engineering of devices

– Intro

– Vacuum Cleaning Robot

– Wi-Fi Network Speaker

– Smart Home Gateway and Lightbulbs

Page 3: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

3HITCON Community 2018 – Dennis Giese

About me

• Researcher at Northeastern University, USA

• Grad student at TU Darmstadt, Germany

• [Insert more uninteresting information here]

• Why I am at HITCON?

– First time in Asia, Curiosity wins

– Xiaomi devices are actually used here ;)

– There is a Xiaomi store in Taipei

Page 4: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

4HITCON Community 2018 – Dennis Giese

MOTIVATION

Page 5: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

5HITCON Community 2018 – Dennis Giese

Why reverse IoT?

• Depending on attacker model

– (Find and exploit bugs to hack other people)

– De-attach devices from the vendor

– Enhance functionality

• Add new features

• Localization: new languages

– Research of privacy problems

• Questions: What data is collected?

Page 6: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

6HITCON Community 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 7: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

7HITCON Community 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 Lamp

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

Page 8: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

8HITCON Community 2018 – Dennis Giese

Why Vacuum Robots?

Source: Xiaomi advertisment

Page 9: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

9HITCON Community 2018 – Dennis Giese

THE XIAOMI CLOUD

Page 10: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

10HITCON Community 2018 – Dennis Giese

Xiaomi Cloud

• Different Vendors, one ecosystem

– Same communication protocol

– Different technologies supported

• Guidelines for implementation exists

– Implementation differs from manufacturer to manufacturer

– Software quality very different

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

Page 11: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

11HITCON Community 2018 – Dennis Giese

Xiaomi Ecosystem

HTTPS

ZigBee

Xiaomi Cloud(Mi)

Gateway

WiFi

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

Page 12: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

12HITCON Community 2018 – Dennis Giese

Device to Cloud Communication

• DeviceID

– Unique per device

• Keys

– Cloud key (16 byte alpha-numeric)

• Is used for cloud communication (AES encryption)

• Static, is not changed by update or provisioning

– Token (16 byte alpha-numeric)

• Is used for app communication (AES encryption)

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

Page 13: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

13HITCON Community 2018 – Dennis Giese

Cloud protocol

• Same payload for UDP and TCP stream

• Encryption key depending of Cloud/App usage

• For unprovisioned devices:– During discovery: Token in plaintext in the checksum field

Byte 0,1 Byte 2,3 Byte 4,5,6,7 Byte 8,9,A,B Byte C,D,E,F

Header Magic:2131 Lenght 00 00 00 00 DID epoch (big endian)

Checksum Md5sum[Header + Key(Cloud)/Token(App) + Data(if exists)]

Data Encrypted Data (if exists, e.g. if not Ping/Pong or Hello message)• token = for cloud: key; for app: token• key = md5sum(token)• iv = md5sum(key+token)• cipher = AES(key, AES.MODE_CBC, iv, padded plaintext)

Page 14: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

14HITCON Community 2018 – Dennis Giese

Cloud protocol

• Data– JSON-formatted messages– Packet identified by packetid– Structures:

• commands: "methods" + "params"• responses : "results"

– Every command/response confirmed by receiver (except otc)• Example

– {'id': 136163637, 'params': {'ap': {'ssid’: ‘myWifi', 'bssid': 'F8:1A:67:CC:BB:AA', 'rssi': -30}, 'hw_ver': 'Linux', 'life': 82614, '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'}, 'partner_id': '', 'method': '_otc.info'}

Page 15: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

15HITCON Community 2018 – Dennis Giese

Xiaomi Ecosystem

HTTPS

ZigBee

XiaomiCloud

Gateway

WiFi

Page 16: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

16HITCON Community 2018 – Dennis Giese

App to Cloud communication

• Authentication via OAuth

• Layered encryption

– Outside: HTTPs

– Inside: RC4/AES using a session key

• Separate integrity

• Message format: JSON RPC

• Device specific functions: provided by Plugins

Page 17: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

17HITCON Community 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 18: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

18HITCON Community 2018 – Dennis Giese

App to Cloud communication

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

Source: Openstreetmaps

Page 19: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

19HITCON Community 2018 – Dennis Giese

LETS TAKE A LOOK AT THE PRODUCTS

Page 20: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

20HITCON Community 2018 – Dennis Giese

Products

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

• Depending on selected server location

– Mainland China

– Taiwan

– US

– …

– models not always compatible

• My inventory: ~40 different models

– 95 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

Update after I went to the Mi Store: 42 models, 99 devices ☺

Page 21: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

21HITCON Community 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)

Focus of this talk

Page 22: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

22HITCON Community 2018 – Dennis Giese

Why I hate ESP8266

• Weird architecture

• Difficult to reverse engineer

– No decompiler

– Limited disassembler support

– No useable JTAG

• Its easier to replace the firmware

– UART or OTA-Update

• Good news: No SSL, unencrypted firmware over HTTP

Ap

plie

s to

: p

hili

ps.

ligh

t.b

ulb

, ph

ilip

s.lig

ht.

do

wn

ligh

t,

rob

oro

ck.v

acu

um

.c1

, ro

bo

rock

.vac

uu

m.e

2vi

om

i.dis

hw

ash

er.v

01

, ...

Page 23: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

23HITCON Community 2018 – Dennis Giese

Why I hate ESP8266

Page 24: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

24HITCON Community 2018 – Dennis Giese

Operation Systems

• Ubuntu 14.04

– Vacuum cleaning robots

• OpenWRT

– Xiaomi Wifi Speaker, Routers, Minij washing machine

• Embedded Linux

– IP cameras

• RTOS

– Smart Home products

– Lightbulbs, ceiling lights, light strips

Page 25: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

25HITCON Community 2018 – Dennis Giese

Implementations

Vacuum Robot Smart Home Gateway* Philips Ceiling LightYeelink Bedside Lamp

Manufacturer Rockrobo Lumi United Yeelight

MCU Allwinner + STM + TI Marvell (Wi-Fi) MediaTek (Wi-Fi + BLE)

Firmware Update Encrypted + HTTPS Not Encrypted(No SSL stack!)

Not Encrypted + HTTPS (No Cert check!)

Debug Interfaces Protected Available Available

*Does not apply for DGNWG03LM (Gateway model for Taiwan)

Page 26: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

26HITCON Community 2018 – Dennis Giese

LETS GET ACCESS TO THE DEVICES

Page 27: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

27HITCON Community 2018 – Dennis Giese

How to get access

• Hardware-based access

– Micro USB Port ?

– Serial Connection on PCB ?

– JTAG/SWD?

– Flash ?

• Network-based access

– Open Ports ?

– Sniff Network traffic ?

Page 28: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

28HITCON Community 2018 – Dennis Giese

Warranty seal?

Page 29: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

29HITCON Community 2018 – Dennis Giese

When everything fails

• Trace pins of the IC– Datasheets/SDKs are your friends– Destructive method for BGA:

• Desolder IC and trace test-points– Non-destructive method for BGA/SO:

• Measure voltage of test-points– If 3.3 Volt: potential candidate for UART (TX)

• Signal Analyzer• educated guessing

– Following lines with microscope• X-Ray ;)

Page 30: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

30HITCON Community 2018 – Dennis Giese

VACUUM CLEANING ROBOTS

Res

earc

h in

co

op

erat

ion

wit

h D

anie

l Weg

emer

rock

rob

o.v

acu

um

.v1

, ro

bo

rock

.vac

uu

m.s

5

Page 31: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

31HITCON Community 2018 – Dennis Giese

Gen 1 Device Overview

Source: Xiaomi advertisment

Page 32: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

32HITCON Community 2018 – Dennis Giese

Teardown

Page 33: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

33HITCON Community 2018 – Dennis Giese

Frontside layout mainboard

512 MB RAM

R16SOC

4GBeMMCFlash

WiFi Module

STM32 MCU

Page 34: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

34HITCON Community 2018 – Dennis Giese

Backside layout mainboard

R16 UART(115200 baud)TxRx

STM UART (921600 baud)

Tx

LIDAR UART

Page 35: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

35HITCON Community 2018 – Dennis Giese

Frontside layout mainboard (GEN2)

512 MB RAM

R16SOC

4GBeMMCFlash

WiFi Module

STM32MCU

Page 36: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

36HITCON Community 2018 – Dennis Giese

Rooting

• Usual (possibly destructive) way to retrieve the firmware

Page 37: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

37HITCON Community 2018 – Dennis Giese

Rooting

Our weapon of choice:

Page 38: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

38HITCON Community 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 39: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

39HITCON Community 2018 – Dennis Giese

Rooting (Gen1 + Gen2)

Initial Idea:

• 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 40: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

40HITCON Community 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)

Page 41: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

41HITCON Community 2018 – Dennis Giese

Available data on device

• Data– Logfiles (syslogs, stats, ssid, passwd)– “/usr/sbin/tcpdump -i any -s 0 -c 2000 –w”– Maps

• Data is uploaded to cloud• Factory reset

– Restores recovery to system– Does not delete data

• Maps, Logs still exist

Page 42: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

42HITCON Community 2018 – Dennis Giese

Available data on device

• Maps

– Created by player

– 1024px * 1024px

– 1px = 5cm

Page 43: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

43HITCON Community 2018 – Dennis Giese

Robot intern

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

Page 44: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

44HITCON Community 2018 – Dennis Giese

eMMC LayoutLabel Content Size in MByte

boot-res bitmaps & some wav files 8

env uboot cmd line 16

app device.conf (DID, key, MAC), adb.conf, vinda 16

recovery fallback copy of OS 512

system_a copy of OS (active by default) 512

system_b copy of OS (passive by default) 512

Download temporary unpacked OS update 528

reserve config + calibration files, blackbox.db 16

UDISK/Data logs, maps, pcap files ~1900

Page 45: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

45HITCON Community 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 46: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

46HITCON Community 2018 – Dennis Giese

Firmware updates

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

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

• Integrity– MD5 provided by cloud

Sound PackagesStatic password: “r0ckrobo#23456”

Page 47: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

47HITCON Community 2018 – Dennis Giese

Page 48: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

48HITCON Community 2018 – Dennis Giese

Lets root remotely

• Preparation: Rebuild Firmware

– Include authorized_keys

– Remove iptables rule for sshd

• Send „miIO.ota“ command to vacuum

– Encrypted with token

• From app or unprovisioned state

– Pointing to own http server

Page 49: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

49HITCON Community 2018 – Dennis Giese

Lets root remotely

„miIO.ota“

unprovisioned state

„Get Token“

Webserver

Page 50: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

50HITCON Community 2018 – Dennis Giese

SSH

Page 51: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

51HITCON Community 2018 – Dennis Giese

Page 52: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

52HITCON Community 2018 – Dennis Giese

Page 53: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

53HITCON Community 2018 – Dennis Giese

Gain Independence

Xiaomi Cloud

Copyright: 20th Century Fox

Page 54: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

54HITCON Community 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 55: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

55HITCON Community 2018 – Dennis Giese

Possible Countermeasures

• Changing the firmware key

– Useless -> we will figure out ;)

• Encrypting the MMC, enabling Secure Boot

– Allwinner R16 does not support this

• Encrypting/Obfuscating the log-files and maps

– They tried in the last version

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

Page 56: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

56HITCON Community 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 57: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

57HITCON Community 2018 – Dennis Giese

Helpful Tools

• Dustcloud (https://github.com/dgiese/dustcloud)

– image builder: generation of custom firmware

– flasher: easy installation of firmware

– “Dustcloud”: emulation of the Xiaomi Smarthome Cloud

• Interesting projects

– Aerodust: WiFi signal strength mapping using the robot

– Various local interfaces (maps, controls)

Page 58: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

58HITCON Community 2018 – Dennis Giese

Summary of the Vacuum

• Rooting

– Remote!

• Cloud Connection

– Run without cloud

– Run with your own cloud

• Main objective: We want the Cloudkeys!

Page 59: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

59HITCON Community 2018 – Dennis Giese

WI-FI NETWORK SPEAKER

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.*

Page 60: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

60HITCON Community 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

– VLC libraries

Page 61: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

61HITCON Community 2018 – Dennis Giese

Serial Port

Page 62: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

62HITCON Community 2018 – Dennis Giese

Rooting

• Teardown of device not necessary

• Firmware updates over HTTP

– packed LZMA in XML format

• 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`

Page 63: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

63HITCON Community 2018 – Dennis Giese

SMART HOME GATEWAY, LIGHTBULBS AND LED STRIPS

Ap

plie

s to

: yee

link.

ligh

t.co

lor2

, yee

link.

ligh

t.ct

2, y

eelin

k.lig

ht.

mo

no

1,

yeel

ink.

ligh

t.co

lor1

, zim

i.po

wer

stri

p.v

2, c

hu

angm

i.plu

g.m

1, l

um

i.gat

eway

.v3

*Does not apply for DGNWG03LM (Gateway model for Taiwan)

Page 64: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

64HITCON Community 2018 – Dennis Giese

Xiaomi Ecosystem

HTTPS

ZigBee

XiaomiCloud

Gateway

Page 65: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

65HITCON Community 2018 – Dennis Giese

Overview Hardware

• Application-MCU: Marvell 88MW30x *– ARM Cortex-M4F @ 200 MHz– RAM: 512 KByte SRAM– Flash: 16 MByte (Gateway)

• 4 Mbyte SPI (LED Strip, Lightbulb, etc)– Integrated 802.11b/g/n WiFi Core– Device ID + Keys stored in OTP memory

• Zigbee-MCU: NXP JN5169 (Gateway only)– 32-bit RISC CPU– RAM: 32 kB– Flash: 512 kB embedded Flash, 4 kB EEPROM

*Does not apply for DGNWG03LM (Gateway Model for Taiwan)

Page 66: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

66HITCON Community 2018 – Dennis Giese

Sensors connected via gateway

Zigbee (NXP JN5169) based• Door Sensor (Reed contact)• Temperature sensor• Power Plug• Motion Sensor• Button• Smoke Detector• Smart Door Lock• …

Page 67: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

67HITCON Community 2018 – Dennis Giese

• PCB got lots of testing points

• SWD is enabled by default

Acquiring the Key

SDCLK SDIO

RST TX* GND RX*

We can get the keyfrom the memdump

*UART

Page 68: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

68HITCON Community 2018 – Dennis Giese

Acquiring the Key

• Can we get the Key without a hardware attack?

• Firmware updates are not signed…

No hardware access needed

The lightbulb runs a bare-metal OS => we need to patch the binary

Lets create a modified firmwarewhich gives us the keyautomatically!

Page 69: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

69HITCON Community 2018 – Dennis Giese

Good news

• Vendors are lazy

• Assumed development of firmware:

– Take SDK/toolchain of chip vendor (e.g. Marvell)

– Add Mijia/Mi SDK with samples

– Modify sample that the product runs

– If it works: publish firmware

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

Page 70: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

70HITCON Community 2018 – Dennis Giese

Binary Patching: Goals

• Modify program flow

• Add additional code

• Use existing functions

Original code

Branch: Original code

Patch code

Branch: Patch code

Page 71: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

71HITCON Community 2018 – Dennis Giese

Binary Patching: Why can it be hard?

• Overwrite branch instructionsNew Address = Value of PC + Offset (on ARM)

• Write new code in assembly

• Model address space (RAM / ROM / free space)

• Call existing functions

• Handle different firmware versions and devices

htt

ps:

//gi

thu

b.c

om

/se

emo

o-l

ab/n

exm

on

Page 72: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

72HITCON Community 2018 – Dennis Giese

Nexmon requirements

• Known memory layout

• Known function names and signature

• Free space on flash for patch

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

Page 73: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

73HITCON Community 2018 – Dennis Giese

Binary Patching: Nexmon Framework

Get function names:

main()

Compile Example Project with debug symbols

(e.g. from SDK)

011010100011

vs

Use Bindiff to applyfunction names

Load ELF binary into IDA Pro

Page 74: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

74HITCON Community 2018 – Dennis Giese

Binary Patching: Nexmon Framework

• Write your patch code in C

– Reuse existing functions

Original code

Branch: Original code

Patch code

Page 75: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

75HITCON Community 2018 – Dennis Giese

Preparing the modified binary (Marvell)

• Binaries have special format

– SPI format != OTA format

– Convertion from OTA binary to ELF file helpfulByte 0-3 4-7 8-11 12-15 16-19

Magic Magic Timestamp # of segments entry address

0x00000000 4D 52 56 4C 7B F1 9C 2E FF BE A8 59 03 00 00 00 19 37 00 1F

"MRVL" 0x1f003719

segment magic offset in file size of segment mem addr checksum

0x00000014 02 00 00 00 C8 00 00 00 50 36 00 00 00 00 10 00 20 C8 51 7D

0xc8 0x3650 0x100000

segment magic offset in file size of segment mem addr checksum

0x00000028 02 00 00 00 18 37 00 00 28 15 08 00 18 37 00 1F 0A 11 25 85

0x3718 0x81528 0x1f003718

segment magic offset in file size of segment mem addr checksum

0x0000003C 02 00 00 00 40 4C 08 00 54 19 00 00 40 00 00 20 FB 5F ED 39

0x84c40 0x1954 0x20000040

We have Python tools for that

Bin -> ELFELF -> Bin

Page 76: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

76HITCON Community 2018 – Dennis Giese

Preparing the modified binary (Mediatek)

• Mediatek Segments: lzma-compressed

Byte 0-3 4-7 8-11 12-15 16-19

Magic # of Segments Offset in File mem addr Size of segment

0x00000000 4D 4D 4D 00 03 00 00 00 C8 00 00 00 00 00 10 00 50 36 00 00

„MMM" 0xc8 0x100000 0x3650

… …

SHA-1 Checksum…

0x00000080

…SHA-1 Checksum Segment data

0x00000090 …

Page 77: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

77HITCON Community 2018 – Dennis Giese

Applying the modified firmware

Xiaomi Cloud

Xiaomi CDN

Our CDN ;)

DNS

Page 78: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

78HITCON Community 2018 – Dennis Giese

Proxy cloud communication

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

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

Android/iPhone App

DNS Records

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

Dustcloud

<-commands,reports->

Page 79: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

79HITCON Community 2018 – Dennis Giese

Summary Lightbulbs/Gateway

• Rooting

– Modification of the firmware

– Remote! (thanks to missing integrity checks)

• Cloud Connection

– Read all cloud communications in plaintext

– Run with your own cloud

Page 80: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

80HITCON Community 2018 – Dennis Giese

One word of warning…

• Never leave your devices unprovisioned

– Someone else can provision it for you

• Install malicious firmware

• Snoop on your apartment

• Be careful with used devices

– e.g. Amazon Marketplace

– Some malicious software may be installed

Page 81: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

81HITCON Community 2018 – Dennis Giese

Conclusion

• Basic best practices not used

– No firmware signatures

– Use of HTTPS and certificate verification broken

– Hardware security features are missing

• Good

– We can modify the devices

• Bad

– Someone else can do too

Page 82: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

82HITCON Community 2018 – Dennis Giese

Acknowledgements

• Secure Mobile Networking (SEEMOO) Labs and CROSSING S1

• Prof. Guevara Noubir (CCIS, Northeastern University)

• Daniel Wegemer (aka DanielAW)

• Special thanks to my credit card and bank account ;)

→www.dontvacuum.me

Page 83: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

83HITCON Community 2018 – Dennis Giese

Questions?

Page 84: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

84HITCON Community 2018 – Dennis Giese

Page 85: HITCON Community 2018 Dennis Giese · Products • ~260 different models supported (WiFi + Zigbee + BLE) • Depending on selected server location –Mainland China –Taiwan –US

85HITCON Community 2018 – Dennis Giese