SlideShare a Scribd company logo
Mobile App Security Code Reviews
           Security BSides Las Vegas 2011




© Copyright 2011 Denim Group - All Rights Reserved
Instructor
 Dan Cornell
 dan@denimgroup.com
 @danielcornell

 www.denimgroup.com
 www.smartphonesdumbapps.com
 (210) 572-4400




© Copyright 2011 Denim Group - All Rights Reserved   1
My Background
 • Dan Cornell – Founder and CTO Denim Group
 • Software developer by background (Java, .NET, etc.)

 • Denim Group
         – Build software with special security, performance, reliability
           requirements
         – Help organizations deal with the risk associated with their software
                  • Code reviews and application assessments
                  • SDLC consulting
                  • Secure development training – instructor-led and e-Learning




© Copyright 2011 Denim Group - All Rights Reserved                                2
Agenda
    1.      Introduction and Overview
    2.      Data: In Motion and at Rest
    3.      Other Dangerous Inputs
    4.      Platform-Specific Concerns
    5.      Conclusions / Questions




© Copyright 2011 Denim Group - All Rights Reserved   3
1 – Introduction and Overview
 •     Focus For This Class
 •     Security Implications for Mobile Applications
 •     Mobile Application Threat Model
 •     Testing the Security of Mobile Applications
 •     Platform Background
         – Android
         – iOS




© Copyright 2011 Denim Group - All Rights Reserved     4
Tradeoffs: Value versus Risk
 • Mobile applications can create tremendous value for organizations
         – New classes of applications utilizing mobile capabilities: GPS, camera, etc.
         – Innovating applications for employees and customers
 • Mobile devices and mobile applications can create tremendous risks
         – Sensitive data inevitably stored on the device (email, contacts)
         – Connect to a lot of untrusted networks (carrier, WiFi)


 • Most developers are not trained to develop secure applications
         – Fact of life, but slowing getting better
 • Most developers are new to creating mobile applications
         – Different platforms have different security characteristics and capabilities




© Copyright 2011 Denim Group - All Rights Reserved                                        5
Smart Phones, Dumb Apps
 • Lots of media focus on device and platform security
         – Important because successful attacks give tremendous attacker leverage
 • Most organizations:
         –     Accept realities of device and platform security
         –     Concerned about the security of their custom applications
         –     Concerned about sensitive data on the device because of their apps
         –     Concerned about network-available resources that support their apps


 • Who has mobile application deployed for customers?

 • Who has had mobile applications deployed without their knowledge?
         – *$!%$# marketing department…




© Copyright 2011 Denim Group - All Rights Reserved                                   6
Generic Mobile Application
 Threat Model




© Copyright 2011 Denim Group - All Rights Reserved   7
Some Assumptions for Developers
 • Smartphone applications are essentially thick-client applications
         –     That people carry in their pockets
         –     And drop in toilets
         –     And put on eBay when the new iPhone comes out
         –     And leave on airplanes
         –     And so on…


 • Attackers will be able to access:
         – Target user (victim) devices
         – Your application binaries


 • What else should you assume they know or will find out?



© Copyright 2011 Denim Group - All Rights Reserved                     8
Testing the Security of Mobile Applications
 • IMPORTANT: It is really the system as a whole you care about
         –     Application plus…
         –     3rd party web services
         –     Enterprise services
         –     And so on


 • The most “interesting” weaknesses and vulnerabilities we find are in
   mobile applications’ interactions with supporting services

 • Mobile applications are different than web applications
         – Can’t just fire up an automated scanner and turn up a bunch of SQL injection and
           XSS vulnerabilities
         – Usually…


© Copyright 2011 Denim Group - All Rights Reserved                                            9
Testing the Security of Mobile Applications
 Type of Analysis                                    Activities
 Static Analysis
       Source Code                                   Source code scanning
                                                     Manual source code review
       Binary                                        Reverse engineering
 Dynamic Analysis                                    Debugger execution
                                                     Traffic capture via proxy
 Forensic Analysis                                   File permission analysis
                                                     File content analysis




© Copyright 2011 Denim Group - All Rights Reserved                               10
Platform Background: Android
 • Linux-based operating system
 • Applications typically written in Java
 • Java compiled to DEX bytecode for the Dalvik virtual machine
         – Kind of like a Java virtual machine
         – Register-based rather than stack-based




© Copyright 2011 Denim Group - All Rights Reserved                11
Platform Background:
 • UNIX-based operating system
 • Applications written in Objective-C




© Copyright 2011 Denim Group - All Rights Reserved   12
Pandemobium Stock Trader Application
  • Android and iOS versions



  • Functionality
          –    Log in
          –    Track stock tips
          –    Make stock trades
          –    Get stock tips
          –    Share stock tips
  • We will use as an example
    through the class

© Copyright 2011 Denim Group - All Rights Reserved   13
2 – Data: In Motion and at Rest
 • Local Data Storage
 • Consuming 3rd Party Web Services
 • Mobile Applications and Enterprise Services




© Copyright 2011 Denim Group - All Rights Reserved   14
Local Data Storage
 • Overview
 • Identifying Potential Storage Issues
 • Encryption Best Practices




