hacker halted 2014 - reverse engineering the android os

113

Upload: ec-council

Post on 09-Jul-2015

372 views

Category:

Technology


3 download

DESCRIPTION

Introduction to the Android OS. the Android Developers Kit, Android Emulators, Rooting Android devices, de-compiling Android Apps. Dex2jar, Java JD_GUI and so on. During the presentation I will pull an App apart and show how to bypass a login screen. What better way to express the Zombie Apocalypse then with mobile devices. They are ubiquitous. they are carried everywhere, they go everywhere. Having a decent understanding of the Operating System and it’s vulnerabilities can go a long way towards keeping your device protected.

TRANSCRIPT

Page 1: Hacker Halted 2014 - Reverse Engineering the Android OS
Page 2: Hacker Halted 2014 - Reverse Engineering the Android OS

Reverse Engineeringthe

Android OS

Page 3: Hacker Halted 2014 - Reverse Engineering the Android OS

About MeEx Military “31 Mic” Microwave Communications - 34th Signal Battalion

Lab Developer for Jones and Bartlett Publishing

CEI – CEH V8

Martial Art Nutcase

Co-creator of Cyber Kung Fu

Page 4: Hacker Halted 2014 - Reverse Engineering the Android OS

Reverse Engineering

• Understand how applications work

• Analyze them

• Find vulnerabilities

• Uncover hard coded information

Page 5: Hacker Halted 2014 - Reverse Engineering the Android OS

Why do I want to Hack Mobile Devices

Page 6: Hacker Halted 2014 - Reverse Engineering the Android OS

• Natural Curiosity

• MacGyver Fan

• CEH V8 mobile sucked

• Humongous Installed Base

• Self Defense

Page 7: Hacker Halted 2014 - Reverse Engineering the Android OS

Lots of important information

• Contacts• Messages• Photos• Email• GPS co-ordinates• Personal notes• Stored accounts• Web traffic• Application configs and credentials

Page 8: Hacker Halted 2014 - Reverse Engineering the Android OS

Double Edged Sword

• User moves between work and personal environments

• Carries Corporate Data

• Device can be compromised in less secure areas

• Compromised device is then connected to work environment

Page 9: Hacker Halted 2014 - Reverse Engineering the Android OS

Theft and Loss

• Weak protective mechanisms

• Compounded by users turning off security features

• Rooted devices

Page 10: Hacker Halted 2014 - Reverse Engineering the Android OS

More Problems

• Increasing everyday use

• Users not educated

• Mix of personal and business use

• Always connected to internet

Page 11: Hacker Halted 2014 - Reverse Engineering the Android OS

Physical Security

• Phone is easily accessed

• SD Card

• Charging/io port access – Rubber Ducky

• Shoulder Surfing

• Smudge attack

Page 12: Hacker Halted 2014 - Reverse Engineering the Android OS

Web Issues

• Small screen hides full URL

• XSS

• CSRF

• Phishing

Page 13: Hacker Halted 2014 - Reverse Engineering the Android OS

Rogue Applications

• Malware

• Virus

• Trojans

• Spyware

Page 14: Hacker Halted 2014 - Reverse Engineering the Android OS

History

• Cabir – 2004

• Skulls – 2004

• pbstealer

• Commwarrior

• Cardtrap

