SlideShare a Scribd company logo
Abusing Android In-app Billing
feature thanks to a
misunderstood integration
JUGL
28/09/2017 – Jérémy MATOS
whois securingapps
Developer background
Worked last 10 years in Switzerland on security products and
solutions
Focus on mobile since 2010
OWASP Geneva member
Now freelance application security consultant
Consulting to build security in software
Mobile
Web
Cloud
Internet Of Things
Bitcoin/Blockchain @Securingapps
Agenda
1. Android In-app billing in a nutshell
2. Real-life exploitation in a rather popular game:
getting free credits
Java reverse engineering
Writing a Java hook with Xposed framework
Bytecode patching of application and redistribution
3. Lessons learned
4. Recommendations
1. Android In-app billing in a nutshell
Goal: show that Java reverse engineering can cause a loss of
value in real-life
Target: Android In-app billing feature
Allow developers to sell content in their app, e.g.
subscribtions to magazines
premium features
extra content in games
Payment is handled by Google
Requires Google Play services
No credit card data exposed to developers
Documentation available at
https://developer.android.com/google/play/billing/index.html
1. Android In-app billing in a nutshell
2. Real-life exploitation 1/n
(Used to be) rather popular game: PandaPop
In-app purchases to buy credits
New weapons
Extra lifes
Step 1: Download the APK archive: e.g. from apk-dl.com
Avoid executing this binary, or in an emulator
2. Real-life exploitation 2/n
Step 2: Prepare emulator
1. We will use Genymotion emulator
Fast (thanks to x86 image)
Rooting possible in 1 click
Free version available
2. Install Google Play Services in Genymotion device
Drag/drop ARM translation zip + restart
Drag/drop gapps-lp-<verions>.zip
Google Play errors are normal
Wait for the various updates to take place
At one point, provide a valid gmail account
2. Real-life exploitation 3/n
Step 3: use jadx free tool to convert automatically
an APK in readable Java source code
1. converts Dalvik bytecode to Java bytecode
2. decompiles Java bytecode in Java source code
3. displays the results in an IDE for analysis
Step 4: Look for instances of IInAppBillingService
This interface cannot be renamed
Nothing is obfuscated!
2. Real-life exploitation 4/n
Step 5: Easily review related implementation classes
Fascinating code in method purchaseProduct of class
com.prime31.GoogleIABPlugin
Step 6: Find out what android.test.purchased means
Google is our friend
https://developer.android.com/google/play/billing/billing_testing.html
2. Real-life exploitation 5/n
Step 7: force value to android.test.purchased and
see what happens
Let’s write a hook that forces sku of purchaseProduct
to this value
Using Xposed framework
Overload the behavior of an application by intercepting calls in the
Dalvik virtual machine
No change to the original apk file
Implement a hook with Android Studio in an independent apk
2. Real-life exploitation 6/n
Prerequisites
Rooted device to installed the Xposed libraries
Emulator (to avoid smartphone bricking…)
Install hooking framework in Genymotion device
Install terminal application
Drag/drop terminal.apk
Start it and type su
Check that root access is prompted and validate you are really root on the device
Drag/drop XposedInstaller_3.1.apk
Start it and choose install
Reboot the Genymotion device
2. Real-life exploitation 7/n
2. Real-life exploitation 8/n
Step 8: Deploy hook
Build hook apk with Android Studio
Copy it to Genymotion device
Activate hook in Xposed configuration panel
Reboot Genymotion device
Enjoy free credits
Step 9: Bytecode patching
Hook requires a rooted smartphone
We want to update the original apk to be able to deploy it on any device
2. Real-life exploitation 9/n
Android doesn’t use Java bytecode but Smali
classes.dex contains the Java classes converted to Smali bytecode
Smali bytecode can be transformed back and forth to human readble
instructions
Principle
Get readable smali of original class
Get readable smali of hook
Manual merge hook in original class
Rebuild the APK with the new smali code (including signature)
2. Real-life exploitation 10/n
Convert APK to readable smali with command
java -jar apktool.jar d your.apk
Edit manually smali code in your/smali
Recompiling with apktool loses native library, instead
cp your.apk yourPatched.apk
java -jar smali_2.1.1.jar your/smali -o classes.dex
(to compile smali code)
zip yourPatched.apk classes.dex
zip --delete yourPatched.apk "META-INF/*"
(to delete the existing signature)
2. Real-life exploitation 11/n
2. Real-life exploitation 12/n
Sign the APK with the key of your choice !
Generate a new signing key with
keytool -genkey -v -keystore patch.keystore -alias patch -keyalg RSA -
keysize 2048 -validity 10000
Enter whatever your want in password and certificate info
Sign APK with jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -
keystore patch.keystore yourPatched.apk patch
Ensure signature is OK jarsigner -verify -verbose -certs yourPatched.apk
Deploy to a non rooted device and play ;)
We could even publish in the Play Store under a new name !
3. Lessons learned 1/2
Never let debug code in production app
An access control decision client side is insecure by design
Google documentation is misleading: cf
https://developer.android.com/google/play/billing/billing_best_
practices.html
3. Lessons learned 2/2
in-app billing can’t be used to buy credits
Designed to purchase original content that is not guessable
Otherwise always possible to modify the counter via hooking
or bytecode patching
Responsible disclosure
PandaPop team: /dev/null
Prime31: quick feedback « the vulnerability doesn't make any sense »
4. Recommendations
0. Use Proguard obfuscation to slow down a reverser
1. Use NDK to embed sensitive logic in C code
With JNI possible to call C librairies via the native keyword
Much more effort to reverse and patch binary code (e.g ARM)
2. Use a backend for validating purchases
Still possible to hook/patch the response of the server
3. Only sell « real » content
and not something easy to guess like a counter
e.g Angry Birds sell extra levels
and they also use NDK for calls to validation server
4. Recommendations
Conclusion
Android Java reverse engineering is really easy with jadx
You cannot trust the Java code running in your Android app
Modifying and resigning an APK is not difficult
Only server side code can be considered secure
Google recommendations for in-app purchases are
incomplete and misleading
By design most in-app uses cases are not possible to secure
Only secure use case: download impredictable content from server
Bonus
Possible to debug in Android Studio a reversed app
Jadx can export to an Android Studio project
Add android:debuggable=’’true’’ in AndroidManifest.xml
Resign app
Deploy and start debugging from Android Studio
Any question ? contact@securingapps.com