© Copyright 2011 Denim Group - All Rights Reserved   15
Local Data Storage Overview
 • If you store data on the device it can be captured
         – How you store the data can impact how easy this is
         – But at the end of the day it can be captured
         – So be careful what you store on the device. And be careful how you store it


 • But what if I encrypt the data?
         – Great idea. Where are you going to store the key?


 • This is an issue that gets a lot of media attention




© Copyright 2011 Denim Group - All Rights Reserved                                       16
Local Data Storage: Android
 • Files
         – Internal storage (file permissions enforced)
         – External storage (no file permissions enforced)
 • SQLite Databases
 • Shared Preferences
 • Web Cache




© Copyright 2011 Denim Group - All Rights Reserved           17
Android Data Storage

 • In Android, every application gets its own uid/gid
         – Clever use of the Linux security model
         – But external storage does not have permission enforcement


 • Default permissions are to be readable and writeable by the app only
         –     Files
         –     SQLite databases
         –     Shared Permissions
         –     Context.MODE_PRIVATE


 • But of course you can override this
         – Context.MODE_WORLD_READABLE
         – Context.MODE_WORLD_WRITEABLE

© Copyright 2011 Denim Group - All Rights Reserved                        18
Local Data Storage:
 •     Files
 •     SQLite Databases
 •     plist Files
 •     Keychain
 •     Web Cache




© Copyright 2011 Denim Group - All Rights Reserved   19
Android Static Analysis
 for Storage Issues
 • Android-specific functions for file handling:
         – Context.openFileOutput()
         – Context.openFileInput()
         – Context.getDir()


 • Android-specific functions for SQLite database handling:
         – Context.openOrCreateDatabase()
         – Context.getDatabasePath()
         – SQLiteDatabase.openDatabase()




© Copyright 2011 Denim Group - All Rights Reserved            20
Android Static Analysis
 for Storage Issues
 • Android-specific functions for Shared Preferences handling
         – Context.getSharedPreferences()


 • Android-specific functions for cache handling:
         – Context.getCacheDir()
         – Context.getExternalCacheDir()


 • Non-Android-specific functions
         – Anything else you would examine in Java
         – java.io and the like




© Copyright 2011 Denim Group - All Rights Reserved              21
Android Static Analysis
 for Storage Issues
 • File permissions:
         – MODE_PRIVATE – generally all right
         – MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE – why?


 • What is being stored?
 • How is it being used?

 • World readable/writeable files can be manipulated by malicious
   applications




© Copyright 2011 Denim Group - All Rights Reserved                  22
iOS Static Analysis for
 Storage Issues
 • NSFileManager class
         – NSFileProtectionKey attribute
                  • NSFileProtectionNone – Always accessible
                  • NSFileProtectionComplete – Encrypted on disk when device is locked or booting



 • UIApplicationProtectedDataWillBecomeUnavailable notification
         – Fired when application data is about to become unavailable
         – References to sensitive files should be dropped




© Copyright 2011 Denim Group - All Rights Reserved                                                  23
Encryption Best Practices
 • Key management is a huge problem
 • If encrypted data and the key are stored on the device…

 • Android Encryption
         – Access to javax.crypto libraries
         – Open source options like Bouncy Castle


 • iOS Encryption
         – Access to common crypto algorithms
         – Keychain available for encrypted storage




© Copyright 2011 Denim Group - All Rights Reserved           24
iOS Keychain
 • Allows you to store key/value pairs using iOS protections
 • Default: only visible to “owning” application
 • Possible values for kSecAttrAccessible:
         –     kSecAttrAccessibleWhenUnlocked
         –     kSecAttrAccessibleAfterFirstUnlock
         –     kSecAttrAccessibleAlways
         –     kSecAttrAccessibleWhenUnlockedThisDeviceOnly
         –     kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
         –     kSecAttrAccessibleAlwaysThisDeviceOnly
 • But…
         – Clever German researchers found out how to dump non-PIN protected data
         – And clever Russian researchers found out how to brute-force the PIN
         – Do not store sensitive data on the device



© Copyright 2011 Denim Group - All Rights Reserved                                  25
Consuming 3rd Party Web Services
 • Overview
 • Identifying Services In Use
 • Data Communications and Handling Best Practices




© Copyright 2011 Denim Group - All Rights Reserved   26
Overview of Consuming 3rd Party Web Services
 • Interesting apps need to talk to stuff
         – And most of that stuff you should not trust


 • These are untrusted inputs
         – Positively validate them before use


 • You do not control what they do with the data
         – Be careful what you send




© Copyright 2011 Denim Group - All Rights Reserved       27
Identifying Services In Use
 • Look for URL connections

 • Look for network connections

 • Look for web controls




© Copyright 2011 Denim Group - All Rights Reserved   28
Data Communications and Handling Best Practices
 • Remember: Mobile devices can talk on lots of different networks

 • So use SSL
         – Can not observe or change traffic
         – DNS concerns


 • And force it to be used correctly
         – With valid certificates


 • Be careful of caching




© Copyright 2011 Denim Group - All Rights Reserved                   29
Android Network Connections
 • Android-specific classes:
         – android.net.*
         – android.net.SSLCertificateFactory
                  • Make sure server validation has not been turned off



 • Java platform classes:
         – java.net.URLConnection
         – java.net.URL
         – And so on…




© Copyright 2011 Denim Group - All Rights Reserved                        30
Android Network Connections
 • Included Apache classes:
         – org.apache.http.HttpClient
         – org.apache.http.HttpPost
         – org.apache.http.Response


 • WebView component
         – Include HTML content in web applications




