60
Multi ARCH Firmware Emulation #JDHITB2018 BEIJING, November 2018 Yu Tong KaiJern LAU

Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Multi ARCH Firmware Emulation

#JDHITB2018 BEIJING, November 2018

Yu Tong

KaiJern LAU

Page 2: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Why This Talk Exits and Thanks RD

This Talk Is Part of 2nd Nov, Fuzzing Talk

Page 3: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

About NGUYEN Anh Quynh

> Nanyang Technological University, Singapore

> PhD in Computer Science

> Operating System, Virtual Machine, Binary analysis, etc

> Usenix, ACM, IEEE, LNCS, etc

> Blackhat USA/EU/Asia, DEFCON, Recon, HackInTheBox,

Syscan, etc

> Capstone disassembler: http://capstone-engine.org

> Unicorn emulator: http://unicorn-engine.org

> Keystone assembler: http://keystone-engine.org

Page 4: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

About KaiJern

Founder of

hackersbadge.com, RE &&

CTF fan

Badge Maker

> Reversing Binary

> Reversing IoT Devices

> Part Time CtF player

Hack in the box, Netherland

and Singapore. Soon to be

Beijing and Dubai

HITB

Security Conference

> 2006 till end of time

> Core Crew

> Review Board

> 2005, HITB CTF, Malaysia, First Place /w 20+ Intl. Team

> 2010, Hack In The Box, Malaysia, Speaker

> 2012, Codegate, Korean, Speaker

> 2015, VXRL, Hong Kong, Speaker

> 2015, HITCON Pre Qual, Taiwan, Top 10 /w 4K+ Intl. Team

> 2016, Codegate PreQual, Korean, Top 5 /w 3K+ Intl. Team

> 2016, Qcon, Beijing, Speaker

> 2016, Kcon, Beijing, Speaker

> 2016, Intl. Antivirus Conference, Tianjin, Speaker

> MacOS SMC, Buffer Overflow, suid

> GDB, PE File Parser Buffer Overflow

> Metasploit Module, Snort Back Oriffice

> Linux ASLR bypass, Return to EDX

Stay in the office 24/7 by

hoping making the world a

better place

The Shepherd Lab

> IoT Research

> Blockchain Research

> Fun Security Research

> 2017, Kcon, Beijing, Trainer

> 2017, DC852, Hong Kong, Speaker

> 2018, KCON, Beijing, Trainer

> 2018, DC010, Beijing, Speaker

> 2018, Brucon, Brussel, Speaker

> 2018, H2HC, San Paolo, Brazil

> 2018, HITB, Beijing/Dubai, Speaker

> 2018, beVX, Hong Kong, Speaker

Page 5: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Your Very First IoT Device

Some Said Wi-Fi Router

Page 6: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Why Hacking IoT

Remembering,

smashing the stack for fun and profit

Page 7: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Why IoT Research Is Important

> Binary only - without source code

> Existing guided fuzzers rely on source code

available

> Source code is needed for branch

instrumentation to feedback fuzzing

progress

> Emulation such as QEMU mode support in

AFL is slow & limited in capability

> Same issue for other tools based on

Dynamic Binary Instrumentation

> Without built-in shell access for user

interaction

> Without developement facilities required for

building new tools

> Compiler

> Debugger

> Analysis tools

> Most fuzzers are built for X86 only

> Embedded systems based on Arm,

Arm64, Mips, PPC

> Existing DBIs are poor for non-X86 CPU

> Pin: Intel only

> DynamoRio: experimental support for

Arm

Firmware

Emulation

Skorpio

DBI

Guided

Fuzzer for Embedded

Page 8: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Back to School Edition: DEFINATION of IoT

Page 9: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Definition of IoT – From The Book

Any Online-able THINGS

Page 10: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

The Real Definition of IoT

Human Operated + Online-able Item + AI Capability

* Data Mining(maybe) Business *

Page 11: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Attack Surface

Page 12: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Attacker Perspective

> Data Transmission Hijack

> Sniffing

> Household Security

> Device Password

> Server OS Security

> Application Security

> Vendor Data Center Security

> Communication Protocol

Again, Why?

Is To Discover The Truth

Page 13: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Back To 101

Page 14: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Everything is small, Including SECURITY

➢ System on Chip

➢ A chip with all the PCI-e slot and card in it

➢ Pinout to different parts

➢ WiFi, Lan, Bluetooth and etc

➢ Low power device

➢ Strip Down Power Usage

➢ Strip Down Size

➢ Strip Down Processing

➢ Strip Down SECURITY