More Related Content

Similar to Reverse engineering Java et contournement du mécanisme de paiement inapp Android

Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
Christoffer Noring
 
Android Study Jam - Introduction
Android Study Jam - IntroductionAndroid Study Jam - Introduction
Android Study Jam - Introduction
HitanshDoshi
 
Appium solution artizone
Appium solution   artizoneAppium solution   artizone
Appium solution artizone
Nael Abd Eljawad
 
Android
Android Android
Android
Akhilesh Saini
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
Bogusz Jelinski
 
Codename one
Codename oneCodename one
Android - Getting started with Android
Android - Getting started with Android Android - Getting started with Android
Android - Getting started with Android
Vibrant Technologies & Computers
 
Who Needs Thumbs? Reverse Engineering Scramble With Friends
Who Needs Thumbs? Reverse Engineering Scramble With FriendsWho Needs Thumbs? Reverse Engineering Scramble With Friends
Who Needs Thumbs? Reverse Engineering Scramble With Friends
Apkudo
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
Pece Nikolovski
 
7 maven vsgradle
7 maven vsgradle7 maven vsgradle
7 maven vsgradle
Avitesh Kesharwani
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
Jim Jeffers
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
Pratik Patel
 
React native bridge for iOS and android
 React native bridge for iOS and android React native bridge for iOS and android
React native bridge for iOS and android
Katy Slemon
 
GSoC
GSoCGSoC
React Native: Is It Worth It? UA Mobile 2017.
React Native: Is It Worth It? UA Mobile 2017.React Native: Is It Worth It? UA Mobile 2017.
React Native: Is It Worth It? UA Mobile 2017.
UA Mobile
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
Ryan Stewart
 
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Sargis Sargsyan
 
VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...
VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...
VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...
Riddhi Shree
 
Inside Dvm basics
Inside Dvm basicsInside Dvm basics
Inside Dvm basics
Mykola Bova
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
Abraham Aranguren
 

Similar to Reverse engineering Java et contournement du mécanisme de paiement inapp Android (20)

Nativescript with angular 2
Nativescript with angular 2Nativescript with angular 2
Nativescript with angular 2
 
Android Study Jam - Introduction
Android Study Jam - IntroductionAndroid Study Jam - Introduction
Android Study Jam - Introduction
 
Appium solution artizone
Appium solution   artizoneAppium solution   artizone
Appium solution artizone
 
Android
Android Android
Android
 
Mobile development in 2020
Mobile development in 2020 Mobile development in 2020
Mobile development in 2020
 
Codename one
Codename oneCodename one
Codename one
 
Android - Getting started with Android
Android - Getting started with Android Android - Getting started with Android
Android - Getting started with Android
 
Who Needs Thumbs? Reverse Engineering Scramble With Friends
Who Needs Thumbs? Reverse Engineering Scramble With FriendsWho Needs Thumbs? Reverse Engineering Scramble With Friends
Who Needs Thumbs? Reverse Engineering Scramble With Friends
 
Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0Consuming Restful APIs using Swagger v2.0
Consuming Restful APIs using Swagger v2.0
 
7 maven vsgradle
7 maven vsgradle7 maven vsgradle
7 maven vsgradle
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Getting started with appium
Getting started with appiumGetting started with appium
Getting started with appium
 
React native bridge for iOS and android
 React native bridge for iOS and android React native bridge for iOS and android
React native bridge for iOS and android
 
GSoC
GSoCGSoC
GSoC
 
React Native: Is It Worth It? UA Mobile 2017.
React Native: Is It Worth It? UA Mobile 2017.React Native: Is It Worth It? UA Mobile 2017.
React Native: Is It Worth It? UA Mobile 2017.
 
Intro to PhoneGap
Intro to PhoneGapIntro to PhoneGap
Intro to PhoneGap
 
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
Appium Dockerization: from Scratch to Advanced Implementation - HUSTEF 2019
 
VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...
VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...
VyAPI - A Modern Cloud Based Vulnerable Android App (Presented at BSides Delh...
 
Inside Dvm basics
Inside Dvm basicsInside Dvm basics
Inside Dvm basics
 
Pwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreakPwning mobile apps without root or jailbreak
Pwning mobile apps without root or jailbreak
 

More from JUG Lausanne

Introduction aux algorithmes génétiques
Introduction aux algorithmes génétiquesIntroduction aux algorithmes génétiques
Introduction aux algorithmes génétiques
JUG Lausanne
 
Développer un moteur d'exécution symbolique en partant de rien
Développer un moteur d'exécution symbolique en partant de rienDévelopper un moteur d'exécution symbolique en partant de rien
Développer un moteur d'exécution symbolique en partant de rien
JUG Lausanne
 
Exemple d'IOT et ML avec Android, Cassandra et Spark
Exemple d'IOT et ML avec Android, Cassandra et SparkExemple d'IOT et ML avec Android, Cassandra et Spark
Exemple d'IOT et ML avec Android, Cassandra et Spark
JUG Lausanne
 
Play! chez Zaptravel - Nicolas Martignole - December 2012
Play! chez Zaptravel - Nicolas Martignole - December 2012Play! chez Zaptravel - Nicolas Martignole - December 2012
Play! chez Zaptravel - Nicolas Martignole - December 2012
JUG Lausanne
 
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
JUG Lausanne
 
CloudBees - Sacha Labourey - May 2011
CloudBees - Sacha Labourey - May 2011CloudBees - Sacha Labourey - May 2011
CloudBees - Sacha Labourey - May 2011
JUG Lausanne
 
Apache Camel - Stéphane Kay - April 2011
Apache Camel - Stéphane Kay - April 2011Apache Camel - Stéphane Kay - April 2011
Apache Camel - Stéphane Kay - April 2011
JUG Lausanne
 
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
JUG Lausanne
 
OpenDS - Ludovic Poitou - December 2010
OpenDS - Ludovic Poitou - December 2010OpenDS - Ludovic Poitou - December 2010
OpenDS - Ludovic Poitou - December 2010
JUG Lausanne
 
Spring Batch - Julien Jakubowski - November 2010
Spring Batch - Julien Jakubowski - November 2010Spring Batch - Julien Jakubowski - November 2010
Spring Batch - Julien Jakubowski - November 2010
JUG Lausanne
 
Infinispan - Galder Zamarreno - October 2010
Infinispan - Galder Zamarreno - October 2010Infinispan - Galder Zamarreno - October 2010
Infinispan - Galder Zamarreno - October 2010
JUG Lausanne
 
No Sql - Olivier Mallassi - September 2010
No Sql - Olivier Mallassi - September 2010No Sql - Olivier Mallassi - September 2010
No Sql - Olivier Mallassi - September 2010
JUG Lausanne
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
JUG Lausanne
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
JUG Lausanne
 
Introduction Groovy / Grails - Cyril Picat - December 2009
Introduction Groovy / Grails - Cyril Picat - December 2009Introduction Groovy / Grails - Cyril Picat - December 2009
Introduction Groovy / Grails - Cyril Picat - December 2009
JUG Lausanne
 
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
JUG Lausanne
 
Sonar - Freddy Mallet - April 2009
Sonar - Freddy Mallet - April 2009Sonar - Freddy Mallet - April 2009
Sonar - Freddy Mallet - April 2009
JUG Lausanne
 
Maven2 - Philippe Kernevez - March 2009
Maven2 - Philippe Kernevez - March 2009Maven2 - Philippe Kernevez - March 2009
Maven2 - Philippe Kernevez - March 2009
JUG Lausanne
 
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
JUG Lausanne
 
XML & Java - Raphaël Tagliani - March 2008
XML & Java - Raphaël Tagliani - March 2008XML & Java - Raphaël Tagliani - March 2008
XML & Java - Raphaël Tagliani - March 2008
JUG Lausanne
 

More from JUG Lausanne (20)

Introduction aux algorithmes génétiques
Introduction aux algorithmes génétiquesIntroduction aux algorithmes génétiques
Introduction aux algorithmes génétiques
 
Développer un moteur d'exécution symbolique en partant de rien
Développer un moteur d'exécution symbolique en partant de rienDévelopper un moteur d'exécution symbolique en partant de rien
Développer un moteur d'exécution symbolique en partant de rien
 
Exemple d'IOT et ML avec Android, Cassandra et Spark
Exemple d'IOT et ML avec Android, Cassandra et SparkExemple d'IOT et ML avec Android, Cassandra et Spark
Exemple d'IOT et ML avec Android, Cassandra et Spark
 
Play! chez Zaptravel - Nicolas Martignole - December 2012
Play! chez Zaptravel - Nicolas Martignole - December 2012Play! chez Zaptravel - Nicolas Martignole - December 2012
Play! chez Zaptravel - Nicolas Martignole - December 2012
 
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
Playframework Realtime Web - Guillaume Bort & Sadek Drobi - December 2012
 
CloudBees - Sacha Labourey - May 2011
CloudBees - Sacha Labourey - May 2011CloudBees - Sacha Labourey - May 2011
CloudBees - Sacha Labourey - May 2011
 
Apache Camel - Stéphane Kay - April 2011
Apache Camel - Stéphane Kay - April 2011Apache Camel - Stéphane Kay - April 2011
Apache Camel - Stéphane Kay - April 2011
 
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
Session dédiée à l'analyse de la qualité du code Java - Cyril Picat - Februar...
 
OpenDS - Ludovic Poitou - December 2010
OpenDS - Ludovic Poitou - December 2010OpenDS - Ludovic Poitou - December 2010
OpenDS - Ludovic Poitou - December 2010
 
Spring Batch - Julien Jakubowski - November 2010
Spring Batch - Julien Jakubowski - November 2010Spring Batch - Julien Jakubowski - November 2010
Spring Batch - Julien Jakubowski - November 2010
 
Infinispan - Galder Zamarreno - October 2010
Infinispan - Galder Zamarreno - October 2010Infinispan - Galder Zamarreno - October 2010
Infinispan - Galder Zamarreno - October 2010
 
No Sql - Olivier Mallassi - September 2010
No Sql - Olivier Mallassi - September 2010No Sql - Olivier Mallassi - September 2010
No Sql - Olivier Mallassi - September 2010
 
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
Java EE 6 & GlassFish V3 - Alexis Moussine-Pouchkine - May 2010
 
Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010Introduction à Scala - Michel Schinz - January 2010
Introduction à Scala - Michel Schinz - January 2010
 
Introduction Groovy / Grails - Cyril Picat - December 2009
Introduction Groovy / Grails - Cyril Picat - December 2009Introduction Groovy / Grails - Cyril Picat - December 2009
Introduction Groovy / Grails - Cyril Picat - December 2009
 
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
Initiation aux tests fonctionnels - Philippe Kernevez - October 2009
 
Sonar - Freddy Mallet - April 2009
Sonar - Freddy Mallet - April 2009Sonar - Freddy Mallet - April 2009
Sonar - Freddy Mallet - April 2009
 
Maven2 - Philippe Kernevez - March 2009
Maven2 - Philippe Kernevez - March 2009Maven2 - Philippe Kernevez - March 2009
Maven2 - Philippe Kernevez - March 2009
 
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
Introduction à Google Web Toolkit (GWT) - Philippe Kernevez - February 2009
 
XML & Java - Raphaël Tagliani - March 2008
XML & Java - Raphaël Tagliani - March 2008XML & Java - Raphaël Tagliani - March 2008
XML & Java - Raphaël Tagliani - March 2008
 

Recently uploaded

5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 

Recently uploaded (20)

5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 

Reverse engineering Java et contournement du mécanisme de paiement inapp Android

  • 1. Abusing Android In-app Billing feature thanks to a misunderstood integration JUGL 28/09/2017 – Jérémy MATOS
  • 2. whois securingapps Developer background Worked last 10 years in Switzerland on security products and solutions Focus on mobile since 2010 OWASP Geneva member Now freelance application security consultant Consulting to build security in software Mobile Web Cloud Internet Of Things Bitcoin/Blockchain @Securingapps
  • 3. Agenda 1. Android In-app billing in a nutshell 2. Real-life exploitation in a rather popular game: getting free credits Java reverse engineering Writing a Java hook with Xposed framework Bytecode patching of application and redistribution 3. Lessons learned 4. Recommendations
  • 4. 1. Android In-app billing in a nutshell Goal: show that Java reverse engineering can cause a loss of value in real-life Target: Android In-app billing feature Allow developers to sell content in their app, e.g. subscribtions to magazines premium features extra content in games Payment is handled by Google Requires Google Play services No credit card data exposed to developers Documentation available at https://developer.android.com/google/play/billing/index.html
  • 5. 1. Android In-app billing in a nutshell
  • 6. 2. Real-life exploitation 1/n (Used to be) rather popular game: PandaPop In-app purchases to buy credits New weapons Extra lifes Step 1: Download the APK archive: e.g. from apk-dl.com Avoid executing this binary, or in an emulator
  • 7. 2. Real-life exploitation 2/n Step 2: Prepare emulator 1. We will use Genymotion emulator Fast (thanks to x86 image) Rooting possible in 1 click Free version available 2. Install Google Play Services in Genymotion device Drag/drop ARM translation zip + restart Drag/drop gapps-lp-<verions>.zip Google Play errors are normal Wait for the various updates to take place At one point, provide a valid gmail account
  • 8. 2. Real-life exploitation 3/n Step 3: use jadx free tool to convert automatically an APK in readable Java source code 1. converts Dalvik bytecode to Java bytecode 2. decompiles Java bytecode in Java source code 3. displays the results in an IDE for analysis Step 4: Look for instances of IInAppBillingService This interface cannot be renamed Nothing is obfuscated!
  • 9. 2. Real-life exploitation 4/n Step 5: Easily review related implementation classes Fascinating code in method purchaseProduct of class com.prime31.GoogleIABPlugin Step 6: Find out what android.test.purchased means Google is our friend https://developer.android.com/google/play/billing/billing_testing.html
  • 10. 2. Real-life exploitation 5/n Step 7: force value to android.test.purchased and see what happens Let’s write a hook that forces sku of purchaseProduct to this value Using Xposed framework Overload the behavior of an application by intercepting calls in the Dalvik virtual machine No change to the original apk file Implement a hook with Android Studio in an independent apk
  • 11. 2. Real-life exploitation 6/n Prerequisites Rooted device to installed the Xposed libraries Emulator (to avoid smartphone bricking…) Install hooking framework in Genymotion device Install terminal application Drag/drop terminal.apk Start it and type su Check that root access is prompted and validate you are really root on the device Drag/drop XposedInstaller_3.1.apk Start it and choose install Reboot the Genymotion device
  • 13. 2. Real-life exploitation 8/n Step 8: Deploy hook Build hook apk with Android Studio Copy it to Genymotion device Activate hook in Xposed configuration panel Reboot Genymotion device Enjoy free credits Step 9: Bytecode patching Hook requires a rooted smartphone We want to update the original apk to be able to deploy it on any device
  • 14. 2. Real-life exploitation 9/n Android doesn’t use Java bytecode but Smali classes.dex contains the Java classes converted to Smali bytecode Smali bytecode can be transformed back and forth to human readble instructions Principle Get readable smali of original class Get readable smali of hook Manual merge hook in original class Rebuild the APK with the new smali code (including signature)
  • 15. 2. Real-life exploitation 10/n Convert APK to readable smali with command java -jar apktool.jar d your.apk Edit manually smali code in your/smali Recompiling with apktool loses native library, instead cp your.apk yourPatched.apk java -jar smali_2.1.1.jar your/smali -o classes.dex (to compile smali code) zip yourPatched.apk classes.dex zip --delete yourPatched.apk "META-INF/*" (to delete the existing signature)
  • 17. 2. Real-life exploitation 12/n Sign the APK with the key of your choice ! Generate a new signing key with keytool -genkey -v -keystore patch.keystore -alias patch -keyalg RSA - keysize 2048 -validity 10000 Enter whatever your want in password and certificate info Sign APK with jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 - keystore patch.keystore yourPatched.apk patch Ensure signature is OK jarsigner -verify -verbose -certs yourPatched.apk Deploy to a non rooted device and play ;) We could even publish in the Play Store under a new name !
  • 18. 3. Lessons learned 1/2 Never let debug code in production app An access control decision client side is insecure by design Google documentation is misleading: cf https://developer.android.com/google/play/billing/billing_best_ practices.html
  • 19. 3. Lessons learned 2/2 in-app billing can’t be used to buy credits Designed to purchase original content that is not guessable Otherwise always possible to modify the counter via hooking or bytecode patching Responsible disclosure PandaPop team: /dev/null Prime31: quick feedback « the vulnerability doesn't make any sense »
  • 20. 4. Recommendations 0. Use Proguard obfuscation to slow down a reverser 1. Use NDK to embed sensitive logic in C code With JNI possible to call C librairies via the native keyword Much more effort to reverse and patch binary code (e.g ARM) 2. Use a backend for validating purchases Still possible to hook/patch the response of the server 3. Only sell « real » content and not something easy to guess like a counter e.g Angry Birds sell extra levels and they also use NDK for calls to validation server
  • 22. Conclusion Android Java reverse engineering is really easy with jadx You cannot trust the Java code running in your Android app Modifying and resigning an APK is not difficult Only server side code can be considered secure Google recommendations for in-app purchases are incomplete and misleading By design most in-app uses cases are not possible to secure Only secure use case: download impredictable content from server
  • 23. Bonus Possible to debug in Android Studio a reversed app Jadx can export to an Android Studio project Add android:debuggable=’’true’’ in AndroidManifest.xml Resign app Deploy and start debugging from Android Studio
  • 24. Any question ? contact@securingapps.com