© Copyright 2011 Denim Group - All Rights Reserved    31
iOS Network Connections
 • CFStream
         –     kCFStreamPropertyShouldCloseNativeSocket
         –     kCFStreamPropertySocketSecurityLevel
         –     kCFStreamPropertySOCKSProxy
         –     kCFStreamPropertySSLPeerCertificates
         –     kCFStreamPropertySSLPeerTrust
         –     kCFStreamPropertySSLSettings
 •     CFHost
 •     NSStream
 •     NSHost
 •     NSURLDownload
 •     NSURL
 •     UIWebView

© Copyright 2011 Denim Group - All Rights Reserved        32
What to do With 3rd Party Services?
 • Largest concern is how they impact YOUR security
         – Validate all input
         – Be careful how your logic treats the data
         – Be careful what you send




© Copyright 2011 Denim Group - All Rights Reserved     33
Overview of Mobile Applications and Enterprise Services
 • If you were a bad guy, would you rather have
         – The data on one device
         – All the data on the server
         – I guess it depends on how advanced and persistent you are…


 • These provide a great window into your organization
         – Client data
         – Transaction data
         – And so on…


 • The most serious vulnerabilities we find in assessments deal with
   apps’ interactions with enterprise services



© Copyright 2011 Denim Group - All Rights Reserved                      34
3 – Other Dangerous Inputs
 • Mobile Browser Content Handling




© Copyright 2011 Denim Group - All Rights Reserved   35
Mobile Browser Content Handling
 • Identifying Mobile Browser Content Handlers
 • Testing the Security of Content Handlers




© Copyright 2011 Denim Group - All Rights Reserved   36
Android: Identifying Content Handlers
 • Look in AndroidManifest.xml
 • Look for <intent-filter> tags:
 <intent-filter>
     <action android:name="android.intent.action.VIEW" />
     <category android:name="android.intent.category.DEFAULT" />
     <category android:name="android.intent.category.BROWSABLE" />
     <data android:scheme=“the_scheme" />
 </intent-filter>


 • But what apps export intents?
         – http://www.openintents.org/




© Copyright 2011 Denim Group - All Rights Reserved                   37
iOS: Identifying Content Handlers
 • Look in Info.plist
 • Look for <key>CFBundleURLSchemes</key>
       <array>
             <dict>
               <key>CFBundleURLSchemes</key>
               <array>
                  <string>the_scheme</string>
               </array>
             </dict>
       </array>


 • But what apps handle custom schemes?
         – http://handleopenurl.com/



© Copyright 2011 Denim Group - All Rights Reserved   38
Testing the Security of Content Handlers
 • How to reach them?
         – Get a user to click: <a href=“the_scheme://stuff?param=value” />
         – Get a user to visit a malicious web page:
           <iframe src=“the_scheme://stuff?param=value” />


 • Approaches:
         – Fuzzing
         – Targeted attacks




© Copyright 2011 Denim Group - All Rights Reserved                            39
Implementing Secure Content Handlers
 • This is remotely-accessible attack surface
 • Ask yourself: Do you really need to expose this attack surface?

 • Of course you do, think of how cool this will be…

 • Treat that as any untrusted input
         – Positive validation
         – Design logic accordingly




© Copyright 2011 Denim Group - All Rights Reserved                   40
Where Does Tainted Data Come From?
 • Android:
         – Activity.getIntent().getData()


 • iOS:
         – handleOpenURL() – Now deprecated
         – openURL() – New method – complete w/ naming conflict




© Copyright 2011 Denim Group - All Rights Reserved                41
Interlude: SQL Injection for Mobile Applications
 • iOS and Android both provide built-in access to SQLite databases
 • Validate input and properly encode it before including it in SQL queries

 • Android
         – query(), rawQuery() – Be careful
         – compileStatement() – Better, but still be careful


 • iOS
         – sqlite3_exec() – Be careful
         – sqlite3_prepare_v2() – Better, but still be careful
         – iOS SQLite has such an elegant syntax, doesn’t it?




© Copyright 2011 Denim Group - All Rights Reserved                            42
But How Bad is SQL Injection in Mobile Apps?
 • Probably not as bad as SQL injection for web applications
         – Probably


 • Remember DREAD:
         –     Damage Potential
         –     Reproducibility
         –     Exploitability
         –     Affected Users
         –     Discoverability




© Copyright 2011 Denim Group - All Rights Reserved             43
4 – Platform-Specific Concerns
 • Secure Coding Practices for the iOS Platform
         – Buffer overflows and format strings
         – Everything old is new again
         – Objective-C is a superset of “actual” C – enjoy




© Copyright 2011 Denim Group - All Rights Reserved           44
Let’s Take Apart Some Apps: Android

 • Example of static                                 • axml2xml.pl
                                                       –   http://code.google.com/p/android-random/downloads/detail?name=axml2xml.pl

   binary analysis
                                                     • dedexer
                                                       – http://dedexer.sourceforge.net/
 • Application structure                             • dex2jar
         –     AndroidManifest.xml                     – http://code.google.com/p/dex2jar/

         –     assets/                               • JD-GUI
         –     res/                                    – http://java.decompiler.free.fr/

         –     classes.dex                           • SQLite Browser
                                                       – http://java.decompiler.free.fr/

