SlideShare a Scribd company logo
1 of 44
Download to read offline
Hacking Android Apps
Erez Metula, Application Security Expert
AppSec Labs (Founder & CEO)
ErezMetula@AppSec-Labs.com
Agenda
Introduction to android application security model
Mobile app security – why should we care?
Top 10 of the most common android app
vulnerabilities
DEMOS !
About me
Application security expert
Founder & CEO of AppSec Labs
Book author - Managed Code Rootkits
Speaker - BlackHat, Defcon, RSA, OWASP, etc.
Trainer - Secure Coding / Hacking
Android Security Model
Well established OS, based on Linux
Sandboxed VM runtime (“Dalvik”) similar to Java’s JVM
The OS creates unique user for each app
Each app runs in a sandbox using its UID
Security is enforced at the OS and the App level
Each app is signed
Applications are totally isolated by default
So where’s the problem ???
Top 10 – most common
vulnerabilities (OWASP)
1. Weak Server Side Controls
2. Insecure Data Storage
3. Insufficient Transport Layer Protection
4. Unintended Data Leakage
5. Poor Authorization and Authentication
6. Broken Cryptography
7. Client Side Injection
8. Security Decisions Via Untrusted Inputs
9. Improper Session Handling
10. Lack of Binary Protections
Things an attacker will probably do
Reverse engineering the APK – peek into code, manifest file,
etc
Grab all app files stored in /data/data/
Debug the running app & Setting breakpoints
Hook important runtime calls
Monitor & manipulate network traffic (sniffing, proxying)
Monitor process activity
Observing file access
Analyze memory dumps (MAT, hprof dumps)
Weak Server Side Controls
Weak Server Side Controls
Using the android mobile app to attack the server
business logic
Not a risk specific to the mobile platform
Common server side vulnerabilities such as SQL
injection, XSS, insecure authentication, etc.
Often by redirecting the phone’s request to a proxy
and manipulate with it
DEMO
Intercepting and manipulating client/server
requests
Insecure Data Storage
Insecure Data Storage
Many of the most publicized mobile application security incidents have
been caused by insecure or unnecessary client-side data storage.
Sometimes app developers assume the app data cannot be accessed by
an attacker
Sensitive information – usernames, passwords, Encryption keys,
Credit cards, session identifiers, tokens, etc.
Private information - Phone numbers, Addresses, Emails, locations
Interesting places that might contain sensitive data
SQLite databases
Log Files
XML Data Stores or Manifest Files
Binary data stores
SD Card
Cloud
Insecure File Permissions
In general, app files are sandboxed
Writing files with poor permissions
Files on /data/data/APP/ with “everyone read”
Files stored on SDcard (no permissions !!)
Allows AppA to steal files from AppB
Example – Skype bad permissions - steal contacts !
Insufficient Transport Layer
Security (no HTTPS)
Insufficient Transport Layer
Security (no HTTPS)
“10% of apps fail doing SSL cert validation” - CERT
HTTPS (TLS or SSL), are cryptographic protocols that
provide communication security over the Internet:
Encrypting the transport layer
Authentication the server side
Any request sent without HTTPS is vulnerable to..
Information disclosure
Data tampering
Server spoofing and phishing
Another common Mistakes – no
cert validation
• usage of out of date/self signed SSL certificates
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException { }
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException { }
}};
Unintended Data Leakage
Unintended Data Leakage
Unintended data leakage occurs when
a developer accidentally places sensitive data in a location on the
mobile device that can be accessed by other apps / physical access
Another case is during sensitive data processing, a side-effect (that is
unknown to the developer) results in that information being placed
into an insecure location
Examples - places to look for
URL Caching (Both request and response)
Keyboard Press Caching
Copy/Paste buffer Caching
Application backgrounding
Logging
HTML5 data storage
Browser cookie objects
Analytics data sent to 3rd parties
Example - Insecure Log Exposure
Some apps store their own logs inside the local folder
Logs can contain info such as
Important events (app start, user login details, page load)
Exceptions
Sensitive variables (encryption keys, serial numbers)
Sensitive information (credit cards, passwords)
Often such files are stored without any protection at
the file system
Sometimes such files don’t even have any file
permission protection – any app can steal such info
Common Pitfall - Leaking
Information to Runtime Logs
Private information is often written to logs
Location, Phone identifiers ,Passwords, CC, URL, etc
Poor Authorization and
Authentication
Poor or missing authentication
Attacker van to anonymously execute
functionality
Can also allow to impersonate other
users
Sometimes weak passwords can lead to
broken authentication
Strong passwords are hard to enter on a
mobile device
Short passwords (4-digit PINs) are often
used
Poor Authorization and
Authentication
Example - Device authentication based on IMEI,
IMSI, UUID is not sufficient
Hardware identifiers persist across data wipes and factory resets
Don’t use device identifier as session token
Another example - When security is enforced at the
client side
The UI shows the user only what he can do. What he cannot is
disabled or just not visible
Attacker can bypass this quite easily
Demo
IMEI restriction bypass with ReFrameworker
Broken cryptography
(“Encraption”)
Broken cryptography
(“Encraption”)
Usage of a broken or risky cryptographic algorithm may result
in the exposure of sensitive information.
Configuration files or databases belonging to the app may
contain some encrypted data
Many times the app does bad encryption
Hard-coded key is stored in the source code
Same key for all users
Key can be stolen by other apps due to bad permissions
Key is stored right next the encrypted data
Custom, easily defeated crypto implementations (“encraption”)
Encrypting some data while storing the encryption key at the
client side does not help that much
Spot the bug
what’s wrong with this code?
Spot 3 different bugs related to encryption!!!!
Hard
coded
key
Bad
algorithm
Bad
crypto
mode
Client side injections
Client side injections
Results in the execution of malicious code
Malicious code is provided in the form of input that
is processed by the app
During processing, the input is interpreted as
executable code which is executed by the app,
running with its access permissions
Input can come from
Another app via intent/content provider
Shared file (ex: sdcard) manipulated by another app
Server side response
3rd party web site
Some examples
SQL Injection – embedding untrusted input into raw SQL statements
String query = "select * from table where columnName=‘“+external_input+”’”;
db.rawQuery( query, null );
Command Injection – embedding untrusted input into OS command execution
Process process = Runtime.getRuntime().exec("top -n “ + external_input );
Directory traversal – using a manipulated file name
basePath = “/sdcard/DCIM/”;
Filename = getInput();// “../../data/data/target.app.packagename/shared_prefs/preferences.xml”
openFileOutput(basePath+filename, Context.MODE_WORLD_READABLE);
XSS/Javascript injection into WebView – embedding input into HTML
String htmlCode = "<html><body><button type="button" onclick="myFunction()">+ external_input
+"</button></body></html>";
webView.loadDataWithBaseURL("null", htmlCode, "text/html", "UTF-8", null);
Security Decisions Via Untrusted
Inputs
Insecure IPC
(Inter Process Communication)
Interoperability - A unique aspect of the Android system design is that any
application can start another application’s component
Apps are sandboxed, and cannot directly activate a component from another
application.
Therefore, to activate a component in another application, apps deliver an
asynchronous message to the system (“intent”)
The system then activates the target component
Exposed components
Components are not visible to other apps by default. Unless….
It has At least one <intent-filter> tag
It is declared as exported “exported=true”
<receiver android:name="com.appsec.hackmepal.BrReciever" android:exported="true"> </receiver>
It is a dynamically registered broadcast receiver
public
Insecure IPC
(Inter Process Communication)
If it is exposed, and you didn’t use android:permission than
you’re screwed.. ☺☺☺☺
Some examples
Unauthorized caller/intent spoofing
Permission re-delegation/Confused deputy
Phishing/CSRF
Intent sniffing
DoS
Component hijack/identity theft
DEMO
Intent Denial of Service (DoS)
Improper Session Handling
Improper Session Handling
Mobile apps often use session tokens to maintain
state over stateless protocols like HTTP or SOAP
Client authenticates with the backend server
gets a session cookie in response
Cookie is added to all requests sent to the server
Server can enforce authentication and authorization
Common mistakes
Insecure Token Creation
Failure to Invalidate Sessions on the server side
Lack of Adequate Timeout Protection
Failure to Properly Rotate Cookies (timeout, changing user role, etc).
Lack of Binary Protections
Lack of Binary Protections
Exposure of the application to a variety of risks
Results in a mobile app that can be analyzed,
reverse-engineered, and modified
It is extremely common for apps to be deployed
without binary protection.
The Problem of Reversing &
Decompilation
Major risks
Code exposure
Business logic (secret algorhithms, etc)
Security vulnerabilities in the code
Secrets in code (passwords, Encryption keys, etc)
Software piracy
Code modification
Add backdoors to original code
Patching - Change the application logic, add or remove
functionaliy, etc
Reverse engineering
Extract application from device (adb pull app.apk)
Reverse Engineering the apk
Extracting the APK content
apktool d someapp.apk –o outputDir
Disassembly
Smali/baksmali
Decompile the APK
dex2jar - Converting the classes.dex file to a jar
Decompiling the jar file and getting java source code
Analyzing the app
Locating sensitive files on device storage, Insecure file permissions, Locating
secrets in code/config files, Tracking insecure IPC, etc.
Patching the apk
Rebuilding the APK content
apktool b outputDir –o new.apk
Re-Signing modified apk’s
Signapk new.apk new_signed.apk
Put it back (adb push new_signed.apk)
Obfuscated Code and
anti-debugging
Although it’s a bit harder to read, class and member types
must stay the same..
Encrypted values must have the key somewhere near
Anti debugging code can be removed…
Summary
Android application level vulnerabilities put the service and
the end user at risk
Never take any security decisions at the Android side!
Remember this: “APK = open source code”. This way you’ll
avoid doing stupid things (security wise ☺)
Integrate security into your development lifecycle
Performing penetration testing on your Android apps
QUESTIONS ?
THANK YOU !
ErezMetula@AppSec-Labs.com
Download AppUse for free:
https://appsec-labs.com/appuse/

More Related Content

What's hot

When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
Shakacon
 
Mobile Application Pentest [Fast-Track]
Mobile Application Pentest [Fast-Track]Mobile Application Pentest [Fast-Track]
Mobile Application Pentest [Fast-Track]
Prathan Phongthiproek
 
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Ajin Abraham
 
Analysis and research of system security based on android
Analysis and research of system security based on androidAnalysis and research of system security based on android
Analysis and research of system security based on android
Ravishankar Kumar
 

What's hot (20)

When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
When Encryption is Not Enough...Sumanth Naropanth, Chandra Prakash Gopalaiah ...
 
Android Security
Android SecurityAndroid Security
Android Security
 
Mobile Application Pentest [Fast-Track]
Mobile Application Pentest [Fast-Track]Mobile Application Pentest [Fast-Track]
Mobile Application Pentest [Fast-Track]
 
Hacking your Droid (Aditya Gupta)
Hacking your Droid (Aditya Gupta)Hacking your Droid (Aditya Gupta)
Hacking your Droid (Aditya Gupta)
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and Security
 
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015Hacking Tizen : The OS of Everything - Nullcon Goa 2015
Hacking Tizen : The OS of Everything - Nullcon Goa 2015
 
Android sandbox
Android sandboxAndroid sandbox
Android sandbox
 
Android Application Penetration Testing - Mohammed Adam
Android Application Penetration Testing - Mohammed AdamAndroid Application Penetration Testing - Mohammed Adam
Android Application Penetration Testing - Mohammed Adam
 
Sperasoft talks: Android Security Threats
Sperasoft talks: Android Security ThreatsSperasoft talks: Android Security Threats
Sperasoft talks: Android Security Threats
 
Android Security - Common Security Pitfalls in Android Applications
Android Security - Common Security Pitfalls in Android ApplicationsAndroid Security - Common Security Pitfalls in Android Applications
Android Security - Common Security Pitfalls in Android Applications
 
Hacking Tizen: The OS of everything - Whitepaper
Hacking Tizen: The OS of everything - WhitepaperHacking Tizen: The OS of everything - Whitepaper
Hacking Tizen: The OS of everything - Whitepaper
 
Hacker Halted 2014 - Reverse Engineering the Android OS
Hacker Halted 2014 - Reverse Engineering the Android OSHacker Halted 2014 - Reverse Engineering the Android OS
Hacker Halted 2014 - Reverse Engineering the Android OS
 
Android pen test basics
Android pen test basicsAndroid pen test basics
Android pen test basics
 
Learning by hacking - android application hacking tutorial
Learning by hacking - android application hacking tutorialLearning by hacking - android application hacking tutorial
Learning by hacking - android application hacking tutorial
 
[Wroclaw #2] iOS Security - 101
[Wroclaw #2] iOS Security - 101[Wroclaw #2] iOS Security - 101
[Wroclaw #2] iOS Security - 101
 
[Wroclaw #1] Android Security Workshop
[Wroclaw #1] Android Security Workshop[Wroclaw #1] Android Security Workshop
[Wroclaw #1] Android Security Workshop
 
I Want More Ninja – iOS Security Testing
I Want More Ninja – iOS Security TestingI Want More Ninja – iOS Security Testing
I Want More Ninja – iOS Security Testing
 
Pentesting Android Applications
Pentesting Android ApplicationsPentesting Android Applications
Pentesting Android Applications
 
Analysis and research of system security based on android
Analysis and research of system security based on androidAnalysis and research of system security based on android
Analysis and research of system security based on android
 
Pentesting Mobile Applications (Prashant Verma)
Pentesting Mobile Applications (Prashant Verma)Pentesting Mobile Applications (Prashant Verma)
Pentesting Mobile Applications (Prashant Verma)
 

Similar to Android App Hacking - Erez Metula, AppSec

Security testing of mobile applications
Security testing of mobile applicationsSecurity testing of mobile applications
Security testing of mobile applications
GTestClub
 
Security communication
Security communicationSecurity communication
Security communication
Say Shyong
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
Abdul Wahid
 
Testingfor Sw Security
Testingfor Sw SecurityTestingfor Sw Security
Testingfor Sw Security
ankitmehta21
 
Software Security Testing
Software Security TestingSoftware Security Testing
Software Security Testing
ankitmehta21
 

Similar to Android App Hacking - Erez Metula, AppSec (20)

Pentesting Android Apps
Pentesting Android AppsPentesting Android Apps
Pentesting Android Apps
 
Smart Bombs: Mobile Vulnerability and Exploitation
Smart Bombs: Mobile Vulnerability and ExploitationSmart Bombs: Mobile Vulnerability and Exploitation
Smart Bombs: Mobile Vulnerability and Exploitation
 
Security in the cloud protecting your cloud apps
Security in the cloud   protecting your cloud appsSecurity in the cloud   protecting your cloud apps
Security in the cloud protecting your cloud apps
 
Untitled 1
Untitled 1Untitled 1
Untitled 1
 
Secure Android Apps- nVisium Security
Secure Android Apps- nVisium SecuritySecure Android Apps- nVisium Security
Secure Android Apps- nVisium Security
 
Bank One App Sec Training
Bank One App Sec TrainingBank One App Sec Training
Bank One App Sec Training
 
Security testing of mobile applications
Security testing of mobile applicationsSecurity testing of mobile applications
Security testing of mobile applications
 
Security communication
Security communicationSecurity communication
Security communication
 
Whittaker How To Break Software Security - SoftTest Ireland
Whittaker How To Break Software Security - SoftTest IrelandWhittaker How To Break Software Security - SoftTest Ireland
Whittaker How To Break Software Security - SoftTest Ireland
 
Survey Presentation About Application Security
Survey Presentation About Application SecuritySurvey Presentation About Application Security
Survey Presentation About Application Security
 
OWASP Mobile Security: Top 10 Risks for 2017
OWASP Mobile Security: Top 10 Risks for 2017OWASP Mobile Security: Top 10 Risks for 2017
OWASP Mobile Security: Top 10 Risks for 2017
 
Web Application Security
Web Application SecurityWeb Application Security
Web Application Security
 
Testingfor Sw Security
Testingfor Sw SecurityTestingfor Sw Security
Testingfor Sw Security
 
Secure Android Development
Secure Android DevelopmentSecure Android Development
Secure Android Development
 
R U aBLE? BLE Application Hacking
R U aBLE? BLE Application HackingR U aBLE? BLE Application Hacking
R U aBLE? BLE Application Hacking
 
Sql securitytesting
Sql  securitytestingSql  securitytesting
Sql securitytesting
 
Software Security Testing
Software Security TestingSoftware Security Testing
Software Security Testing
 
Enterprise Cloud Security - Concepts Mash-up
Enterprise Cloud Security - Concepts Mash-upEnterprise Cloud Security - Concepts Mash-up
Enterprise Cloud Security - Concepts Mash-up
 
Mobile security
Mobile securityMobile security
Mobile security
 
Understanding Application Threat Modelling & Architecture
 Understanding Application Threat Modelling & Architecture Understanding Application Threat Modelling & Architecture
Understanding Application Threat Modelling & Architecture
 

More from DroidConTLV

More from 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
 
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGeneBang-Bang, you have been hacked - Yonatan Levin, KolGene
Bang-Bang, you have been hacked - Yonatan Levin, KolGene
 
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
 

Recently uploaded

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Android App Hacking - Erez Metula, AppSec

  • 1. Hacking Android Apps Erez Metula, Application Security Expert AppSec Labs (Founder & CEO) ErezMetula@AppSec-Labs.com
  • 2. Agenda Introduction to android application security model Mobile app security – why should we care? Top 10 of the most common android app vulnerabilities DEMOS !
  • 3. About me Application security expert Founder & CEO of AppSec Labs Book author - Managed Code Rootkits Speaker - BlackHat, Defcon, RSA, OWASP, etc. Trainer - Secure Coding / Hacking
  • 4. Android Security Model Well established OS, based on Linux Sandboxed VM runtime (“Dalvik”) similar to Java’s JVM The OS creates unique user for each app Each app runs in a sandbox using its UID Security is enforced at the OS and the App level Each app is signed Applications are totally isolated by default So where’s the problem ???
  • 5. Top 10 – most common vulnerabilities (OWASP) 1. Weak Server Side Controls 2. Insecure Data Storage 3. Insufficient Transport Layer Protection 4. Unintended Data Leakage 5. Poor Authorization and Authentication 6. Broken Cryptography 7. Client Side Injection 8. Security Decisions Via Untrusted Inputs 9. Improper Session Handling 10. Lack of Binary Protections
  • 6. Things an attacker will probably do Reverse engineering the APK – peek into code, manifest file, etc Grab all app files stored in /data/data/ Debug the running app & Setting breakpoints Hook important runtime calls Monitor & manipulate network traffic (sniffing, proxying) Monitor process activity Observing file access Analyze memory dumps (MAT, hprof dumps)
  • 7. Weak Server Side Controls
  • 8. Weak Server Side Controls Using the android mobile app to attack the server business logic Not a risk specific to the mobile platform Common server side vulnerabilities such as SQL injection, XSS, insecure authentication, etc. Often by redirecting the phone’s request to a proxy and manipulate with it
  • 9. DEMO Intercepting and manipulating client/server requests
  • 11. Insecure Data Storage Many of the most publicized mobile application security incidents have been caused by insecure or unnecessary client-side data storage. Sometimes app developers assume the app data cannot be accessed by an attacker Sensitive information – usernames, passwords, Encryption keys, Credit cards, session identifiers, tokens, etc. Private information - Phone numbers, Addresses, Emails, locations Interesting places that might contain sensitive data SQLite databases Log Files XML Data Stores or Manifest Files Binary data stores SD Card Cloud
  • 12. Insecure File Permissions In general, app files are sandboxed Writing files with poor permissions Files on /data/data/APP/ with “everyone read” Files stored on SDcard (no permissions !!) Allows AppA to steal files from AppB Example – Skype bad permissions - steal contacts !
  • 14. Insufficient Transport Layer Security (no HTTPS) “10% of apps fail doing SSL cert validation” - CERT HTTPS (TLS or SSL), are cryptographic protocols that provide communication security over the Internet: Encrypting the transport layer Authentication the server side Any request sent without HTTPS is vulnerable to.. Information disclosure Data tampering Server spoofing and phishing
  • 15. Another common Mistakes – no cert validation • usage of out of date/self signed SSL certificates TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[] {}; } public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } }};
  • 17. Unintended Data Leakage Unintended data leakage occurs when a developer accidentally places sensitive data in a location on the mobile device that can be accessed by other apps / physical access Another case is during sensitive data processing, a side-effect (that is unknown to the developer) results in that information being placed into an insecure location Examples - places to look for URL Caching (Both request and response) Keyboard Press Caching Copy/Paste buffer Caching Application backgrounding Logging HTML5 data storage Browser cookie objects Analytics data sent to 3rd parties
  • 18. Example - Insecure Log Exposure Some apps store their own logs inside the local folder Logs can contain info such as Important events (app start, user login details, page load) Exceptions Sensitive variables (encryption keys, serial numbers) Sensitive information (credit cards, passwords) Often such files are stored without any protection at the file system Sometimes such files don’t even have any file permission protection – any app can steal such info
  • 19. Common Pitfall - Leaking Information to Runtime Logs Private information is often written to logs Location, Phone identifiers ,Passwords, CC, URL, etc
  • 21. Poor or missing authentication Attacker van to anonymously execute functionality Can also allow to impersonate other users Sometimes weak passwords can lead to broken authentication Strong passwords are hard to enter on a mobile device Short passwords (4-digit PINs) are often used
  • 22. Poor Authorization and Authentication Example - Device authentication based on IMEI, IMSI, UUID is not sufficient Hardware identifiers persist across data wipes and factory resets Don’t use device identifier as session token Another example - When security is enforced at the client side The UI shows the user only what he can do. What he cannot is disabled or just not visible Attacker can bypass this quite easily
  • 23. Demo IMEI restriction bypass with ReFrameworker
  • 25. Broken cryptography (“Encraption”) Usage of a broken or risky cryptographic algorithm may result in the exposure of sensitive information. Configuration files or databases belonging to the app may contain some encrypted data Many times the app does bad encryption Hard-coded key is stored in the source code Same key for all users Key can be stolen by other apps due to bad permissions Key is stored right next the encrypted data Custom, easily defeated crypto implementations (“encraption”) Encrypting some data while storing the encryption key at the client side does not help that much
  • 26. Spot the bug what’s wrong with this code? Spot 3 different bugs related to encryption!!!! Hard coded key Bad algorithm Bad crypto mode
  • 28. Client side injections Results in the execution of malicious code Malicious code is provided in the form of input that is processed by the app During processing, the input is interpreted as executable code which is executed by the app, running with its access permissions Input can come from Another app via intent/content provider Shared file (ex: sdcard) manipulated by another app Server side response 3rd party web site
  • 29. Some examples SQL Injection – embedding untrusted input into raw SQL statements String query = "select * from table where columnName=‘“+external_input+”’”; db.rawQuery( query, null ); Command Injection – embedding untrusted input into OS command execution Process process = Runtime.getRuntime().exec("top -n “ + external_input ); Directory traversal – using a manipulated file name basePath = “/sdcard/DCIM/”; Filename = getInput();// “../../data/data/target.app.packagename/shared_prefs/preferences.xml” openFileOutput(basePath+filename, Context.MODE_WORLD_READABLE); XSS/Javascript injection into WebView – embedding input into HTML String htmlCode = "<html><body><button type="button" onclick="myFunction()">+ external_input +"</button></body></html>"; webView.loadDataWithBaseURL("null", htmlCode, "text/html", "UTF-8", null);
  • 30. Security Decisions Via Untrusted Inputs
  • 31. Insecure IPC (Inter Process Communication) Interoperability - A unique aspect of the Android system design is that any application can start another application’s component Apps are sandboxed, and cannot directly activate a component from another application. Therefore, to activate a component in another application, apps deliver an asynchronous message to the system (“intent”) The system then activates the target component
  • 32. Exposed components Components are not visible to other apps by default. Unless…. It has At least one <intent-filter> tag It is declared as exported “exported=true” <receiver android:name="com.appsec.hackmepal.BrReciever" android:exported="true"> </receiver> It is a dynamically registered broadcast receiver public
  • 33. Insecure IPC (Inter Process Communication) If it is exposed, and you didn’t use android:permission than you’re screwed.. ☺☺☺☺ Some examples Unauthorized caller/intent spoofing Permission re-delegation/Confused deputy Phishing/CSRF Intent sniffing DoS Component hijack/identity theft
  • 34. DEMO Intent Denial of Service (DoS)
  • 36. Improper Session Handling Mobile apps often use session tokens to maintain state over stateless protocols like HTTP or SOAP Client authenticates with the backend server gets a session cookie in response Cookie is added to all requests sent to the server Server can enforce authentication and authorization Common mistakes Insecure Token Creation Failure to Invalidate Sessions on the server side Lack of Adequate Timeout Protection Failure to Properly Rotate Cookies (timeout, changing user role, etc).
  • 37. Lack of Binary Protections
  • 38. Lack of Binary Protections Exposure of the application to a variety of risks Results in a mobile app that can be analyzed, reverse-engineered, and modified It is extremely common for apps to be deployed without binary protection.
  • 39. The Problem of Reversing & Decompilation Major risks Code exposure Business logic (secret algorhithms, etc) Security vulnerabilities in the code Secrets in code (passwords, Encryption keys, etc) Software piracy Code modification Add backdoors to original code Patching - Change the application logic, add or remove functionaliy, etc
  • 40. Reverse engineering Extract application from device (adb pull app.apk) Reverse Engineering the apk Extracting the APK content apktool d someapp.apk –o outputDir Disassembly Smali/baksmali Decompile the APK dex2jar - Converting the classes.dex file to a jar Decompiling the jar file and getting java source code Analyzing the app Locating sensitive files on device storage, Insecure file permissions, Locating secrets in code/config files, Tracking insecure IPC, etc. Patching the apk Rebuilding the APK content apktool b outputDir –o new.apk Re-Signing modified apk’s Signapk new.apk new_signed.apk Put it back (adb push new_signed.apk)
  • 41. Obfuscated Code and anti-debugging Although it’s a bit harder to read, class and member types must stay the same.. Encrypted values must have the key somewhere near Anti debugging code can be removed…
  • 42. Summary Android application level vulnerabilities put the service and the end user at risk Never take any security decisions at the Android side! Remember this: “APK = open source code”. This way you’ll avoid doing stupid things (security wise ☺) Integrate security into your development lifecycle Performing penetration testing on your Android apps
  • 44. THANK YOU ! ErezMetula@AppSec-Labs.com Download AppUse for free: https://appsec-labs.com/appuse/