SlideShare ist ein Scribd-Unternehmen logo
1 von 72
Downloaden Sie, um offline zu lesen
Yonatan V.Levin
levin.yonatan parahall
Google Developer Expert
CTO & Co Founder
>100 Cities > 30M usersRuby, Go, Python, Microservices
Ooooops...
What Do We Do?
● Android Fundamentals
● Android UI / UX
● Community Hackathon
● Android Advanced
● Mentors Program
● Active community
facebook.com/groups/android.academy.ils/
22.10
Fundamentals
Bang! Bang! You have been hacked.
private boolean isMocLocationsOn() {
return Settings.Secure.getString(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION)
.equals(ALLOW_MOC_LOCATIONS_ON);
}
public class TimeChangedReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
onSystemTimeChanged();
}
}
urlSigner.getUrlSignature(encodedPath, mAuthenticationToken);
Network request signing
First sign
public class NetworkHttpUnauthorizedReceiver extends BroadcastReceiver
{
public void onReceive(Context context, Intent intent) {
int httpCode = intent.getIntExtra(IntentExtras.HTTP_CODE, -1);
if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
LoginActivity.logOut(context);
}
}
}
Anyone can send “unauthorized”
Possible way to solve it
- Exported = ‘false’ in AndroidManifest.xml
- Custom permissions with
protectionLevel=”signature”
- Dynamic register with LocalBroadcastManager
We lost the battle but not the war
How he did it
Static Analysis
• APKTool, Smali/Baksmali, BytecodeViewer, JEB ($), IDA Pro ($$) …
Network Analysis
• mitmproxy, charles, burpsuite, wireshark
Security is hard.
If it’s not - it’s easy to break
Disclaimer: I’m not security expert.
It’s our journey, and I decided to share it.
It’s a team work
Very easy to reverse-engineer
https://github.com/google/android-classyshark
The first goal:
Protect our code
Code Protection
● Name obfuscation
● String encryption
● Class encryption
● Resources, asset and native library encryption Control flow and
arithmetic obfuscation
● Hide calls through reflection
public String encryptSensitiveMessage() {
String nuclearLaunchCode = "abc123";
String encryptionKey = "secretkey";
return CryptoEngine.encrypt(nuclearLaunchCode, encryptionKey);
}
Example
public String encryptSensitiveMessage() {
String nuclearLaunchCode = "abc123";
String encryptionKey = "secretkey";
Class clazz = Class.forName("CryptoEngine");
Method meth = clazz.getMethod("encrypt", String.class, String.class);
return (String) meth.invoke(null, nuclearLaunchCode, encryptionKey);
}
Reflection
public String encryptSensitiveMessage() {
String nuclearLaunchCode = Base64.decode("YWJjMTIz");
String encryptionKey = Base64.decode("c2VjcmV0a2V5");
Class clazz = Class.forName(Base64.decode("Q3J5cHRvRW5naW5l"));
Method meth = clazz.getMethod(Base64.decode("ZW5jcnlwdA=="), String.class,
String.class);
return (String) meth.invoke(null, nuclearLaunchCode, encryptionKey);
}
String obfuscation
public String a() {
String a = e.f("YWJjMTIz");
String b = e.f("c2VjcmV0a2V5");
Class c = Class.forName(e.f("Q3J5cHRvRW5naW5l"));
Method d = c.getMethod(e.f("ZW5jcnlwdA=="), String.class, String.class);
return (String) d.invoke(null, a, b);
}
Name obfuscation
Automate it:
Proguard
Proguard
release {
minifyEnabled true
shrinkResources true
proguardFile 'proguard-project.pro'
proguardFile 'proguard-crashlytics.pro'
proguardFile 'proguard-gson.pro'
proguardFile 'proguard-okhttp.pro'
proguardFile 'proguard-mixpanel.pro'
proguardFile 'proguard-retrofit.pro'
proguardFile 'proguard-pubnub.pro'
proguardFile 'proguard-logback-android.pro'
proguardFile getDefaultProguardFile('proguard-android.txt')
debuggable false
signingConfig signingConfigs.release
}
-repackageclasses
-allowaccessmodification
-flattenpackagehierarchy
Proguard obfuscation
GSON makes you weak :)
"Order": {
"id": 89684,
"status": "expired",
"payment_type": "cash",
"future_ride": false,
"passenger_comment": "",
"scheduled_at": "2015-12-13T15:13:48+02:00",
"account_ride": false,
"ride_type": "private",
"price_origin": "driver",
"autopay": false...
public class A {
private int b;
private AB c;
private TM d;
private boolean e;
private S f;
private D j;
private D g;
private D k;
private boolean l;
private double m;
private boolean n;
Second goal:
Hide model in network layer
Protocol Buffers
(Wire)
message Person {
// The customer's full name.
required string name = 1;
// The customer's ID number.
required int32 id = 2;
// Email address for the customer.
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
// The user's phone number.
required string number = 1;
// The type of phone stored here.
optional PhoneType type = 2 [default = HOME];
}
// A list of the user's phone numbers.
repeated PhoneNumber phone = 4;
}
public final class Person extends Message {
/** The customer's full name. */
@ProtoField(tag = 1, type = STRING, label = REQUIRED)
public final String name;
/** The customer's ID number. */
@ProtoField(tag = 2, type = INT32, label = REQUIRED)
public final Integer id;
/** Email address for the customer. */
@ProtoField(tag = 3, type = STRING)
public final String email;
/** A list of the user's phone numbers. */
@ProtoField(tag = 4, label = REPEATED)
public final List<PhoneNumber> phone;
byte[] data = person.toByteArray();
Wire wire = new Wire();
Person newPerson = wire.parseFrom(data, Person.class);
Our Network exposing our models
* Ask server guys to have a flag - JSON/ProtoBuff format.
Will make your life easy to debug
Retrofit StarWarsServiceRetrofit = new
Retrofit.Builder().baseUrl(baseUrl)
.client(clientBuilder.build())
.addConverterFactory(WireConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
Third goal:
Challenge the code stripping.
APK Signature check
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String currentSignature = Base64.encodeToString(md.digest(), Base64.DEFAULT);
//compare signatures
if (EXPECTED_SIGNATURE.equals(currentSignature)) {
return VALID;
}
return INVALID;
Challenge
Connect the code ,key and API.
Goal: every single change in code will generate different key and this
key will be used to sign API request.
Dex
- Custom Class Loading in Dalvik
DexClassLoader cl = new
DexClassLoader(dexInternalStoragePath.getAbsolutePath(),
optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader());
Class libProviderClazz = null;
try {
// Load the library.
libProviderClazz = cl.loadClass("com.example.dex.lib.LibraryProvider");
LibraryInterface lib = (LibraryInterface) libProviderClazz.newInstance();
lib.showAwesomeToast(this, "hello");
} catch (Exception e) {...}
Reflection
Ask application with API - Who are you?
Generate challenge for each user randomly.Load it from server.
What can be challenged?
Resource IDs,
Class fields,
Classes
Method results
NDK possible to reverse-engineer too but really really hard!
https://www.hex-rays.com/products/decompiler/
JNI
- Use bytecode libs
With Help from Google
App Licensing
Google Library to query Google Play
Services if Application was installed from
the play store.
In order to download your expansion files
from Google Play, the user must have
acquired your application from Google
Play.
Combination - Part 1 Authorization
Answer to challenge
Obtain random
challenge for
current session
Application Side
Server Side
Download the
challenge
Using
Reflection
answer
challenge Send as
bytecode data
using
flatbuffer/wire
Compare
&
decide
Combination - Every request
Build
.apk
Extract MD5
from .apk
Store MD5 on server +
hash function (RSA,
AES)
Run-Time
Building Release
Load dex library.
Obtain MD5 from
dex/.so lib
Sign URL with MD5,
Token, TimeStamp and
challenge response Send data using
flatbuffer/wire
Compare url
signature
Compare
signature
and decide
Build
.apk
Extract MD5
from .apk
Store MD5 on
server per built
version
Run-Time
Building Release
Load dex library with
challenge.
Obtain MD5 from
dex/.so lib
Sign API Request with
MD5, Token,
TimeStamp and
challenge response
Answer to challenge
Obtain random
challenge for
current session
Server Side
Generate signature
based on stored MD5,
Challenge Answer,
TimeStamp & Token
Send data using
flatbuffer/wire
Yonatan V.Levin levin.yonatan
parahallGoogle Developer Expert

Weitere ähnliche Inhalte

Was ist angesagt?

Sustaining Test-Driven Development
Sustaining Test-Driven DevelopmentSustaining Test-Driven Development
Sustaining Test-Driven Development
AgileOnTheBeach
 
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트
기룡 남
 
Building Your First Data Science Applicatino in MongoDB
Building Your First Data Science Applicatino in MongoDBBuilding Your First Data Science Applicatino in MongoDB
Building Your First Data Science Applicatino in MongoDB
MongoDB
 
Tugas Praktikum Java 2
Tugas Praktikum Java 2Tugas Praktikum Java 2
Tugas Praktikum Java 2
azmi007
 

Was ist angesagt? (20)

드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
드로이드 나이츠 2018: RxJava 적용 팁 및 트러블 슈팅
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
The Ring programming language version 1.5.4 book - Part 70 of 185
The Ring programming language version 1.5.4 book - Part 70 of 185The Ring programming language version 1.5.4 book - Part 70 of 185
The Ring programming language version 1.5.4 book - Part 70 of 185
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
4Developers 2018: Evolution of C++ Class Design (Mariusz Łapiński)
 
Sustaining Test-Driven Development
Sustaining Test-Driven DevelopmentSustaining Test-Driven Development
Sustaining Test-Driven Development
 
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash courseCodepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
Codepot - Pig i Hive: szybkie wprowadzenie / Pig and Hive crash course
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
 
Testing with Node.js
Testing with Node.jsTesting with Node.js
Testing with Node.js
 
Refactoring for testability c++
Refactoring for testability c++Refactoring for testability c++
Refactoring for testability c++
 
생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트생산적인 개발을 위한 지속적인 테스트
생산적인 개발을 위한 지속적인 테스트
 
Building Your First Data Science Applicatino in MongoDB
Building Your First Data Science Applicatino in MongoDBBuilding Your First Data Science Applicatino in MongoDB
Building Your First Data Science Applicatino in MongoDB
 
LISA QooxdooTutorial Slides
LISA QooxdooTutorial SlidesLISA QooxdooTutorial Slides
LISA QooxdooTutorial Slides
 
Spock and Geb in Action
Spock and Geb in ActionSpock and Geb in Action
Spock and Geb in Action
 
Работа с реляционными базами данных в C++
Работа с реляционными базами данных в C++Работа с реляционными базами данных в C++
Работа с реляционными базами данных в C++
 
groovy & grails - lecture 7
groovy & grails - lecture 7groovy & grails - lecture 7
groovy & grails - lecture 7
 
Tugas Praktikum Java 2
Tugas Praktikum Java 2Tugas Praktikum Java 2
Tugas Praktikum Java 2
 
The Ring programming language version 1.2 book - Part 79 of 84
The Ring programming language version 1.2 book - Part 79 of 84The Ring programming language version 1.2 book - Part 79 of 84
The Ring programming language version 1.2 book - Part 79 of 84
 
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180
 

Ähnlich wie Bang-Bang, you have been hacked - Yonatan Levin, KolGene

Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
Yekmer Simsek
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
Droidcon Berlin
 

Ähnlich wie Bang-Bang, you have been hacked - Yonatan Levin, KolGene (20)

Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Phone gap 12 things you should know
Phone gap 12 things you should knowPhone gap 12 things you should know
Phone gap 12 things you should know
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Thomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-finalThomas braun dependency-injection_with_robo_guice-presentation-final
Thomas braun dependency-injection_with_robo_guice-presentation-final
 
Taking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the ExtremeTaking Jenkins Pipeline to the Extreme
Taking Jenkins Pipeline to the Extreme
 
Zone.js 2017
Zone.js 2017Zone.js 2017
Zone.js 2017
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
July 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKIJuly 2015 Android Taipei - Anti-Decompiler by SUKI
July 2015 Android Taipei - Anti-Decompiler by SUKI
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in Grails
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in Grails
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Native Java with GraalVM
Native Java with GraalVMNative Java with GraalVM
Native Java with GraalVM
 
Fun Teaching MongoDB New Tricks
Fun Teaching MongoDB New TricksFun Teaching MongoDB New Tricks
Fun Teaching MongoDB New Tricks
 
Android Bootstrap
Android BootstrapAndroid Bootstrap
Android Bootstrap
 
Retrofit
RetrofitRetrofit
Retrofit
 
HBaseCon 2013: A Developer’s Guide to Coprocessors
HBaseCon 2013: A Developer’s Guide to CoprocessorsHBaseCon 2013: A Developer’s Guide to Coprocessors
HBaseCon 2013: A Developer’s Guide to Coprocessors
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
 

Mehr von DroidConTLV

Mehr von DroidConTLV (20)

Mobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, NikeMobile Development in the Information Age - Yossi Elkrief, Nike
Mobile Development in the Information Age - Yossi Elkrief, Nike
 
Doing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra TechnologiesDoing work in the background - Darryn Campbell, Zebra Technologies
Doing work in the background - Darryn Campbell, Zebra Technologies
 
No more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola SolutionsNo more video loss - Alex Rivkin, Motorola Solutions
No more video loss - Alex Rivkin, Motorola Solutions
 
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.comMobile at Scale: from startup to a big company - Dor Samet, Booking.com
Mobile at Scale: from startup to a big company - Dor Samet, Booking.com
 
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, ClimacellLiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
LiveData on Steroids - Giora Shevach + Shahar Ben Moshe, Climacell
 
MVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, LightricksMVVM In real life - Lea Cohen Tannoudji, Lightricks
MVVM In real life - Lea Cohen Tannoudji, Lightricks
 
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
Best Practices for Using Mobile SDKs - Lilach Wagner, SafeDK (AppLovin)
 
Building Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice NinjaBuilding Apps with Flutter - Hillel Coren, Invoice Ninja
Building Apps with Flutter - Hillel Coren, Invoice Ninja
 
New Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy ZukanovNew Android Project: The Most Important Decisions - Vasiliy Zukanov
New Android Project: The Most Important Decisions - Vasiliy Zukanov
 
Designing a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, GettDesigning a Design System - Shai Mishali, Gett
Designing a Design System - Shai Mishali, Gett
 
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, PepperThe Mighty Power of the Accessibility Service - Guy Griv, Pepper
The Mighty Power of the Accessibility Service - Guy Griv, Pepper
 
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDevKotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
Kotlin Multiplatform in Action - Alexandr Pogrebnyak - IceRockDev
 
Flutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, TikalFlutter State Management - Moti Bartov, Tikal
Flutter State Management - Moti Bartov, Tikal
 
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bisReactive UI in android - Gil Goldzweig Goldbaum, 10bis
Reactive UI in android - Gil Goldzweig Goldbaum, 10bis
 
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevelFun with flutter animations - Divyanshu Bhargava, GoHighLevel
Fun with flutter animations - Divyanshu Bhargava, GoHighLevel
 
DroidconTLV 2019
DroidconTLV 2019DroidconTLV 2019
DroidconTLV 2019
 
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, MondayOk google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
Ok google, it's time to bot! - Hadar Franco, Albert + Stav Levi, Monday
 
Introduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, WixIntroduction to React Native - Lev Vidrak, Wix
Introduction to React Native - Lev Vidrak, Wix
 
Educating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz TamirEducating your app – adding ML edge to your apps - Maoz Tamir
Educating your app – adding ML edge to your apps - Maoz Tamir
 
Constraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, GoogleConstraint-ly motion - making your app dance - John Hoford, Google
Constraint-ly motion - making your app dance - John Hoford, Google
 

Kürzlich hochgeladen

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 

Kürzlich hochgeladen (20)

Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 

Bang-Bang, you have been hacked - Yonatan Levin, KolGene

  • 1. Yonatan V.Levin levin.yonatan parahall Google Developer Expert CTO & Co Founder
  • 2. >100 Cities > 30M usersRuby, Go, Python, Microservices Ooooops...
  • 3.
  • 4. What Do We Do? ● Android Fundamentals ● Android UI / UX ● Community Hackathon ● Android Advanced ● Mentors Program ● Active community
  • 7. Bang! Bang! You have been hacked.
  • 8.
  • 9.
  • 10.
  • 11. private boolean isMocLocationsOn() { return Settings.Secure.getString(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION) .equals(ALLOW_MOC_LOCATIONS_ON); }
  • 12. public class TimeChangedReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { onSystemTimeChanged(); } }
  • 14.
  • 15.
  • 17. public class NetworkHttpUnauthorizedReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { int httpCode = intent.getIntExtra(IntentExtras.HTTP_CODE, -1); if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) { LoginActivity.logOut(context); } } } Anyone can send “unauthorized”
  • 18. Possible way to solve it - Exported = ‘false’ in AndroidManifest.xml - Custom permissions with protectionLevel=”signature” - Dynamic register with LocalBroadcastManager
  • 19.
  • 20.
  • 21.
  • 22.
  • 23. We lost the battle but not the war
  • 24. How he did it Static Analysis • APKTool, Smali/Baksmali, BytecodeViewer, JEB ($), IDA Pro ($$) … Network Analysis • mitmproxy, charles, burpsuite, wireshark
  • 25. Security is hard. If it’s not - it’s easy to break
  • 26. Disclaimer: I’m not security expert. It’s our journey, and I decided to share it.
  • 28. Very easy to reverse-engineer https://github.com/google/android-classyshark
  • 30. Code Protection ● Name obfuscation ● String encryption ● Class encryption ● Resources, asset and native library encryption Control flow and arithmetic obfuscation ● Hide calls through reflection
  • 31. public String encryptSensitiveMessage() { String nuclearLaunchCode = "abc123"; String encryptionKey = "secretkey"; return CryptoEngine.encrypt(nuclearLaunchCode, encryptionKey); } Example
  • 32. public String encryptSensitiveMessage() { String nuclearLaunchCode = "abc123"; String encryptionKey = "secretkey"; Class clazz = Class.forName("CryptoEngine"); Method meth = clazz.getMethod("encrypt", String.class, String.class); return (String) meth.invoke(null, nuclearLaunchCode, encryptionKey); } Reflection
  • 33. public String encryptSensitiveMessage() { String nuclearLaunchCode = Base64.decode("YWJjMTIz"); String encryptionKey = Base64.decode("c2VjcmV0a2V5"); Class clazz = Class.forName(Base64.decode("Q3J5cHRvRW5naW5l")); Method meth = clazz.getMethod(Base64.decode("ZW5jcnlwdA=="), String.class, String.class); return (String) meth.invoke(null, nuclearLaunchCode, encryptionKey); } String obfuscation
  • 34. public String a() { String a = e.f("YWJjMTIz"); String b = e.f("c2VjcmV0a2V5"); Class c = Class.forName(e.f("Q3J5cHRvRW5naW5l")); Method d = c.getMethod(e.f("ZW5jcnlwdA=="), String.class, String.class); return (String) d.invoke(null, a, b); } Name obfuscation
  • 36.
  • 37. Proguard release { minifyEnabled true shrinkResources true proguardFile 'proguard-project.pro' proguardFile 'proguard-crashlytics.pro' proguardFile 'proguard-gson.pro' proguardFile 'proguard-okhttp.pro' proguardFile 'proguard-mixpanel.pro' proguardFile 'proguard-retrofit.pro' proguardFile 'proguard-pubnub.pro' proguardFile 'proguard-logback-android.pro' proguardFile getDefaultProguardFile('proguard-android.txt') debuggable false signingConfig signingConfigs.release }
  • 39.
  • 40. GSON makes you weak :)
  • 41. "Order": { "id": 89684, "status": "expired", "payment_type": "cash", "future_ride": false, "passenger_comment": "", "scheduled_at": "2015-12-13T15:13:48+02:00", "account_ride": false, "ride_type": "private", "price_origin": "driver", "autopay": false... public class A { private int b; private AB c; private TM d; private boolean e; private S f; private D j; private D g; private D k; private boolean l; private double m; private boolean n;
  • 42. Second goal: Hide model in network layer
  • 43.
  • 44.
  • 46. message Person { // The customer's full name. required string name = 1; // The customer's ID number. required int32 id = 2; // Email address for the customer. optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { // The user's phone number. required string number = 1; // The type of phone stored here. optional PhoneType type = 2 [default = HOME]; } // A list of the user's phone numbers. repeated PhoneNumber phone = 4; }
  • 47. public final class Person extends Message { /** The customer's full name. */ @ProtoField(tag = 1, type = STRING, label = REQUIRED) public final String name; /** The customer's ID number. */ @ProtoField(tag = 2, type = INT32, label = REQUIRED) public final Integer id; /** Email address for the customer. */ @ProtoField(tag = 3, type = STRING) public final String email; /** A list of the user's phone numbers. */ @ProtoField(tag = 4, label = REPEATED) public final List<PhoneNumber> phone;
  • 48. byte[] data = person.toByteArray(); Wire wire = new Wire(); Person newPerson = wire.parseFrom(data, Person.class);
  • 49.
  • 50. Our Network exposing our models
  • 51. * Ask server guys to have a flag - JSON/ProtoBuff format. Will make your life easy to debug
  • 52. Retrofit StarWarsServiceRetrofit = new Retrofit.Builder().baseUrl(baseUrl) .client(clientBuilder.build()) .addConverterFactory(WireConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build();
  • 53. Third goal: Challenge the code stripping.
  • 55. PackageInfo packageInfo = context.getPackageManager() .getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); for (Signature signature : packageInfo.signatures) { MessageDigest md = MessageDigest.getInstance("SHA"); md.update(signature.toByteArray()); String currentSignature = Base64.encodeToString(md.digest(), Base64.DEFAULT); //compare signatures if (EXPECTED_SIGNATURE.equals(currentSignature)) { return VALID; } return INVALID;
  • 56. Challenge Connect the code ,key and API. Goal: every single change in code will generate different key and this key will be used to sign API request.
  • 57. Dex - Custom Class Loading in Dalvik
  • 58. DexClassLoader cl = new DexClassLoader(dexInternalStoragePath.getAbsolutePath(), optimizedDexOutputPath.getAbsolutePath(), null, getClassLoader()); Class libProviderClazz = null; try { // Load the library. libProviderClazz = cl.loadClass("com.example.dex.lib.LibraryProvider"); LibraryInterface lib = (LibraryInterface) libProviderClazz.newInstance(); lib.showAwesomeToast(this, "hello"); } catch (Exception e) {...}
  • 59. Reflection Ask application with API - Who are you? Generate challenge for each user randomly.Load it from server. What can be challenged? Resource IDs, Class fields, Classes Method results
  • 60. NDK possible to reverse-engineer too but really really hard! https://www.hex-rays.com/products/decompiler/
  • 62. With Help from Google
  • 63. App Licensing Google Library to query Google Play Services if Application was installed from the play store.
  • 64.
  • 65. In order to download your expansion files from Google Play, the user must have acquired your application from Google Play.
  • 66. Combination - Part 1 Authorization Answer to challenge Obtain random challenge for current session Application Side Server Side Download the challenge Using Reflection answer challenge Send as bytecode data using flatbuffer/wire Compare & decide
  • 67. Combination - Every request Build .apk Extract MD5 from .apk Store MD5 on server + hash function (RSA, AES) Run-Time Building Release Load dex library. Obtain MD5 from dex/.so lib Sign URL with MD5, Token, TimeStamp and challenge response Send data using flatbuffer/wire Compare url signature
  • 68. Compare signature and decide Build .apk Extract MD5 from .apk Store MD5 on server per built version Run-Time Building Release Load dex library with challenge. Obtain MD5 from dex/.so lib Sign API Request with MD5, Token, TimeStamp and challenge response Answer to challenge Obtain random challenge for current session Server Side Generate signature based on stored MD5, Challenge Answer, TimeStamp & Token Send data using flatbuffer/wire
  • 69.
  • 70.
  • 71.