Page 15: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Skillz

Page 16: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Requirement

Understanding The Board

Page 17: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Requirement: Software

Skill @ GNU Command Set

Page 18: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Lets Get Started

Page 19: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Device Limited Bug

If all_model = one_firmware

In The Beginning:

We Need Firmware

Page 20: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Getting Firmware

Page 21: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

c

Firmware and Hardware

Extract From APK, Traffic Sniffing or Just Download

1. Download 2. Patch with Backdoor 3. Flash 4. pwned

If we need more ?

1. RCE 2. Study the firmware

c

Page 22: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Firmware Architecture

Page 23: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Romance of 3 Kingdom

MIPS ARM AARCH64

We learn from the hard way (aka story time)

Page 24: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

The Easy Way

Page 25: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Complete Kit to Success

MIPS ARM AARCH64Interchangeable Base Board

If There are only 3 platform,

Download, Flash, Reverse and pwn !!!

Page 26: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

If *ARM/AARCH64* Why Not Raspberry PI

Page 27: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

LIBC Compatibility

MIPS ARM AARCH64Not Supported by Raspberry PI

Raspberry PI Is not *reverser* Friendly

So, QEMU is a MUST

Page 28: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Assembly Instruction Compatibility

ARM AARCH64

Page 29: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Current Work Around

Page 30: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Qemu Static

QEMU-Static is good for binary execution without additional

software or hardware interection

Page 31: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Current Primitive Firmware Emulation

Leaving squashfs and going into a unknown world

Its not easy after 2016

Page 32: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Why Firmware Emulation

Page 33: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

More Resources = More Power

Processor RAM FLASH

Most Important, we got apt-get

Multicore MAX RAM MAX Space

Normally 1-2 Core Normally

256MB/512MB

Normally

8MB/16MB/32MB/256MB

Page 34: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Objectives

Page 35: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Only One Process with Interaction

most of the devices comes with one big binary

Hunt for the one that spawn

listener port

Page 36: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Booting Up

Page 37: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Distro and Kernel Mix and Match

argument: running new or old distro + kernel

script to boot arm script to boot mips

Page 38: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

chroot

Page 39: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Easy Way Out, chroot

chroot is easy (still hardware dependent), but we will have issue with tools

Running without chroot

Page 40: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Classic Case: File Not Found

Page 41: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

The File Missing Trick

We found you

We Missed You

Page 42: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

The missing .SO and binary Issue

Page 43: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Out from chroot, we need feeeding

Feeding all the required so and binary with “ln –s”

Page 44: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Out from chroot, we need feeding

“segfault” without clear error. strace come to rescue

Classical file not found error

Page 45: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

The Secretive NVRAM

Page 46: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

reply with

nvram info

Dark side of NVRAM

ask for nvram info

main process

interactor

Relationship between main binary is so intimate,

but in actual fact. Is just a hit and run

Page 47: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

reply with

nvram info

Dark Side of NVRAM

ask for nvram info

main process

Relationship between main binary is so intimate,

but in actual fact. Is just a hit and run

Dark Side of the main process, we ignore and con’t to next step

interactor

Page 48: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

A fake NVRAM

ask for nvram info

main process

interactor

IF interactor is the medium,

can we fake it ?

reply with

nvram info

Page 49: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

A fake NVRAM

ask for nvram info

main process

interactor

reply with

nvram info

Custom Interactor

IF interactor is the medium,

can we fake it ?

Page 50: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

br0

Page 51: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

The bridge trick

The switch looking device

Page 52: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Wireless Device

Page 53: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Faking wpa_supplicant

making eth0 looks like wlan0 works too

Page 54: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Everything Things Else Fail

Page 55: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

BL, BNE, BEQ and friends

Patched BIN

Argument: To Patch or To Fulfill Firmware Needs

Original BIN

Page 56: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

DEMO *bug disclosed in geekpwn 2018, shanghai*

Page 57: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Web Cam Buffer Overflow

Pre Authentication Bug

Buffer Overflow

Address Overwritten

Debug is almost Impossible *watchdog*

Emulation comes into play

Page 58: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

IoT with UDP Access

Web Cam with Motor

Page 59: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Command Execution Injection

Chinese based WiFi Router

Page 60: Multi ARCH Firmware Emulation - Hack In The Box · Hack in the box, Netherland and Singapore. Soon to be Beijing and Dubai HITB Security Conference ... WiFi, Lan, Bluetooth and etc

Questions

Multi ARCH Firmware Emulation

Yu Tong

KaiJern LAU