Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deep Dive into Android Static Analysis and Exploitation

Deep Dive into Android Static Analysis and Exploitation

Presented by Gaurang Bhatnagar ar Optiv SourceZeroCon 2021.

Gaurang Bhatnagar

July 18, 2021
Tweet

Other Decks in Research

Transcript

  1. 2 ABOUT THE RESEARCH Case Studies from Popular Applications Mainly

    focused on Custom URI Schemes and Webview Exploitation Performed Code Review on Popular Applications (100+) Found interesting Scenarios and Misconfigurations
  2. 4 PROJECT - INSECURESHOP • Vulnerable Android app built in

    Kotlin • Real-World Vulnerabilities • Based on my research on URI Scheme and WebView Exploitation • Replicates Vulnerabilities disclosed by Well-Known Mobile Researchers
  3. WHAT ARE DEEPLINKS? 6 • Deeplink are specific URIs which

    sends users directly into a specific point in the app, rather than opening an external website • Helps users to navigate between web and mobile apps
  4. DEEPLINK ABUSE IMPACT XSS: Possible if setJavaScriptEnabled(true) is set in

    Webview. Theft of Auth tokens: May result in account takeover if authentication tokens are passed to websites that are opened in webview. Phishing: Possible If you can load any arbitrary URL in Webview. Load Local files in webview: Possible if setAllowFileAccess(true) is set in Webview. DOS: Possible if a malformed deeplink can be used to crash the application.
  5. CVE-2017-13274 • There was a problem in android.net.Uri and java.net.URI

    parsers. These parsers don't recognize backslashes in authority part Payload: http://attacker.com\\\\@legitimate.com/smth • CVE-2017-13274 - Fixed for API level 28 and above
  6. 21 OAUTH ATTACK VECTOR – REDIRECT URI Developers often fail

    to validate Redirect URI parameter, thus allowing attackers to steal access tokens. A lack of scheme validation may also lead to leak of access tokens. Redirect URLs are a critical part of the OAuth flow. After a user successfully authorizes an application, the authorization server will redirect the user back to the application with either an authorization code or access token in the URL.
  7. REMOTE THEFT OF SESSION COOKIES There are following Pre-Requisites: •

    If you can load any arbitrary URL in Webview • If setJavaScriptEnabled(true) is set in Webview [Disabled by default] • If setAllowFileAccess(true) is set in Webview [Enabled by default]
  8. REMOTE THEFT OF SESSION COOKIES Malicious app sends an intent

    with url which loads attacker provided html file in webview. http://attackerdomain.com/symlink/set_cookies.html
  9. The Malicious app creates a symlink with .html extention (symlink.html)

    to force webview parse database file as a HTML file. ln -s /data/data/com.target/app_webview/Cookies /data/data/com.hack/symlink.html
  10. When symlink.html file is loaded in webview, JavaScript payload is

    triggered which sends data to the attacker domain.
  11. REMOTE THEFT OF ALL FILES There are following Pre-Requisites: •

    If you can load any arbitrary URL in Webview • If target app can read data from External storage <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> • If setAllowUniversalAccessFromFileURLs(true) is set in Webview [Disabled by default]
  12. 35 ACCESS TO PROTECTED COMPONENTS As researched by OVERSECURED, It

    was found that more than 80% of apps contain this vulnerability. DEVELOPERS often create proxy components (activities, broadcast receivers and services) that take an embedded Intent and pass it to dangerous methods like startActivity(...), sendBroadcast(...), etc.
  13. 41 EXPLICIT VS IMPLICIT INTENT EXPLICIT IMPLICIT Explicitly specify the

    name of the component to be invoked by activity and we use explicit intents to start a component in our own app. Does not specify any name of the component to start. Instead, it declares an action to perform and allows a component from other apps to handle it. INTENT
  14. IMPLICIT INTENT Intent Explicit Implicit Implicit intent used to send

    a broadcast Implicit intent used to launch an activity
  15. 45 INTENT INTERCEPTION (BROADCAST) • Since Android Oreo, implicit broadcast

    receivers won’t work when registered in the AndroidManifest.xml. • To use Implicit Receivers in your application, you need to define them programmatically in your code, using registerReceiver().
  16. SUMMARIZING DEMO Intent Explicit Exploited Broadcast Receiver Loaded untrusted URL

    in webview Access to Content Provider with android:grantUriPermissions=“true”
  17. SUMMARIZING DEMO (CONTINUED…) Intent Explicit Insecure use of File Paths

    in FileProvider Code Execution by Overwriting Native Library Ability to read and overwrite internal app files Yet to implement in InsecureShop…
  18. SUMMARIZING DEMO (CONTINUED…) Intent Explicit placed Malicious HTML file in

    sdcard Data exfiltrated to remote domain Malicious HTML file is called via file:// scheme Webview used “setAllowUniversalAccessFromFileURLs=true”
  19. LACK OF SSL VALIDATION Android apps are often coded in

    such a way that it ignores any kind of SSL warning and proceeds with an attacker provided certificate. This makes an app vulnerable to MITM attacks.
  20. 54

  21. 55 COMMON QUESTIONS • How are you going to exploit

    this in a real scenario? • How are you going to issue an attacker provided certificate to the Android user and capture the traffic originating from their device?
  22. HARDCODED API KEYS AND SECRET KeyHacks shows ways in which

    particular API keys found on a Bug Bounty Program can be used, to check if they are valid.
  23. 63 TAKEAWAYS Most of the time developers don’t add scheme

    and host validation check or either they don’t implement that correctly. Loading arbitrary URL in webview may give you authentication tokens. Also, try to exfiltrate data from local sandbox to the remote domain (depending on the webview properties enabled). Note, Google has fixed the Symlink attack as part of the system webview update. So symlink attack won’t work on latest android devices or devices with the updated system webview. IPC components can introduce many vulnerabilities if not properly configured
  24. 64 TAKEAWAYS Expand your attack surface to non-exported components. Developers

    often pass sensitive data via Implicit intents which can be intercepted by other apps on the device MITM vulnerabilities are too common in android apps. Developers often override SSL error which makes app vulnerable to MITM attack (eg. Unsafe implementation of onReceivedSslError ). Hardcoding API keys and secrets in mobile app is common. You must understand the purpose of hardcoding these keys, check the API docs and see if the keys are supposed to be public or private
  25. 65 OPTIV RESOURCES • InsecureShop App (https://github.com/optiv/Insecureshop) • Nuclei Templates

    (https://github.com/optiv/mobile-nuclei-templates) • Optiv Source Zero Blog (https://www.optiv.com/insights/source-zero)
  26. 66 ADDITIONAL RESOURCES • https://github.com/streaak/keyhacks • https://hackerone.com/reports/431002 • https://blog.oversecured.com/Interception-of-Android-implicit-intents •

    https://blog.oversecured.com/Evernote-Universal-XSS-theft-of-all- cookies-from-all-sites-and-more • https://blog.mzfr.me/posts/2020-11-07-exported-activities/ • https://medium.com/@dPhoeniixx/tiktok-for-android-1-click-rce- 240266e78105