© Copyright 2011 Denim Group - All Rights Reserved                                                                                     45
Other Materials
 • www.smartphonesdumbapps.com – Denim Group presentations,
   slides and code for mobile application security
 • http://software-security.sans.org/downloads/appsec-2011-
   files/dhanjani-hacking-securing-next-gen.pdf - SANS APPSEC
   SUMMIT 2011 presentation from Nitesh Dhanjani and Sean Pennline
 • http://www.slideshare.net/SOURCEConference/david-thiel-secure-
   development-on-ios - SOURCE Boston 2011 presentation from David
   Thiel from iSecPartners
 • McAfee mobile pen testing guidelines:
         – http://www.mcafee.com/us/resources/white-papers/foundstone/wp-pen-testing-
           iphone-ipad-apps.pdf
         – http://www.mcafee.com/us/resources/white-papers/foundstone/wp-pen-testing-
           android-apps.pdf



© Copyright 2011 Denim Group - All Rights Reserved                                      46
5 – Conclusions and Questions
 Dan Cornell
 dan@denimgroup.com
 @danielcornell

 www.denimgroup.com
 www.smartphonesdumbapps.com
 (210) 572-4400




© Copyright 2011 Denim Group - All Rights Reserved   47

More Related Content

PPTX
Serverless Architecture
PPTX
Website upgrade strategy
PPTX
Amazon ec2
PPT
Security Exploit of Business Logic Flaws, Business Logic Attacks
PDF
Infrastructure as Code for Beginners
PPTX
SharePoint Overview
PDF
AWS Summit Seoul 2023 | SK와 함께하는 AWS Migration Journey & App Modernization 전략
PDF
OWASP Top 10 API Security Risks
Serverless Architecture
Website upgrade strategy
Amazon ec2
Security Exploit of Business Logic Flaws, Business Logic Attacks
Infrastructure as Code for Beginners
SharePoint Overview
AWS Summit Seoul 2023 | SK와 함께하는 AWS Migration Journey & App Modernization 전략
OWASP Top 10 API Security Risks

What's hot (20)

ODP
Introduction to Amazon Web Services
PPTX
ASP.NET with VB.NET
PDF
AWS를 활용한 상품 추천 서비스 구축::김태현:: AWS Summit Seoul 2018
PPTX
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
PDF
서버리스 기반 콘텐츠 추천 서비스 만들기 - 이상현, Vingle :: AWS Summit Seoul 2019
PPTX
Data Loss Prevention in Office 365
PDF
Fundamentals of Cloud Computing & AWS
PDF
Serverless Microservices Communication with Amazon EventBridge
PPTX
Patch Management Best Practices 2019
PPT
Best practises for log management
PDF
Microsoft Cloud's Front Door: Building a Global API
PPTX
NIST CSF Overview
PPT
Intro to Amazon S3
PPTX
Pentesting iOS Applications
PDF
Stopping zero day threats
PDF
AWS Summit Seoul 2023 | 클라우드 정책의 현재와 미래: 전문가 대담
PPT
Rhapsody Systems Software
PDF
Microsoft 365 Compliance
PPTX
iOS-Application-Security-iAmPr3m
Introduction to Amazon Web Services
ASP.NET with VB.NET
AWS를 활용한 상품 추천 서비스 구축::김태현:: AWS Summit Seoul 2018
Going Beyond Microsoft IIS Short File Name Disclosure - NahamCon 2023 Edition
서버리스 기반 콘텐츠 추천 서비스 만들기 - 이상현, Vingle :: AWS Summit Seoul 2019
Data Loss Prevention in Office 365
Fundamentals of Cloud Computing & AWS
Serverless Microservices Communication with Amazon EventBridge
Patch Management Best Practices 2019
Best practises for log management
Microsoft Cloud's Front Door: Building a Global API
NIST CSF Overview
Intro to Amazon S3
Pentesting iOS Applications
Stopping zero day threats
AWS Summit Seoul 2023 | 클라우드 정책의 현재와 미래: 전문가 대담
Rhapsody Systems Software
Microsoft 365 Compliance
iOS-Application-Security-iAmPr3m
Ad

Viewers also liked (20)

PDF
Developing Secure Mobile Applications
PDF
Security Code Review for .NET - Sherif Koussa (OWASP Ottawa)
PDF
Objective briefing on the current mobile threat 2010/2011
PPTX
Understanding android security model
PPTX
Android vs iOS encryption systems
PPT
Mobile application security and threat modeling
PDF
Designing Secure Mobile Apps
PDF
When Ajax Attacks! Web application security fundamentals
ODP
Mobile App Security Testing -2
PPTX
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
PPTX
Automated Security Analysis of Android & iOS Applications with Mobile Securit...
PPTX
G4H Webcast: Automated Security Analysis of Mobile Applications with Mobile S...
PDF
Java Web Application Security - Denver JUG 2013
PPTX
Mobile Application Security
PDF
Mobile_app_security
PDF
SN-Security Architecture for Mobile Computing and IoT
PPTX
The curious case of mobile app security.pptx
PPT
2010: Mobile Security - WHYMCA Developer Conference
PDF
Nullcon Goa 2016 - Automated Mobile Application Security Testing with Mobile ...
PPTX
CDIC 2013-Mobile Application Pentest Workshop
Developing Secure Mobile Applications
Security Code Review for .NET - Sherif Koussa (OWASP Ottawa)
Objective briefing on the current mobile threat 2010/2011
Understanding android security model
Android vs iOS encryption systems
Mobile application security and threat modeling
Designing Secure Mobile Apps
When Ajax Attacks! Web application security fundamentals
Mobile App Security Testing -2
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
Automated Security Analysis of Android & iOS Applications with Mobile Securit...
G4H Webcast: Automated Security Analysis of Mobile Applications with Mobile S...
Java Web Application Security - Denver JUG 2013
Mobile Application Security
Mobile_app_security
SN-Security Architecture for Mobile Computing and IoT
The curious case of mobile app security.pptx
2010: Mobile Security - WHYMCA Developer Conference
Nullcon Goa 2016 - Automated Mobile Application Security Testing with Mobile ...
CDIC 2013-Mobile Application Pentest Workshop
Ad

