Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify...

45
PROGRAMMING AND HACKING ANDROID Fabrizio Cornelli HT

Transcript of Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify...

Page 1: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

PROGRAMMING AND HACKING ANDROID

Fabrizio CornelliHT

Page 3: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

CV

Filibusta LUG

Laurea a Crema, nel 2012

CTO, Enterprise srl

QA Manager, HT

Page 4: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

FIRST RULE OF HT

YOU DO NO TALK ABOUT HT

Page 5: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Fighting crime since 2001

Internet is wrong

Page 6: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Summary

Being a Developer

Being a Hacker

Android Architecture Overview

How to write an APT on Android

Page 7: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

DEVELOPER“If it ain’t broke, don’t fix it”

Page 8: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Software engineer

Constructive

Programming skills

Good Practices

Design then code (and test)

RTFM

Frameworks and Libraries

Don’t be the first

High level languages

Page 9: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Software Engineering Proverbs

The ends does not justify the mean

Choose two: good, fast, cheap

Any fool can write code that a computer can understand. Good programmers write code that humans can understand. [M. Fowler]

Page 10: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

HACKER“shit happens”

Page 11: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Hacker

Deconstructive

Reverse Engineer

Lateral Thinking

Lazy

Subvert the manual

Shortcut

Must be the first

Low level languages (C, asm)

Page 12: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Hacking Proverbs

the ends justify the means

a clever person solves a problem, a wise person avoids it.

Page 13: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Shared values

Discipline / Focus

Imagination

Page 14: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Farmer vs Hunter hypotesis

• farmer

• permanent settlements

• tradition

• patience

• collaboration

• hunter

• autonomy

• innovation

• initiative

• indipendence

Page 15: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Programming

Be a hacker: get your POC

Be a developer: evolve an idea to a product

Page 16: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

ANDROID

Page 17: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can
Page 18: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can
Page 19: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Boot

• firmware

• kernel

• drivers

• fs

• user space (init)

• dalvik /ART

• daemons

• GC

Page 20: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can
Page 21: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

APK

classes.dex : Code

Manifest

Resources / Assets /Licence

Libs

Signature

Page 22: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Dalvik

Process VM

register based

Java -> bytecode

APK

.dex -> .odex

JIT

Page 23: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Android Runtime (ART)

.dex -> elf

AOT Compilation

Page 24: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

ANDROID DEVELOPMENT

Page 25: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Android Studio

IntelliJ Platform

IDE

gradle / ant

adb

emulator

Page 26: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

ADB

Android Debug Bridge

Device in Debug Mode

subcommands:

shell

pull

push

install

kill-server

reboot

Page 27: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

REVERSING

Page 28: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Tools

Decompilers

jd-gui

dad

jeb

Apk dissectors

androguard

apktool

Reversing Frameworks

IDA

Radare

Network analyzer

Wireshark / tcpdump

burp

Page 29: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

apktool

decode apk

build apk

internal use of smali/baksmali

needs jarsigner

Page 30: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

smali

.method public static main([Ljava/lang/String;)V .registers 2

sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;

const-string v1, "Hello World!"

invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V

return-void .end method

Page 31: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

learn from malware

http://contagiominidump.blogspot.it/

Virus Total

Androguard DatabaseAndroidMalwares

Page 32: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

APT CONCEPTSAdvanced Persistence Threats

Page 33: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Life cycle

Configuration

Build

Installation

Execution

Persistence

Data Exfiltration

Uninstall

Page 34: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

HACKING ANDROID

Page 35: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Get the privileges

Flash the OS

Use a local to root exploit

Use a system exploit

Page 36: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Starting at the boot

Use the Manifest

Use the OS (root)

Page 37: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Get data

Use Android API

Use OS libraries

Get data reading memory (root)

Get data reading files (root)

Page 38: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Communication

Covered link

Use Android API

Page 39: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

ENGINEER A PRODUCT

Page 40: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Agile programming

Page 41: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Protect from hackers

anti reversing tricks

polymorphic tools

encryption and obfuscation

anti virtualisation tricks

packing

virtualize

Page 42: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Maintain the code

Versioning

Continuous integration

Testing and code coverage

Acceptance tests

Automatic tests

Page 43: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

Make a product

Customer support

Release policies

Marketing

Page 44: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

LINKS

Page 45: Programming and Hacking Android and... · Software Engineering Proverbs The ends does not justify the mean Choose two: good, fast, cheap Any fool can write code that a computer can

NOW HIRING