• All Symbion basesd but eventually spread to CE and Java (J2ME

Page 15: Hacker Halted 2014 - Reverse Engineering the Android OS

Android and IOs

• Ikee – 2009/2010 - worm

• AndroidOS.FakePlayer – premuium SMS

• Geinimi Trojan

• SMS Replicator

• DroidDream

• GinerMaster

• DroidKungFu

Page 16: Hacker Halted 2014 - Reverse Engineering the Android OS

Older Devices

• Out of date software

• Vulnerable to older fixed exploits

• Patching – no incentive for older hardware

• Carrier indifference

Page 17: Hacker Halted 2014 - Reverse Engineering the Android OS

Architecture

Page 18: Hacker Halted 2014 - Reverse Engineering the Android OS

KernelFirst layer to interact with Hardware

Page 19: Hacker Halted 2014 - Reverse Engineering the Android OS

C/C++ Libraries

• Exposed to developer via Java API

• Kind of a transaction layer between kernel and application framework

• Provides common services for apps

Page 20: Hacker Halted 2014 - Reverse Engineering the Android OS

Core Libraries

• SSL

• SLite

• Surface Manager

• WebKit

• Font, media, display libraries

Page 21: Hacker Halted 2014 - Reverse Engineering the Android OS

Runtime

• DVM – Dalvik Virtual Machine

• Efficient and Secure mobile environment

Page 22: Hacker Halted 2014 - Reverse Engineering the Android OS

Secure

• Each app runs in its own instance

• Unique ID and VM

• Separate memory and files

Page 23: Hacker Halted 2014 - Reverse Engineering the Android OS

Application Framework

• Compiled java code running in DVM

• Provides services to multiple apps

• Layer that 3rd party developers interact with

• Abstract access to key resources

Page 24: Hacker Halted 2014 - Reverse Engineering the Android OS

Application Layer• Contacts

• Phone

• Calendar

• Browser

• Maps

• Pictures

Page 25: Hacker Halted 2014 - Reverse Engineering the Android OS

Privilege Separation & Sandboxing

• Based on Linux security model

• Each user is assigned a unique ID (UID)

• Each user can be assigned to Groups

• Each Group has an unique ID (GID)

Page 26: Hacker Halted 2014 - Reverse Engineering the Android OS

Resource Permissions

• Owner

• Group

• Rest of world (everyone)

Page 27: Hacker Halted 2014 - Reverse Engineering the Android OS

Sandboxing

• Two or more applications can communicate

• Provided they grant permissions

• Implemented in the kernel

• Extended to all software above 1st layer

Page 28: Hacker Halted 2014 - Reverse Engineering the Android OS

App Separation

• Kernel assigns unique UID

• Runs as that user in separate process

• Different than multiuser OS

Page 29: Hacker Halted 2014 - Reverse Engineering the Android OS

File Separation

• New apps get new UIDs

• Extended across memory cards

• All associated DB and files use the new UID

Page 30: Hacker Halted 2014 - Reverse Engineering the Android OS

File Permissions

Page 31: Hacker Halted 2014 - Reverse Engineering the Android OS

Separate File Permission Groups

• Note – only the associated UID and root UID have full privileges on these resources unless the developer exposes files to other apps.

Page 32: Hacker Halted 2014 - Reverse Engineering the Android OS

SD Cards

• Everyone (Whole World) has access Storage

• Currently vfat fs

• Doesn’t support granular permissions

• Note – good place for privilege escalation

Page 33: Hacker Halted 2014 - Reverse Engineering the Android OS

Data Storage on the Device

• Databases

• SharedPreferences

Page 34: Hacker Halted 2014 - Reverse Engineering the Android OS

SharedPreferences

• Allows app to store and retrieve persistent key values

• Persist across device sessions

• Accesss using the SharedPreferences Object

• Stored as XML

• /data/data/”app”/shared_prefs

• Example

Page 35: Hacker Halted 2014 - Reverse Engineering the Android OS

SQLite3

• Full Support

• Accessed via the UID of the related app

• /data/data/”app”/databases

Page 36: Hacker Halted 2014 - Reverse Engineering the Android OS

Application Signing

• Ensures Integrity and Authenticity

• APK must be signed

• Inhibits tampering

• Aids confidentiality by insuring where it came from

• Apps signed with same key can share UID, Process, Memory, Data Storage and Sandbox

Page 37: Hacker Halted 2014 - Reverse Engineering the Android OS

Signing Quirks

• Apps can be disassembled and changed

• Can be resigned with same certificate if you have key

• Multiple apps can use same certificate

• App can be manipulated to accept same certificate

• Debugging certificate

Page 38: Hacker Halted 2014 - Reverse Engineering the Android OS

App access to resources

• Developer limits access to required resources

• Helps to inhibit rogue apps from taking over

• Text, GPS, MMS, camera, microphone, contacts

Page 39: Hacker Halted 2014 - Reverse Engineering the Android OS

API Permissions

• AndroidManifest.xml

• Used by trusted applications

• Tracks what the user is allowed to do

• Each app must have an AndroidManifest.xml

Page 40: Hacker Halted 2014 - Reverse Engineering the Android OS

Permission Model

• System displays permissions

• Helps user to decide to trust app or not.

Normal – Dangerous – Signature – Signature or System

Page 41: Hacker Halted 2014 - Reverse Engineering the Android OS

Components

• Activity

• Content Providers

• Broadcast Receivers

• Services

Page 42: Hacker Halted 2014 - Reverse Engineering the Android OS

Activity

• Provides a screen and allows a user to interact with it.

• A window where the user interface is defined

Page 43: Hacker Halted 2014 - Reverse Engineering the Android OS

Content Providers

• Allow efficient data sharing between processes & applications

• Allow applications to access the stored data of other applications

• Use relational databases similar to tables

• Each row is an Instance each column is a Type

• Pic

Page 44: Hacker Halted 2014 - Reverse Engineering the Android OS

Examples of Content Providers

• Calendar provider

• Contacts provider

Page 45: Hacker Halted 2014 - Reverse Engineering the Android OS

Broadcast Receiver

• Listens for asynchronous request from intents

• Apps can register for events and get notified when it happens

Page 46: Hacker Halted 2014 - Reverse Engineering the Android OS

Services

• Background processes

• Run even when app is not visible

• Provide computations

• Example is GPS

Page 47: Hacker Halted 2014 - Reverse Engineering the Android OS

SecurityException

• Without proper permissions a component call will raise a Security Exception

Page 48: Hacker Halted 2014 - Reverse Engineering the Android OS

Intents

• Mechanisms for asynchronous IPC (Inter Process Communication)

• Allow app to send or broadcast messages to specific components

• Control task and transport data

• Components like Activities, Broadcast Receivers & Services are activated via Intents

• Contain a large amount of information

• Parsed by OS & used by the receiver to take action

• Contain category and instruction for activity launch

Action – Data – Type – Category (note)

Page 49: Hacker Halted 2014 - Reverse Engineering the Android OS

Google Bouncer

• Automatically scans Android Market looking for malicious Apps

• Checks new applications

• Apps already in Store

• Developer accounts

• No restrictions on upload process

• Can be bypassed

Page 50: Hacker Halted 2014 - Reverse Engineering the Android OS

Rooting

• Gain Root permissions

• Allow access and editing of Carrier and Manufacturer apps

• Install Custom Software (ROMs)

• Install different Android Version

• Wi Fi tethering

• Overclocking

• Removing Fluff-ware

Page 51: Hacker Halted 2014 - Reverse Engineering the Android OS

Some Rooting Techniques

• Depends on the device

• OneClickRoot

• SuperOneClick

• z4Root

• GingerBreak

• UnlockRoot

Page 52: Hacker Halted 2014 - Reverse Engineering the Android OS

The SDK

• Windows and Linux

• SDk & Eclipse

• Virtual Devices (emulators)

• Allows interaction with virtual and real devices

– Browse files

– Create, install, extract apps

– Get shells

– SSH & VNC

Page 53: Hacker Halted 2014 - Reverse Engineering the Android OS

SDK continued

• Eclipse

• ADT – Android Developer Tools

– Signing

– Debugging

– Important for developer & tester

– Use Android SDK Tools

• IDE – integrated Development Environment

Page 54: Hacker Halted 2014 - Reverse Engineering the Android OS

Package Explorer

Page 55: Hacker Halted 2014 - Reverse Engineering the Android OS

Package ExplorerMiddle pane

• Source code

• Activity’s UI

Page 56: Hacker Halted 2014 - Reverse Engineering the Android OS

Right Pane (Outline)

• Methods

• Functions

• Arguments

• Variables

• Properties

Page 57: Hacker Halted 2014 - Reverse Engineering the Android OS

Perspectives

• Java – DDMS – Debug (Dalvik Debug Monitor Server)

Page 58: Hacker Halted 2014 - Reverse Engineering the Android OS

AVD Manager

• Allows emulation of devices

• Custom hardware

• Custom software

• Runs from SDK executables

Page 59: Hacker Halted 2014 - Reverse Engineering the Android OS

Android Virtual Device

Page 60: Hacker Halted 2014 - Reverse Engineering the Android OS

Device definition

• Create

• Clone – Edit – Delete

• New custom devices

Page 61: Hacker Halted 2014 - Reverse Engineering the Android OS

What we can do with a Virtual Device

• Send and receive text between devices

• make calls

• interact with the touch screen if you have one on your host

• browse file

• threads

Page 62: Hacker Halted 2014 - Reverse Engineering the Android OS

Commands Available

• the VM can be run from the command line

• Command - adb devices

• adb connect <device name>

• note the number reference the port used

Page 63: Hacker Halted 2014 - Reverse Engineering the Android OS

USB devices are different

Page 64: Hacker Halted 2014 - Reverse Engineering the Android OS

Shell interaction is via the –s option

Page 65: Hacker Halted 2014 - Reverse Engineering the Android OS

Shell commands

• allows browsing

• read and write files & folders

• change permissions

• get network statistics

Page 66: Hacker Halted 2014 - Reverse Engineering the Android OS

basic linux commands

• ls

• ps

• netstat

• top

Page 67: Hacker Halted 2014 - Reverse Engineering the Android OS

More Commands• list all the packages

• pm list packages –f

Page 68: Hacker Halted 2014 - Reverse Engineering the Android OS

sqlite3• access databases *.db

• query statements

• show a browsed database from /data/Datacom.android.providers.telephony/databases

Page 69: Hacker Halted 2014 - Reverse Engineering the Android OS

Browse SMS Folder

Page 70: Hacker Halted 2014 - Reverse Engineering the Android OS

Database containing SMSs

Page 71: Hacker Halted 2014 - Reverse Engineering the Android OS

Sqlite3 mnsms.db

Page 72: Hacker Halted 2014 - Reverse Engineering the Android OS

sqlite .tables

Page 73: Hacker Halted 2014 - Reverse Engineering the Android OS

select * sms

Page 74: Hacker Halted 2014 - Reverse Engineering the Android OS

Adb pull - Adb push

• adb pull <device_path> <local_path>

• adb push <device_path> <local_path>

Page 75: Hacker Halted 2014 - Reverse Engineering the Android OS

Pull ExampleBrowser Files

Page 76: Hacker Halted 2014 - Reverse Engineering the Android OS

Push Example

Changed “enable_javascript” to true

Page 77: Hacker Halted 2014 - Reverse Engineering the Android OS

Device Settings Changed

Page 78: Hacker Halted 2014 - Reverse Engineering the Android OS

Sqlite.exe in sdk/tools

Page 79: Hacker Halted 2014 - Reverse Engineering the Android OS

Sqlite store credentials

Because the Web Browser had the “Remember Password” option enabled we can view it in the “webview.db” file

Page 80: Hacker Halted 2014 - Reverse Engineering the Android OS

DDMS ViewDalvik Debug Monitor Server

Browse all Devices and Contents by using the “File Explorer” Tab

Page 81: Hacker Halted 2014 - Reverse Engineering the Android OS

More Powerfull Shell

Page 82: Hacker Halted 2014 - Reverse Engineering the Android OS

SSH Client

Page 83: Hacker Halted 2014 - Reverse Engineering the Android OS

SSH Server

Page 84: Hacker Halted 2014 - Reverse Engineering the Android OS

Putty as Client

Page 85: Hacker Halted 2014 - Reverse Engineering the Android OS

putty shell via ssh over wifi

Page 86: Hacker Halted 2014 - Reverse Engineering the Android OS

Droid VNC

Page 87: Hacker Halted 2014 - Reverse Engineering the Android OS

Analysis Types

Page 88: Hacker Halted 2014 - Reverse Engineering the Android OS

APK = ZIP

Page 89: Hacker Halted 2014 - Reverse Engineering the Android OS

Decompiling & Disassembling

Page 90: Hacker Halted 2014 - Reverse Engineering the Android OS

Elements in apk

Page 91: Hacker Halted 2014 - Reverse Engineering the Android OS

SourceAndroidManifest.xml

Page 92: Hacker Halted 2014 - Reverse Engineering the Android OS

Dex filesdexdump –d path_to_file.dex

Page 93: Hacker Halted 2014 - Reverse Engineering the Android OS
Page 94: Hacker Halted 2014 - Reverse Engineering the Android OS

apktoolapktool d name.apk path_to_file

Page 95: Hacker Halted 2014 - Reverse Engineering the Android OS

Smali / bacsmali

• Developed by Jesus Freke

• Assembler/ disassembler for dex files

Page 96: Hacker Halted 2014 - Reverse Engineering the Android OS

smali Folder

Page 97: Hacker Halted 2014 - Reverse Engineering the Android OS

classes.dex vs .smali

Page 98: Hacker Halted 2014 - Reverse Engineering the Android OS

ApktoolAndroidManifest.xml

Page 99: Hacker Halted 2014 - Reverse Engineering the Android OS

Folders & Uses

src – source• Packages• MainActivity.java

assets• Fonts, audio, images, text files• Non-android xml files

Page 100: Hacker Halted 2014 - Reverse Engineering the Android OS

Folders & Uses

bin – same as Linuxlibs - same as Linuxres - resources• drawables – images for layouts• layout –user interface *• values – string.xml – styles.xml – dimens.xml - colors

Page 101: Hacker Halted 2014 - Reverse Engineering the Android OS

layout/Folder

Activity_Main.xml<TextView

android:layout_width=“wrap_content”android:layout_height=“wrap_content”android:text=“@string/”hello world”

Page 102: Hacker Halted 2014 - Reverse Engineering the Android OS

values\Folder

Strings.xml<resourses><string name=“Hello world”> Hello world </string>

Page 103: Hacker Halted 2014 - Reverse Engineering the Android OS

dex2jar

Page 104: Hacker Halted 2014 - Reverse Engineering the Android OS

Decompiles dex into java

Page 105: Hacker Halted 2014 - Reverse Engineering the Android OS

JD-GUI

Page 106: Hacker Halted 2014 - Reverse Engineering the Android OS

XDAAutoTool

Page 107: Hacker Halted 2014 - Reverse Engineering the Android OS

XDAAutoTool Options

Page 108: Hacker Halted 2014 - Reverse Engineering the Android OS

Bypassing Security Controls

Page 109: Hacker Halted 2014 - Reverse Engineering the Android OS

Code example

Page 110: Hacker Halted 2014 - Reverse Engineering the Android OS

for - if - else

Page 111: Hacker Halted 2014 - Reverse Engineering the Android OS

passwordafter 5 iterations

Page 112: Hacker Halted 2014 - Reverse Engineering the Android OS

Quick Way

Page 113: Hacker Halted 2014 - Reverse Engineering the Android OS

Tom [email protected]