Similar to Mobile Application Security Code Reviews (20)

PDF
Security Testing Mobile Applications
PDF
Smart Phones Dumb Apps
PPTX
Building a Mobile Security Program
PPT
Mobile Apps Security
PDF
CNIT 128 8: Mobile development security
PDF
C0c0n 2011 mobile security presentation v1.2
PPT
Mobile code mining for discovery and exploits nullcongoa2013
PDF
Pentesting Mobile Applications (Prashant Verma)
PDF
Dirty Little Secret - Mobile Applications Invading Your Privacy
PPTX
Virtue Security - The Art of Mobile Security 2013
PPTX
Workshop 12-06 - Architectures for Enterprise Mobile Applications
PDF
Application Security framework for Mobile App Development in Enterprise Setup
PPTX
Windows Phone 8 Security and Testing WP8 Apps
PDF
There's an App for That: Digital Forensic Realities for Mobile App Evidence, ...
PPTX
Webinar on Enterprise Security & android
PDF
Info security - mobile approach
PPTX
How iOS and Android Handle Security Webinar
PDF
Mobile Application Security
PPTX
Mobile Application Security
PPTX
Mobile application securitry risks ISACA Silicon Valley 2012
Security Testing Mobile Applications
Smart Phones Dumb Apps
Building a Mobile Security Program
Mobile Apps Security
CNIT 128 8: Mobile development security
C0c0n 2011 mobile security presentation v1.2
Mobile code mining for discovery and exploits nullcongoa2013
Pentesting Mobile Applications (Prashant Verma)
Dirty Little Secret - Mobile Applications Invading Your Privacy
Virtue Security - The Art of Mobile Security 2013
Workshop 12-06 - Architectures for Enterprise Mobile Applications
Application Security framework for Mobile App Development in Enterprise Setup
Windows Phone 8 Security and Testing WP8 Apps
There's an App for That: Digital Forensic Realities for Mobile App Evidence, ...
Webinar on Enterprise Security & android
Info security - mobile approach
How iOS and Android Handle Security Webinar
Mobile Application Security
Mobile Application Security
Mobile application securitry risks ISACA Silicon Valley 2012

More from Denim Group (20)

PDF
Long-term Impact of Log4J
PDF
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
PDF
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
PDF
Optimizing Security Velocity in Your DevSecOps Pipeline at Scale
PDF
Application Asset Management with ThreadFix
PDF
OWASP San Antonio Meeting 10/2/20
PDF
AppSec Fast and Slow: Your DevSecOps CI/CD Pipeline Isn’t an SSA Program
PDF
Using Collaboration to Make Application Vulnerability Management a Team Sport
PDF
Managing Penetration Testing Programs and Vulnerability Time to Live with Thr...
PDF
Security Champions: Pushing Security Expertise to the Edges of Your Organization
PDF
The As, Bs, and Four Cs of Testing Cloud-Native Applications
PDF
An Updated Take: Threat Modeling for IoT Systems
PPTX
Continuous Authority to Operate (ATO) with ThreadFix – Bringing Commercial In...
PDF
A New View of Your Application Security Program with Snyk and ThreadFix
PDF
Enabling Developers in Your Application Security Program With Coverity and Th...
PDF
AppSec in a World of Digital Transformation
PDF
The As, Bs, and Four Cs of Testing Cloud-Native Applications
PDF
Enabling Developers in Your Application Security Program With Coverity and Th...
PDF
AppSec in a World of Digital Transformation
PDF
Enumerating Enterprise Attack Surface
Long-term Impact of Log4J
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Threat Modeling the CI/CD Pipeline to Improve Software Supply Chain Security ...
Optimizing Security Velocity in Your DevSecOps Pipeline at Scale
Application Asset Management with ThreadFix
OWASP San Antonio Meeting 10/2/20
AppSec Fast and Slow: Your DevSecOps CI/CD Pipeline Isn’t an SSA Program
Using Collaboration to Make Application Vulnerability Management a Team Sport
Managing Penetration Testing Programs and Vulnerability Time to Live with Thr...
Security Champions: Pushing Security Expertise to the Edges of Your Organization
The As, Bs, and Four Cs of Testing Cloud-Native Applications
An Updated Take: Threat Modeling for IoT Systems
Continuous Authority to Operate (ATO) with ThreadFix – Bringing Commercial In...
A New View of Your Application Security Program with Snyk and ThreadFix
Enabling Developers in Your Application Security Program With Coverity and Th...
AppSec in a World of Digital Transformation
The As, Bs, and Four Cs of Testing Cloud-Native Applications
Enabling Developers in Your Application Security Program With Coverity and Th...
AppSec in a World of Digital Transformation
Enumerating Enterprise Attack Surface

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Modernizing your data center with Dell and AMD
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
KodekX | Application Modernization Development
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
Building Integrated photovoltaic BIPV_UPV.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Modernizing your data center with Dell and AMD
Review of recent advances in non-invasive hemoglobin estimation
Understanding_Digital_Forensics_Presentation.pptx
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
KodekX | Application Modernization Development

