45
PROGRAMMING AND HACKING ANDROID Fabrizio Cornelli HT

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

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

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

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

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

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

• 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Get the root

• 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

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

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

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

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

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

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

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

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

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

NOW HIRING