Mobile Application Security Code Reviews

  • 1. Mobile App Security Code Reviews Security BSides Las Vegas 2011 © Copyright 2011 Denim Group - All Rights Reserved
  • 2. Instructor Dan Cornell dan@denimgroup.com @danielcornell www.denimgroup.com www.smartphonesdumbapps.com (210) 572-4400 © Copyright 2011 Denim Group - All Rights Reserved 1
  • 3. My Background • Dan Cornell – Founder and CTO Denim Group • Software developer by background (Java, .NET, etc.) • Denim Group – Build software with special security, performance, reliability requirements – Help organizations deal with the risk associated with their software • Code reviews and application assessments • SDLC consulting • Secure development training – instructor-led and e-Learning © Copyright 2011 Denim Group - All Rights Reserved 2
  • 4. Agenda 1. Introduction and Overview 2. Data: In Motion and at Rest 3. Other Dangerous Inputs 4. Platform-Specific Concerns 5. Conclusions / Questions © Copyright 2011 Denim Group - All Rights Reserved 3
  • 5. 1 – Introduction and Overview • Focus For This Class • Security Implications for Mobile Applications • Mobile Application Threat Model • Testing the Security of Mobile Applications • Platform Background – Android – iOS © Copyright 2011 Denim Group - All Rights Reserved 4
  • 6. Tradeoffs: Value versus Risk • Mobile applications can create tremendous value for organizations – New classes of applications utilizing mobile capabilities: GPS, camera, etc. – Innovating applications for employees and customers • Mobile devices and mobile applications can create tremendous risks – Sensitive data inevitably stored on the device (email, contacts) – Connect to a lot of untrusted networks (carrier, WiFi) • Most developers are not trained to develop secure applications – Fact of life, but slowing getting better • Most developers are new to creating mobile applications – Different platforms have different security characteristics and capabilities © Copyright 2011 Denim Group - All Rights Reserved 5
  • 7. Smart Phones, Dumb Apps • Lots of media focus on device and platform security – Important because successful attacks give tremendous attacker leverage • Most organizations: – Accept realities of device and platform security – Concerned about the security of their custom applications – Concerned about sensitive data on the device because of their apps – Concerned about network-available resources that support their apps • Who has mobile application deployed for customers? • Who has had mobile applications deployed without their knowledge? – *$!%$# marketing department… © Copyright 2011 Denim Group - All Rights Reserved 6
  • 8. Generic Mobile Application Threat Model © Copyright 2011 Denim Group - All Rights Reserved 7
  • 9. Some Assumptions for Developers • Smartphone applications are essentially thick-client applications – That people carry in their pockets – And drop in toilets – And put on eBay when the new iPhone comes out – And leave on airplanes – And so on… • Attackers will be able to access: – Target user (victim) devices – Your application binaries • What else should you assume they know or will find out? © Copyright 2011 Denim Group - All Rights Reserved 8
  • 10. Testing the Security of Mobile Applications • IMPORTANT: It is really the system as a whole you care about – Application plus… – 3rd party web services – Enterprise services – And so on • The most “interesting” weaknesses and vulnerabilities we find are in mobile applications’ interactions with supporting services • Mobile applications are different than web applications – Can’t just fire up an automated scanner and turn up a bunch of SQL injection and XSS vulnerabilities – Usually… © Copyright 2011 Denim Group - All Rights Reserved 9
  • 11. Testing the Security of Mobile Applications Type of Analysis Activities Static Analysis Source Code Source code scanning Manual source code review Binary Reverse engineering Dynamic Analysis Debugger execution Traffic capture via proxy Forensic Analysis File permission analysis File content analysis © Copyright 2011 Denim Group - All Rights Reserved 10
  • 12. Platform Background: Android • Linux-based operating system • Applications typically written in Java • Java compiled to DEX bytecode for the Dalvik virtual machine – Kind of like a Java virtual machine – Register-based rather than stack-based © Copyright 2011 Denim Group - All Rights Reserved 11
  • 13. Platform Background: • UNIX-based operating system • Applications written in Objective-C © Copyright 2011 Denim Group - All Rights Reserved 12
  • 14. Pandemobium Stock Trader Application • Android and iOS versions • Functionality – Log in – Track stock tips – Make stock trades – Get stock tips – Share stock tips • We will use as an example through the class © Copyright 2011 Denim Group - All Rights Reserved 13
  • 15. 2 – Data: In Motion and at Rest • Local Data Storage • Consuming 3rd Party Web Services • Mobile Applications and Enterprise Services © Copyright 2011 Denim Group - All Rights Reserved 14
  • 16. Local Data Storage • Overview • Identifying Potential Storage Issues • Encryption Best Practices © Copyright 2011 Denim Group - All Rights Reserved 15
  • 17. Local Data Storage Overview • If you store data on the device it can be captured – How you store the data can impact how easy this is – But at the end of the day it can be captured – So be careful what you store on the device. And be careful how you store it • But what if I encrypt the data? – Great idea. Where are you going to store the key? • This is an issue that gets a lot of media attention © Copyright 2011 Denim Group - All Rights Reserved 16
  • 18. Local Data Storage: Android • Files – Internal storage (file permissions enforced) – External storage (no file permissions enforced) • SQLite Databases • Shared Preferences • Web Cache © Copyright 2011 Denim Group - All Rights Reserved 17
  • 19. Android Data Storage • In Android, every application gets its own uid/gid – Clever use of the Linux security model – But external storage does not have permission enforcement • Default permissions are to be readable and writeable by the app only – Files – SQLite databases – Shared Permissions – Context.MODE_PRIVATE • But of course you can override this – Context.MODE_WORLD_READABLE – Context.MODE_WORLD_WRITEABLE © Copyright 2011 Denim Group - All Rights Reserved 18
  • 20. Local Data Storage: • Files • SQLite Databases • plist Files • Keychain • Web Cache © Copyright 2011 Denim Group - All Rights Reserved 19
  • 21. Android Static Analysis for Storage Issues • Android-specific functions for file handling: – Context.openFileOutput() – Context.openFileInput() – Context.getDir() • Android-specific functions for SQLite database handling: – Context.openOrCreateDatabase() – Context.getDatabasePath() – SQLiteDatabase.openDatabase() © Copyright 2011 Denim Group - All Rights Reserved 20
  • 22. Android Static Analysis for Storage Issues • Android-specific functions for Shared Preferences handling – Context.getSharedPreferences() • Android-specific functions for cache handling: – Context.getCacheDir() – Context.getExternalCacheDir() • Non-Android-specific functions – Anything else you would examine in Java – java.io and the like © Copyright 2011 Denim Group - All Rights Reserved 21
  • 23. Android Static Analysis for Storage Issues • File permissions: – MODE_PRIVATE – generally all right – MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE – why? • What is being stored? • How is it being used? • World readable/writeable files can be manipulated by malicious applications © Copyright 2011 Denim Group - All Rights Reserved 22
  • 24. iOS Static Analysis for Storage Issues • NSFileManager class – NSFileProtectionKey attribute • NSFileProtectionNone – Always accessible • NSFileProtectionComplete – Encrypted on disk when device is locked or booting • UIApplicationProtectedDataWillBecomeUnavailable notification – Fired when application data is about to become unavailable – References to sensitive files should be dropped © Copyright 2011 Denim Group - All Rights Reserved 23
  • 25. Encryption Best Practices • Key management is a huge problem • If encrypted data and the key are stored on the device… • Android Encryption – Access to javax.crypto libraries – Open source options like Bouncy Castle • iOS Encryption – Access to common crypto algorithms – Keychain available for encrypted storage © Copyright 2011 Denim Group - All Rights Reserved 24
  • 26. iOS Keychain • Allows you to store key/value pairs using iOS protections • Default: only visible to “owning” application • Possible values for kSecAttrAccessible: – kSecAttrAccessibleWhenUnlocked – kSecAttrAccessibleAfterFirstUnlock – kSecAttrAccessibleAlways – kSecAttrAccessibleWhenUnlockedThisDeviceOnly – kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly – kSecAttrAccessibleAlwaysThisDeviceOnly • But… – Clever German researchers found out how to dump non-PIN protected data – And clever Russian researchers found out how to brute-force the PIN – Do not store sensitive data on the device © Copyright 2011 Denim Group - All Rights Reserved 25
  • 27. Consuming 3rd Party Web Services • Overview • Identifying Services In Use • Data Communications and Handling Best Practices © Copyright 2011 Denim Group - All Rights Reserved 26
  • 28. Overview of Consuming 3rd Party Web Services • Interesting apps need to talk to stuff – And most of that stuff you should not trust • These are untrusted inputs – Positively validate them before use • You do not control what they do with the data – Be careful what you send © Copyright 2011 Denim Group - All Rights Reserved 27
  • 29. Identifying Services In Use • Look for URL connections • Look for network connections • Look for web controls © Copyright 2011 Denim Group - All Rights Reserved 28
  • 30. Data Communications and Handling Best Practices • Remember: Mobile devices can talk on lots of different networks • So use SSL – Can not observe or change traffic – DNS concerns • And force it to be used correctly – With valid certificates • Be careful of caching © Copyright 2011 Denim Group - All Rights Reserved 29
  • 31. Android Network Connections • Android-specific classes: – android.net.* – android.net.SSLCertificateFactory • Make sure server validation has not been turned off • Java platform classes: – java.net.URLConnection – java.net.URL – And so on… © Copyright 2011 Denim Group - All Rights Reserved 30
  • 32. Android Network Connections • Included Apache classes: – org.apache.http.HttpClient – org.apache.http.HttpPost – org.apache.http.Response • WebView component – Include HTML content in web applications © Copyright 2011 Denim Group - All Rights Reserved 31
  • 33. iOS Network Connections • CFStream – kCFStreamPropertyShouldCloseNativeSocket – kCFStreamPropertySocketSecurityLevel – kCFStreamPropertySOCKSProxy – kCFStreamPropertySSLPeerCertificates – kCFStreamPropertySSLPeerTrust – kCFStreamPropertySSLSettings • CFHost • NSStream • NSHost • NSURLDownload • NSURL • UIWebView © Copyright 2011 Denim Group - All Rights Reserved 32
  • 34. What to do With 3rd Party Services? • Largest concern is how they impact YOUR security – Validate all input – Be careful how your logic treats the data – Be careful what you send © Copyright 2011 Denim Group - All Rights Reserved 33
  • 35. Overview of Mobile Applications and Enterprise Services • If you were a bad guy, would you rather have – The data on one device – All the data on the server – I guess it depends on how advanced and persistent you are… • These provide a great window into your organization – Client data – Transaction data – And so on… • The most serious vulnerabilities we find in assessments deal with apps’ interactions with enterprise services © Copyright 2011 Denim Group - All Rights Reserved 34
  • 36. 3 – Other Dangerous Inputs • Mobile Browser Content Handling © Copyright 2011 Denim Group - All Rights Reserved 35
  • 37. Mobile Browser Content Handling • Identifying Mobile Browser Content Handlers • Testing the Security of Content Handlers © Copyright 2011 Denim Group - All Rights Reserved 36
  • 38. Android: Identifying Content Handlers • Look in AndroidManifest.xml • Look for <intent-filter> tags: <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme=“the_scheme" /> </intent-filter> • But what apps export intents? – http://www.openintents.org/ © Copyright 2011 Denim Group - All Rights Reserved 37
  • 39. iOS: Identifying Content Handlers • Look in Info.plist • Look for <key>CFBundleURLSchemes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>the_scheme</string> </array> </dict> </array> • But what apps handle custom schemes? – http://handleopenurl.com/ © Copyright 2011 Denim Group - All Rights Reserved 38
  • 40. Testing the Security of Content Handlers • How to reach them? – Get a user to click: <a href=“the_scheme://stuff?param=value” /> – Get a user to visit a malicious web page: <iframe src=“the_scheme://stuff?param=value” /> • Approaches: – Fuzzing – Targeted attacks © Copyright 2011 Denim Group - All Rights Reserved 39
  • 41. Implementing Secure Content Handlers • This is remotely-accessible attack surface • Ask yourself: Do you really need to expose this attack surface? • Of course you do, think of how cool this will be… • Treat that as any untrusted input – Positive validation – Design logic accordingly © Copyright 2011 Denim Group - All Rights Reserved 40
  • 42. Where Does Tainted Data Come From? • Android: – Activity.getIntent().getData() • iOS: – handleOpenURL() – Now deprecated – openURL() – New method – complete w/ naming conflict © Copyright 2011 Denim Group - All Rights Reserved 41
  • 43. Interlude: SQL Injection for Mobile Applications • iOS and Android both provide built-in access to SQLite databases • Validate input and properly encode it before including it in SQL queries • Android – query(), rawQuery() – Be careful – compileStatement() – Better, but still be careful • iOS – sqlite3_exec() – Be careful – sqlite3_prepare_v2() – Better, but still be careful – iOS SQLite has such an elegant syntax, doesn’t it? © Copyright 2011 Denim Group - All Rights Reserved 42
  • 44. But How Bad is SQL Injection in Mobile Apps? • Probably not as bad as SQL injection for web applications – Probably • Remember DREAD: – Damage Potential – Reproducibility – Exploitability – Affected Users – Discoverability © Copyright 2011 Denim Group - All Rights Reserved 43
  • 45. 4 – Platform-Specific Concerns • Secure Coding Practices for the iOS Platform – Buffer overflows and format strings – Everything old is new again – Objective-C is a superset of “actual” C – enjoy © Copyright 2011 Denim Group - All Rights Reserved 44
  • 46. Let’s Take Apart Some Apps: Android • Example of static • axml2xml.pl – http://code.google.com/p/android-random/downloads/detail?name=axml2xml.pl binary analysis • dedexer – http://dedexer.sourceforge.net/ • Application structure • dex2jar – AndroidManifest.xml – http://code.google.com/p/dex2jar/ – assets/ • JD-GUI – res/ – http://java.decompiler.free.fr/ – classes.dex • SQLite Browser – http://java.decompiler.free.fr/ © Copyright 2011 Denim Group - All Rights Reserved 45
  • 47. Other Materials • www.smartphonesdumbapps.com – Denim Group presentations, slides and code for mobile application security • http://software-security.sans.org/downloads/appsec-2011- files/dhanjani-hacking-securing-next-gen.pdf - SANS APPSEC SUMMIT 2011 presentation from Nitesh Dhanjani and Sean Pennline • http://www.slideshare.net/SOURCEConference/david-thiel-secure- development-on-ios - SOURCE Boston 2011 presentation from David Thiel from iSecPartners • McAfee mobile pen testing guidelines: – http://www.mcafee.com/us/resources/white-papers/foundstone/wp-pen-testing- iphone-ipad-apps.pdf – http://www.mcafee.com/us/resources/white-papers/foundstone/wp-pen-testing- android-apps.pdf © Copyright 2011 Denim Group - All Rights Reserved 46
  • 48. 5 – Conclusions and Questions Dan Cornell dan@denimgroup.com @danielcornell www.denimgroup.com www.smartphonesdumbapps.com (210) 572-4400 © Copyright 2011 Denim Group - All Rights Reserved 47