overview.md (71790B)
1 --- 2 title: "Android Applications Pentesting" 3 section: "Mobile" 4 sectionSlug: "mobile-pentesting" 5 sourcePath: "src/mobile-pentesting/android-app-pentesting/README.md" 6 sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/README.md" 7 sha: "188de82beb54e70956b2952367a0af91d26758b8" 8 isIndex: true 9 modified: true 10 license: "CC-BY-NC-4.0" 11 --- 12 13 # Android Applications Pentesting 14 15 [Dds Rtps Security](https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/generic-methodologies-and-resources/pentesting-network/dds-rtps-security.md) 16 17 ## Android Applications Basics 18 19 It's highly recommended to start reading this page to know about the **most important parts related to Android security and the most dangerous components in an Android application**: 20 21 22 [Android Applications Basics](/hacktricks/mobile-pentesting/android-app-pentesting/android-applications-basics) 23 24 For broader study, combine the OWASP Mobile Application Security project with Android reverse-engineering courses and practical security guides. The Android App Reverse Engineering 101 course, Manifest Security series, Android-Security-Teryaagh notes, Mobile Hacking Workshop, and Application Security Wiki provide complementary labs, methodology, and tool references.<sup>[[2]](#references)[[3]](#references)[[4]](#references)[[5]](#references)[[6]](#references)[[17]](#references)</sup> 25 26 ## ADB (Android Debug Bridge) 27 28 This is the main tool you need to connect to an android device (emulated or physical).\ 29 **ADB** allows to control devices either over **USB** or **Network** from a computer. This utility enables the **copying** of files in both directions, **installation** and **uninstallation** of apps, **execution** of shell commands, **backing up** of data, **reading** of logs, among other functions. 30 31 See the [**ADB Commands**](/hacktricks/mobile-pentesting/android-app-pentesting/adb-commands) page to learn how to use ADB. 32 33 ## Smali 34 35 Sometimes it is useful to **modify application code** to access **hidden information**, such as well-obfuscated passwords or flags. You can decompile the APK, modify its Smali code, and rebuild it.\ 36 [**This tutorial explains how to decompile an APK, modify Smali, and recompile it with new functionality**](/hacktricks/mobile-pentesting/android-app-pentesting/smali-changes). Keep this option in mind as an alternative when performing dynamic-analysis tests. 37 38 ## Other interesting tricks 39 40 - [Spoofing your location in Play Store](/hacktricks/mobile-pentesting/android-app-pentesting/spoofing-your-location-in-play-store) 41 - [Play Integrity attestation spoofing (SafetyNet replacement)](/hacktricks/mobile-pentesting/android-app-pentesting/play-integrity-attestation-bypass)<sup>[[1]](#references)</sup> 42 - [Android app-level virtualization / app cloning abuse & detection](/hacktricks/mobile-pentesting/android-app-pentesting/android-application-level-virtualization) 43 - [Shizuku Privileged API (ADB-based non-root privileged access)](/hacktricks/mobile-pentesting/android-app-pentesting/shizuku-privileged-api) 44 45 [Futex Pi Uaf Pipe Buffer Workqueue Usermodehelper](https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/binary-exploitation/linux-kernel-exploitation/futex-pi-uaf-pipe-buffer-workqueue-usermodehelper.md) 46 47 - [Exploiting Insecure In-App Update Mechanisms](/hacktricks/mobile-pentesting/android-app-pentesting/insecure-in-app-update-rce) 48 - [Abusing Accessibility Services (Android RAT)](/hacktricks/mobile-pentesting/android-app-pentesting/accessibility-services-abuse) 49 - [Android IME / InputMethodService Abuse (Malicious Keyboards)](/hacktricks/mobile-pentesting/android-app-pentesting/inputmethodservice-ime-abuse) 50 - [NFC/EMV Relay via HCE (Android Tap-to-Pay abuse)](/hacktricks/mobile-pentesting/android-app-pentesting/android-hce-nfc-emv-relay-attacks) 51 - [Android POS payment sockets / ISO 8583 backend abuse](/hacktricks/network-services-pentesting/pentesting-iso-8583-payment-sockets)<sup>[[15]](#references)</sup> 52 - **Download APKs**: [https://apps.evozi.com/apk-downloader/](https://apps.evozi.com/apk-downloader/), [https://apkpure.com/es/](https://apkpure.com/es/), [https://www.apkmirror.com/](https://www.apkmirror.com), [https://apkcombo.com/es-es/apk-downloader/](https://apkcombo.com/es-es/apk-downloader/), [https://github.com/kiber-io/apkd](https://github.com/kiber-io/apkd) 53 54 ## Insecure proximity / file-transfer protocols 55 56 Some Android sharing apps stack **BLE discovery/GATT**, **WiFi Direct**, a **control socket**, and a **pull-based HTTP download path**. Audit them as a single trust boundary: if the receiver leaks connection material over BLE or trusts sender-supplied control fields, a normal “Receive” workflow can become a **zero-click arbitrary file delivery** primitive.<sup>[[20]](#references)[[21]](#references)</sup> 57 58 ### What to test 59 60 - **BLE/GATT secret disclosure**: enumerate both custom services and standard characteristics such as **Generic Access / Device Name (`0x2a00`)**. Do not assume these only contain cosmetic names; check for leaked **SSIDs, PSKs, IPs, ports, tokens, or QR-derived metadata**. If the app moved to **BLE extended advertising**, desktop scanners may miss it while Android radios still recover the same bytes.<sup>[[20]](#references)[[21]](#references)</sup> 61 - **Optional cryptography / fake key exchange**: treat ECDH/RSA/DES/AES steps as untrusted until proven enforced. Send malformed or dummy key material, then continue with plaintext. If the receiver still returns an ack and accepts later commands, the real security boundary is only **network access**.<sup>[[20]](#references)[[21]](#references)</sup> 62 - **Remote consent-policy injection**: grep protocol schemas and deserializers for sender-controlled flags such as `silence`, `silent`, `trusted`, `autoAccept`, `skipPrompt`, `hidden`, or `installer`. Trace every branch that consumes them. If those fields suppress dialogs, UI counters, notifications, or transfer-list entries, the sender can convert a visible transfer into a **silent receive** path.<sup>[[20]](#references)</sup> 63 - **Pull-based arbitrary file delivery**: many proximity protocols do not push bytes over the control socket. Instead, the sender supplies **name, size, checksum, and an HTTP URI**, and the receiver connects back to fetch the payload. Exploitation becomes “control-message forgery + matching HTTP response,” so protocol responses like `Accept` / `DownloadFinished` are reliable success indicators even when the victim UI stays empty.<sup>[[20]](#references)[[21]](#references)</sup> 64 - **Hidden staging-directory abuse**: once you gain a file-drop primitive, identify where the app stores silent imports and which later workflows consume that directory. Hidden locations with **`.nomedia`** are valuable staging points. In ShareMe/MiDrop, silent transfers landed in `/sdcard/MIUI/ShareMe/.upgrade_package/`, which is later reused by the app’s self-update logic.<sup>[[20]](#references)[[21]](#references)</sup> 65 - **Weak APK verification in custom updates**: if the same directory feeds an updater, check whether the app validates only `packageName` / `versionCode` or calls `getPackageArchiveInfo(path, 0)` without requesting signing data. That enables **official-looking update prompts**, forced version changes, or downgrade-to-vulnerable-build attacks whenever platform signature checks are weak, bypassed, or satisfied by a correctly signed older build.<sup>[[20]](#references)</sup> 66 - **WebView / FileProvider follow-on pivots**: after file delivery, review `@JavascriptInterface` methods that forward attacker-controlled URLs into `Intent.parseUri(...)` or `startActivity(...)`, and inspect `file_paths.xml` for broad mappings such as `<root-path path="/data/">` or `/storage/`. Those patterns extend a file-transfer bug into **exported-intent abuse** or **provider-assisted file disclosure**.<sup>[[20]](#references)</sup> 67 - **Legacy fallback credentials**: grep for hardcoded WiFi Direct / hotspot passwords in old compatibility paths. Modern Android may override them, while Android 9/10 or OEM fallback code can still use the embedded default verbatim.<sup>[[20]](#references)</sup> 68 69 ### Fast triage 70 71 Use the decompiled tree and a test device to quickly validate this class of bug:<sup>[[20]](#references)[[21]](#references)</sup> 72 73 ```bash 74 rg -n 'send_pk|send_files|silence|silent|autoAccept|skipPrompt|trusted|installer|getPackageArchiveInfo|addJavascriptInterface|parseUri|root-path|/data/|/storage/' . 75 adb shell dumpsys bluetooth_manager | grep name: 76 ``` 77 78 ### Automated multi-source APK acquisition (justapk) 79 80 `pip install justapk` (Python 3.11+). CLI outputs JSON to **stdout** and progress to **stderr** (pipe-friendly). It tries a deterministic fallback chain across **APK20 → F-Droid → APKPure (mobile API) → APKMirror (HTML scrape) → Uptodown (mobile API) → APKCombo (HTML scrape)**. Cloudflare-protected sources use **curl_cffi** with TLS fingerprint impersonation to mimic real clients and reduce bot-detection blocks.<sup>[[13]](#references)</sup> 81 82 ```bash 83 justapk download <package> # auto fallback 84 justapk download <package> -s apkpure # pin a source / version / output dir 85 justapk search telegram 86 justapk info org.telegram.messenger 87 justapk convert app.xapk -o output/ # merges splits, re-signs with debug key 88 ``` 89 90 **convert** merges XAPK/split APKs and signs them with a **debug key**, so the resulting APK signature/provenance differs from the original (use for testing/analysis, not production installs).<sup>[[13]](#references)</sup> 91 92 - Extract APK from device: 93 94 ```bash 95 adb shell pm list packages 96 com.android.insecurebankv2 97 98 adb shell pm path com.android.insecurebankv2 99 package:/data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk 100 101 adb pull /data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk 102 ``` 103 104 - Merge all splits and base apks with [APKEditor](https://github.com/REAndroid/APKEditor): 105 106 ```bash 107 mkdir splits 108 adb shell pm path com.android.insecurebankv2 | cut -d ':' -f 2 | xargs -n1 -i adb pull {} splits 109 java -jar ../APKEditor.jar m -i splits/ -o merged.apk 110 111 # after merging, you will need to align and sign the apk, personally, I like to use the uberapksigner 112 java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed 113 ``` 114 115 ## Jezail rooted Android pentesting toolkit (REST API + web UI) 116 117 - Runs on a **rooted device** (Magisk/rootAVD) and starts an **HTTP server on tcp/8080** with a **Flutter web UI** and **REST API**.<sup>[[14]](#references)</sup> 118 - Install the release APK with perms: `adb install -g -r jezail.apk`, then launch the app (server auto-starts). 119 - Endpoints: `http://<device-ip>:8080/` (UI), `http://<device-ip>:8080/api/json` (API listing), `http://<device-ip>:8080/api/swagger` (Swagger). 120 - Emulator port-forward to reach UI/API from the host: `adb forward tcp:8080 tcp:8080` then browse `http://localhost:8080`. 121 122 ## Android Enterprise & Work Profile Attacks 123 124 [Android Enterprise Work Profile Bypass](/hacktricks/mobile-pentesting/android-app-pentesting/android-enterprise-work-profile-bypass) 125 126 ## Case Studies & Vulnerabilities 127 128 129 [Air Keyboard Remote Input Injection](/hacktricks/mobile-pentesting/ios-pentesting/air-keyboard-remote-input-injection) 130 131 132 [Android Rooting Frameworks Manager Auth Bypass Syscall Hook](/hacktricks/linux-hardening/software-information/android-rooting-frameworks-manager-auth-bypass-syscall-hook) 133 134 [Abusing Android Media Pipelines Image Parsers](/hacktricks/mobile-pentesting/android-app-pentesting/abusing-android-media-pipelines-image-parsers) 135 136 [Baseband And Soc Isolation Exploitation](/hacktricks/mobile-pentesting/android-app-pentesting/baseband-and-soc-isolation-exploitation) 137 138 [Firmware Level Zygote Backdoor Libandroid Runtime](/hacktricks/mobile-pentesting/android-app-pentesting/firmware-level-zygote-backdoor-libandroid-runtime) 139 140 ### Pre-installed privileged Android TV-box implants (OEM / reseller firmware abuse) 141 142 Some Android botnets are not sideloaded by the victim: they are baked into OEM/reseller firmware as privileged packages and later extend themselves with secondary APKs outside the normal user install flow. Treat these samples as a **firmware/supply-chain foothold** instead of as a normal malicious app: they can keep persistent C2 channels, install follow-on modules, stream the display, and repurpose the device for fraud or residential proxying.<sup>[[16]](#references)</sup> 143 144 When reversing pre-installed Android implants, prioritize the following checks.<sup>[[16]](#references)</sup> 145 146 - **Package origin / privilege mismatch**: compare `codePath`, shared UID, requested permissions, and install paths against stock firmware. APKs that live outside `/data/app`, cannot be removed normally, or reappear across unrelated brands/models are strong supply-chain indicators. 147 - **Trusted follow-on install paths**: inspect locations such as `/data/local/system` for dynamically dropped APKs/JARs used as task modules or alternate execution modes. 148 - **Cross-layer identity spoofing**: do not trust only `getprop` or only browser fingerprints. Reconcile system properties, screen size, chipset remnants like `rockchip`, `amlogic`, or `allwinner`, launcher/settings packages, and browser-visible CPU/GPU data to catch TV-box-to-phone masquerading. 149 - **Selector-independent UI automation**: if the sample combines `AccessibilityService` abuse with OCR/object-detection assets, assume the operator can survive DOM/UI churn. Inspect `assets/` for ML models, OCR libraries, browser stealth scripts, and generated JavaScript task modules instead of focusing only on selectors. 150 - **Proxy-only monetization mode**: hunt for bootstrap endpoints that fetch backconnect servers, then long-lived tunnels carrying multiplexed SOCKS5 sessions over a custom framing layer. This is closer to a residential proxy backhaul than a simple local SOCKS listener; see [Tunneling and Port Forwarding](https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/generic-hacking/tunneling-and-port-forwarding.md). 151 - **Expired management infrastructure**: extract hardcoded domains/IPs from privileged apps and management agents, then verify whether DNS/TLS ownership still matches the vendor. If a root-capable management domain has expired, the finding becomes a mass-device takeover opportunity rather than a mere dangling record; see [Domain/Subdomain takeover](/hacktricks/pentesting-web/domain-subdomain-takeover). 152 153 A quick rooted-device triage for this pattern is:<sup>[[16]](#references)</sup> 154 155 ```bash 156 adb shell pm list packages -f 157 adb shell dumpsys package <package> 158 adb shell find /data/local/system -maxdepth 2 -type f 2>/dev/null 159 adb shell getprop | grep -E 'ro.product|ro.board|ro.hardware|ro.build' 160 adb shell dumpsys accessibility 161 ``` 162 163 ## Static Analysis 164 165 First, inspect the APK's **Java code** with a decompiler.\ 166 Please, [**read here to find information about different available decompilers**](/hacktricks/mobile-pentesting/android-app-pentesting/apk-decompilers). 167 168 ### APK anti-analysis via malformed containers, manifests, and asset names 169 170 Some malicious APKs are not merely obfuscated: they are **deliberately malformed** so common tooling (`unzip`, `apktool`, `jadx`, AV scanners, CI pipelines) cannot enumerate files reliably or aborts early. A useful mental model is **parser differential anti-analysis**: Android may still accept enough of the package to install or partially process it, while desktop ZIP/APK parsers disagree about what entries exist or where they start. 171 172 Common patterns: 173 174 - **Malformed ZIP/APK metadata**: inconsistent **local file headers** and **central directory** records can make tools resolve different offsets, sizes, or filenames for the same entry. 175 - **Corrupted binary `AndroidManifest.xml`**: if the manifest cannot be decoded, many static-analysis pipelines stop before inspecting components, permissions, exported surfaces, or embedded resources. 176 - **Malformed asset filenames**: suspicious names inside `assets/` can break extraction, path handling, or downstream file processing and hide secondary payloads. 177 178 Practical workflow when a sample "looks empty" or decompilers crash: 179 180 1. Compare how multiple parsers see the archive: 181 ```bash 182 unzip -l app.apk 183 zipinfo -v app.apk 184 jadx app.apk -d out-jadx 185 apktool d app.apk -o out-apktool 186 ``` 187 2. If the file list differs across tools, or `jadx` / `apktool` fails on `AndroidManifest.xml`, treat the APK as intentionally malformed instead of assuming corruption in transit. 188 3. Rebuild a **normalized APK** that rewrites ZIP metadata, repairs the manifest, and sanitises hostile asset names before deeper reversing. 189 190 One purpose-built tool for this is **MalFixer**:<sup>[[11]](#references)</sup> 191 192 ```bash 193 python malfixer.py /path/to/app.apk 194 python malfixer.py /path/to/app.apk --output-dir /path/to/output 195 python malfixer.py /path/to/app.apk -l DEBUG 196 ``` 197 198 The resulting `*-fixed.apk` is intended to be **standard enough for static tooling**, especially `jadx`. This is useful when triaging Android malware or packers that hide payloads behind malformed container metadata rather than only string/code obfuscation. 199 200 > [!NOTE] 201 > The MalFixer README describes the ZIP repair module as `zipzixer.py`, while the repository file listing currently exposes `zipfixer.py`. If you inspect or import the project manually, verify the actual filename in the checked-out tree. 202 203 ### Looking for interesting Info 204 205 Just taking a look to the **strings** of the APK you can search for **passwords**, **URLs** ([https://github.com/ndelphit/apkurlgrep](https://github.com/ndelphit/apkurlgrep)), **api** keys, **encryption**, **bluetooth uuids**, **tokens** and anything interesting... look even for code execution **backdoors** or authentication backdoors (hardcoded admin credentials to the app). 206 207 **Firebase** 208 209 Pay special attention to **firebase URLs** and check if it is bad configured. [More information about whats is FIrebase and how to exploit it here.](/hacktricks/network-services-pentesting/pentesting-web/buckets/firebase-database) 210 211 ### Basic understanding of the application - Manifest.xml, strings.xml 212 213 The **examination of an application's _Manifest.xml_ and **_strings.xml_** files can reveal potential security vulnerabilities**. These files can be accessed using decompilers or by renaming the APK file extension to .zip and then unzipping it. 214 215 **Vulnerabilities** identified from the **Manifest.xml** include: 216 217 - **Debuggable Applications**: Applications set as debuggable (`debuggable="true"`) in the _Manifest.xml_ file pose a risk as they allow connections that can lead to exploitation. For further understanding on how to exploit debuggable applications, refer to a tutorial on finding and exploiting debuggable applications on a device. 218 - **Backup Settings**: The `android:allowBackup="false"` attribute should be explicitly set for applications dealing with sensitive information to prevent unauthorized data backups via adb, especially when usb debugging is enabled. 219 - **Network Security**: Custom network security configurations (`android:networkSecurityConfig="@xml/network_security_config"`) in _res/xml/_ can specify security details like certificate pins and HTTP traffic settings. An example is allowing HTTP traffic for specific domains. 220 - **Exported Activities and Services**: Identifying exported activities and services in the manifest can highlight components that might be misused. Further analysis during dynamic testing can reveal how to exploit these components. 221 - **Content Providers and FileProviders**: Exposed content providers could allow unauthorized access or modification of data. The configuration of FileProviders should also be scrutinized. 222 - **Broadcast Receivers and URL Schemes**: These components could be leveraged for exploitation, with particular attention to how URL schemes are managed for input vulnerabilities. 223 - **SDK Versions**: The `minSdkVersion`, `targetSDKVersion`, and `maxSdkVersion` attributes indicate the supported Android versions, highlighting the importance of not supporting outdated, vulnerable Android versions for security reasons. 224 225 From the **strings.xml** file, sensitive information such as API keys, custom schemas, and other developer notes can be discovered, underscoring the need for careful review of these resources. 226 227 ### Tapjacking 228 229 **Tapjacking** places an attacker-controlled interface over another app and forwards the victim's touches to obscured controls, tricking the user into triggering actions in the underlying application. Test transparent and partially occluding overlays, especially around exported activities and security-sensitive confirmation screens.\ 230 In effect, it is **blinding the user from knowing they are actually performing actions on the victim app**. 231 232 Find more information in: 233 234 235 [Tapjacking](/hacktricks/mobile-pentesting/android-app-pentesting/tapjacking) 236 237 ### Task Hijacking 238 239 An **activity** with the **`launchMode`** set to **`singleTask` without any `taskAffinity`** defined is vulnerable to task Hijacking. This means, that an **application** can be installed and if launched before the real application it could **hijack the task of the real application** (so the user will be interacting with the **malicious application thinking he is using the real one**). 240 241 More info in: 242 243 244 [Android Task Hijacking](/hacktricks/mobile-pentesting/android-app-pentesting/android-task-hijacking) 245 246 ### Insecure data storage 247 248 **Internal Storage** 249 250 In Android, files **stored** in **internal** storage are **designed** to be **accessible** exclusively by the **app** that **created** them. This security measure is **enforced** by the Android operating system and is generally adequate for the security needs of most applications. However, developers sometimes utilize modes such as `MODE_WORLD_READABLE` and `MODE_WORLD_WRITABLE` to **allow** files to be **shared** between different applications. Yet, these modes **do not restrict access** to these files by other applications, including potentially malicious ones. 251 252 1. **Static Analysis:** 253 - **Ensure** that the use of `MODE_WORLD_READABLE` and `MODE_WORLD_WRITABLE` is **carefully scrutinized**. These modes **can potentially expose** files to **unintended or unauthorized access**. 254 2. **Dynamic Analysis:** 255 - **Verify** the **permissions** set on files created by the app. Specifically, **check** if any files are **set to be readable or writable worldwide**. This can pose a significant security risk, as it would allow **any application** installed on the device, regardless of its origin or intent, to **read or modify** these files. 256 257 **External Storage** 258 259 When dealing with files on **external storage**, such as SD Cards, certain precautions should be taken: 260 261 1. **Accessibility**: 262 - Files on external storage are **globally readable and writable**. This means any application or user can access these files. 263 2. **Security Concerns**: 264 - Given the ease of access, it's advised **not to store sensitive information** on external storage. 265 - External storage can be removed or accessed by any application, making it less secure. 266 3. **Handling Data from External Storage**: 267 - Always **perform input validation** on data retrieved from external storage. This is crucial because the data is from an untrusted source. 268 - Storing executables or class files on external storage for dynamic loading is strongly discouraged. 269 - If your application must retrieve executable files from external storage, ensure these files are **signed and cryptographically verified** before they are dynamically loaded. This step is vital for maintaining the security integrity of your application. 270 271 External storage can be **accessed** in `/storage/emulated/0` , `/sdcard` , `/mnt/sdcard` 272 273 > [!TIP] 274 > Starting with Android 4.4 (**API 17**), the SD card has a directory structure which **limits access from an app to the directory which is specifically for that app**. This prevents malicious application from gaining read or write access to another app's files. 275 276 **Sensitive data stored in clear-text** 277 278 - **Shared preferences**: Android allow to each application to easily save xml files in the path `/data/data/<packagename>/shared_prefs/` and sometimes it's possible to find sensitive information in clear-text in that folder. 279 - **Databases**: Android allow to each application to easily save sqlite databases in the path `/data/data/<packagename>/databases/` and sometimes it's possible to find sensitive information in clear-text in that folder. 280 281 ### Broken TLS 282 283 **Accept All Certificates** 284 285 For some reason sometimes developers accept all the certificates even if for example the hostname does not match with lines of code like the following one: 286 287 ```java 288 SSLSocketFactory sf = new cc(trustStore); 289 sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 290 ``` 291 292 A good way to test this is to try to capture the traffic using some proxy like Burp without authorising Burp CA inside the device. Also, you can generate with Burp a certificate for a different hostname and use it. 293 294 ### Broken Cryptography 295 296 **Poor Key Management Processes** 297 298 Encryption does not protect locally stored secrets when the key is hardcoded or predictably derived: reverse engineering can recover the key and expose the plaintext. 299 300 **Use of Insecure and/or Deprecated Algorithms** 301 302 Avoid **deprecated algorithms** such as RC4, MD4, MD5, and SHA-1 for authorization decisions or for protecting data at rest or in transit. Passwords require a salted, deliberately expensive password-hashing/KDF construction rather than a fast general-purpose hash. 303 304 ### Other checks 305 306 - It's recommended to **obfuscate the APK** to difficult the reverse engineer labour to attackers. 307 - If the app is sensitive (like bank apps), it should perform it's **own checks to see if the mobile is rooted** and act in consequence. 308 - If the app is sensitive (like bank apps), it should check if an **emulator** is being used. 309 - If the app is sensitive (like bank apps), it should **check it's own integrity before executing** it to check if it was modified. 310 - Use [**APKiD**](https://github.com/rednaga/APKiD) to check which compiler/packer/obfuscator was used to build the APK 311 312 ### React Native Application 313 314 Read the following page to learn how to easily access javascript code of React applications: 315 316 317 [React Native Application](/hacktricks/mobile-pentesting/android-app-pentesting/react-native-application) 318 319 ### Xamarin Applications 320 321 Read the following page to learn how to easily access C# code of a xamarin applications: 322 323 324 [Xamarin Apps](/hacktricks/mobile-pentesting/xamarin-apps) 325 326 ### Superpacked Applications 327 328 According to this [**blog post**](https://clearbluejar.github.io/posts/desuperpacking-meta-superpacked-apks-with-github-actions/) superpacked is a Meta algorithm that compress the content of an application into a single file. The blog talks about the possibility of creating an app that decompress these kind of apps... and a faster way which involves to **execute the application and gather the decompressed files from the filesystem.**<sup>[[18]](#references)</sup> 329 330 ### Automated Static Code Analysis 331 332 The tool [**mariana-trench**](https://github.com/facebook/mariana-trench) is capable of finding **vulnerabilities** by **scanning** the **code** of the application. This tool contains a series of **known sources** (that indicates to the tool the **places** where the **input** is **controlled by the user**), **sinks** (which indicates to the tool **dangerous** **places** where malicious user input could cause damages) and **rules**. These rules indicates the **combination** of **sources-sinks** that indicates a vulnerability. 333 334 With this knowledge, **mariana-trench will review the code and find possible vulnerabilities on it**. 335 336 ### Secrets leaked 337 338 An application may contain discoverable secrets such as API keys, passwords, hidden URLs, and subdomains. You can search for them with a tool such as [APKLeaks](https://github.com/dwisiswant0/apkleaks). 339 340 ### Bypass Biometric Authentication 341 342 343 [Bypass Biometric Authentication Android](/hacktricks/mobile-pentesting/android-app-pentesting/bypass-biometric-authentication-android) 344 345 ### Other interesting functions 346 347 - **Code execution**: `Runtime.exec(), ProcessBuilder(), native code:system()` 348 - **Send SMSs**: `sendTextMessage, sendMultipartTestMessage` 349 - **Native functions** declared as `native`: `public native, System.loadLibrary, System.load` 350 - [Read this to learn **how to reverse native functions**](/hacktricks/mobile-pentesting/android-app-pentesting/reversing-native-libraries) 351 - In-memory native code execution via JNI (downloaded shellcode → mmap/mprotect → call):<sup>[[12]](#references)</sup> 352 353 [In Memory Jni Shellcode Execution](/hacktricks/mobile-pentesting/android-app-pentesting/in-memory-jni-shellcode-execution) 354 355 ### **Other tricks** 356 357 358 [Content Protocol](/hacktricks/mobile-pentesting/android-app-pentesting/content-protocol) 359 360 --- 361 362 --- 363 364 ## Dynamic Analysis 365 366 > First of all, you need an environment where you can install the application and all the environment (Burp CA cert, Drozer and Frida mainly). Therefore, a rooted device (emulated or not) is extremely recommended. 367 368 ### Online Dynamic analysis 369 370 You can create a **free account** in: [https://appetize.io/](https://appetize.io). This platform allows you to **upload** and **execute** APKs, so it is useful to see how an apk is behaving. 371 372 You can even **see the logs of your application** in the web and connect through **adb**. 373 374  375 376 Thanks to the ADB connection you can use **Drozer** and **Frida** inside the emulators. 377 378 ### Local Dynamic Analysis 379 380 #### Using an emulator 381 382 - [**Android Studio**](https://developer.android.com/studio) (You can create **x86** and **ARM** devices, and recent x86 system images can run ARM binaries without requiring a slow ARM-only emulator).<sup>[[19]](#references)</sup> 383 - Learn to set it up in this page: 384 385 386 [Avd Android Virtual Device](/hacktricks/mobile-pentesting/android-app-pentesting/avd-android-virtual-device) 387 388 - [**Genymotion**](https://www.genymotion.com/fun-zone/) **(Free version:** Personal Edition, you need to create an account. _It's recommend to **download** the version **WITH**_ _**VirtualBox** to avoid potential errors._) 389 - [**Nox**](https://es.bignox.com) (Free, but it doesn't support Frida or Drozer). 390 391 > [!TIP] 392 > When creating a new emulator on any platform remember that the bigger the screen is, the slower the emulator will run. So select small screens if possible. 393 394 To **install google services** (like AppStore) in Genymotion you need to click on the red marked button of the following image: 395 396  397 398 Also, notice that in the **configuration of the Android VM in Genymotion** you can select **Bridge Network mode** (this will be useful if you will be connecting to the Android VM from a different VM with the tools). 399 400 #### Use a physical device 401 402 You need to activate the **debugging** options and it will be cool if you can **root** it: 403 404 1. **Settings**. 405 2. (FromAndroid 8.0) Select **System**. 406 3. Select **About phone**. 407 4. Press **Build number** 7 times. 408 5. Go back and you will find the **Developer options**. 409 410 > Once you have installed the application, the first thing you should do is to try it and investigate what does it do, how does it work and get comfortable with it.\ 411 > I will suggest to **perform this initial dynamic analysis using MobSF dynamic analysis + pidcat**, so we will be able to **learn how the application works** while MobSF **captures** a lot of **interesting** **data** you can review later on. 412 413 Magisk/Zygisk quick notes (recommended on Pixel devices)<sup>[[10]](#references)</sup> 414 - Patch boot.img with the Magisk app and flash via fastboot to get systemless root 415 - Enable Zygisk + DenyList for root hiding; consider LSPosed/Shamiko when stronger hiding is required 416 - Keep original boot.img to recover from OTA updates; re-patch after each OTA 417 - For screen mirroring, use scrcpy on the host 418 419 420 ### Unintended Data Leakage 421 422 **Logging** 423 424 Developers should be cautious of exposing **debugging information** publicly, as it can lead to sensitive data leaks. The tools [**pidcat**](https://github.com/JakeWharton/pidcat) and `adb logcat` are recommended for monitoring application logs to identify and protect sensitive information. **Pidcat** is favored for its ease of use and readability. 425 426 > [!WARNING] 427 > Note that from **later newer than Android 4.0**, **applications are only able to access their own logs**. So applications cannot access other apps logs.\ 428 > Anyway, it's still recommended to **not log sensitive information**. 429 430 **Copy/Paste Buffer Caching** 431 432 Android's **clipboard-based** framework enables copy-paste functionality in apps, yet poses a risk as **other applications** can **access** the clipboard, potentially exposing sensitive data. It's crucial to **disable copy/paste** functions for sensitive sections of an application, like credit card details, to prevent data leaks. 433 434 **Crash Logs** 435 436 If an application **crashes** and **saves logs**, these logs can assist attackers, particularly when the application cannot be reverse-engineered. To mitigate this risk, avoid logging on crashes, and if logs must be transmitted over the network, ensure they are sent via an SSL channel for security. 437 438 As pentester, **try to take a look to these logs**. 439 440 **Analytics Data Sent To 3rd Parties** 441 442 Applications often integrate services like Google Adsense, which can inadvertently **leak sensitive data** due to improper implementation by developers. To identify potential data leaks, it's advisable to **intercept the application's traffic** and check for any sensitive information being sent to third-party services. 443 444 ### SQLite DBs 445 446 Most of the applications will use **internal SQLite databases** to save information. During the pentest take a **look** to the **databases** created, the names of **tables** and **columns** and all the **data** saved because you could find **sensitive information** (which would be a vulnerability).\ 447 Databases should be located in `/data/data/the.package.name/databases` like `/data/data/com.mwr.example.sieve/databases` 448 449 If the database is saving confidential information and is **encrypted b**ut you can **find** the **password** inside the application it's still a **vulnerability**. 450 451 Enumerate the tables using `.tables` and enumerate the columns of the tables doing `.schema <table_name>` 452 453 ### Drozer (Exploit Activities, Content Providers and Services) 454 455 From [Drozer Docs](https://labs.mwrinfosecurity.com/assets/BlogFiles/mwri-drozer-user-guide-2015-03-23.pdf): **Drozer** allows you to **assume the role of an Android app** and interact with other apps. It can do **anything that an installed application can do**, such as make use of Android’s Inter-Process Communication (IPC) mechanism and interact with the underlying operating system. .\ 456 Drozer is s useful tool to **exploit exported activities, exported services and Content Providers** as you will learn in the following sections. 457 458 ### Exploiting exported Activities 459 460 [**Read this if you want to refresh what is an Android Activity.**](/hacktricks/mobile-pentesting/android-app-pentesting/android-applications-basics#launcher-activity-and-other-activities)\ 461 Also remember that the code of an activity starts in the **`onCreate`** method. 462 463 **Authorisation bypass** 464 465 When an Activity is exported you can invoke its screen from an external app. Therefore, if an activity with **sensitive information** is **exported** you could **bypass** the **authentication** mechanisms **to access it.** 466 467 [**Learn how to exploit exported activities with Drozer.**](drozer-tutorial/index.html#activities) 468 469 You can also start an exported activity from adb: 470 471 - PackageName is com.example.demo 472 - Exported ActivityName is com.example.test.MainActivity 473 474 ```bash 475 adb shell am start -n com.example.demo/com.example.test.MainActivity 476 ``` 477 478 **NOTE**: MobSF will detect as malicious the use of _**singleTask/singleInstance**_ as `android:launchMode` in an activity, but due to [this](https://github.com/MobSF/Mobile-Security-Framework-MobSF/pull/750), apparently this is only dangerous on old versions (API versions < 21). 479 480 > [!TIP] 481 > Note that an authorisation bypass is not always a vulnerability, it would depend on how the bypass works and which information is exposed. 482 483 **Sensitive information leakage** 484 485 **Activities can also return results**. If you manage to find an exported and unprotected activity calling the **`setResult`** method and **returning sensitive information**, there is a sensitive information leakage. 486 487 #### Tapjacking 488 489 If tapjacking isn't prevented, you could abuse the exported activity to make the **user perform unexpected actions**. For more info about [**what is Tapjacking follow the link**](#tapjacking). 490 491 ### Exploiting Content Providers - Accessing and manipulating sensitive information 492 493 [**Read this if you want to refresh what is a Content Provider.**](/hacktricks/mobile-pentesting/android-app-pentesting/android-applications-basics#content-provider)\ 494 Content providers are basically used to **share data**. If an app has available content providers you may be able to **extract sensitive** data from them. It also interesting to test possible **SQL injections** and **Path Traversals** as they could be vulnerable. 495 496 [**Learn how to exploit Content Providers with Drozer.**](drozer-tutorial/index.html#content-providers) 497 498 ### **Exploiting Services** 499 500 [**Read this if you want to refresh what is a Service.**](/hacktricks/mobile-pentesting/android-app-pentesting/android-applications-basics#services)\ 501 Remember that a the actions of a Service start in the method `onStartCommand`. 502 503 As service is basically something that **can receive data**, **process** it and **returns** (or not) a response. Then, if an application is exporting some services you should **check** the **code** to understand what is it doing and **test** it **dynamically** for extracting confidential info, bypassing authentication measures...\ 504 [**Learn how to exploit Services with Drozer.**](drozer-tutorial/index.html#services) 505 506 ### **Exploiting Broadcast Receivers** 507 508 [**Read this if you want to refresh what is a Broadcast Receiver.**](/hacktricks/mobile-pentesting/android-app-pentesting/android-applications-basics#broadcast-receivers)\ 509 Remember that a the actions of a Broadcast Receiver start in the method `onReceive`. 510 511 A broadcast receiver will be waiting for a type of message. Depending on ho the receiver handles the message it could be vulnerable.\ 512 [**Learn how to exploit Broadcast Receivers with Drozer.**](#exploiting-broadcast-receivers) 513 514 ### **Exploiting Schemes / Deep links** 515 516 You can look for deep links manually, using tools like MobSF or scripts like [this one](https://github.com/ashleykinguk/FBLinkBuilder/blob/master/FBLinkBuilder.py).\ 517 You can **open** a declared **scheme** using **adb** or a **browser**: 518 519 ```bash 520 adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name] 521 ``` 522 523 _Note that you can **omit the package name** and the mobile will automatically call the app that should open that link._ 524 525 ```html 526 <!-- Browser regular link --> 527 <a href="scheme://hostname/path?param=value">Click me</a> 528 <!-- fallback in your url you could try the intent url --> 529 <a href="intent://hostname#Intent;scheme=scheme;package=your.package.name;S.browser_fallback_url=http%3A%2F%2Fwww.example.com;end">with alternative</a> 530 ``` 531 532 **Code executed** 533 534 In order to find the **code that will be executed in the App**, go to the activity called by the deeplink and search the function **`onNewIntent`**. 535 536  537 538 **Sensitive info** 539 540 Every time you find a deep link check that i**t's not receiving sensitive data (like passwords) via URL parameters**, because any other application could **impersonate the deep link and steal that data!** 541 542 **Parameters in path** 543 544 You **must check also if any deep link is using a parameter inside the path** of the URL like: `https://api.example.com/v1/users/{username}` , in that case you can force a path traversal accessing something like: `example://app/users?username=../../unwanted-endpoint%3fparam=value` .\ 545 Note that if you find the correct endpoints inside the application you may be able to cause a **Open Redirect** (if part of the path is used as domain name), **account takeover** (if you can modify users details without CSRF token and the vuln endpoint used the correct method) and any other vuln. More [info about this here](http://dphoeniixx.com/2020/12/13-2/). 546 547 **More examples** 548 549 An [interesting bug bounty report](https://hackerone.com/reports/855618) about links (_/.well-known/assetlinks.json_). 550 551 ### Transport Layer Inspection and Verification Failures 552 553 - **Certificates are not always inspected properly** by Android applications. It's common for these applications to overlook warnings and accept self-signed certificates or, in some instances, revert to using HTTP connections. 554 - **Negotiations during the SSL/TLS handshake are sometimes weak**, employing insecure cipher suites. This vulnerability makes the connection susceptible to man-in-the-middle (MITM) attacks, allowing attackers to decrypt the data. 555 - **Leakage of private information** is a risk when applications authenticate using secure channels but then communicate over non-secure channels for other transactions. This approach fails to protect sensitive data, such as session cookies or user details, from interception by malicious entities. 556 557 #### Certificate Verification 558 559 We will focus on **certificate verification**. The integrity of the server's certificate must be verified to enhance security. This is crucial because insecure TLS configurations and the transmission of sensitive data over unencrypted channels can pose significant risks. For detailed steps on verifying server certificates and addressing vulnerabilities, [**this resource**](https://manifestsecurity.com/android-application-security-part-10/) provides comprehensive guidance. 560 561 #### SSL Pinning 562 563 SSL Pinning is a security measure where the application verifies the server's certificate against a known copy stored within the application itself. This method is essential for preventing MITM attacks. Implementing SSL Pinning is strongly recommended for applications handling sensitive information. 564 565 #### Traffic Inspection 566 567 To inspect HTTP traffic, it's necessary to **install the proxy tool's certificate** (e.g., Burp). Without installing this certificate, encrypted traffic might not be visible through the proxy. For a guide on installing a custom CA certificate, [**click here**](/hacktricks/mobile-pentesting/android-app-pentesting/avd-android-virtual-device#install-burp-certificate-on-a-virtual-machine). 568 569 Applications targeting **API Level 24 and above** require modifications to the Network Security Config to accept the proxy's CA certificate. This step is critical for inspecting encrypted traffic. For instructions on modifying the Network Security Config, [**refer to this tutorial**](/hacktricks/mobile-pentesting/android-app-pentesting/make-apk-accept-ca-certificate). 570 571 If **Flutter** is used, follow the instructions on [**this page**](/hacktricks/mobile-pentesting/android-app-pentesting/flutter). Adding the certificate to the Android store alone may not work because Flutter/Dart applications can use an embedded BoringSSL-based networking stack and trust behavior that differs from the platform CA store. 572 573 #### Static detection of SSL/TLS pinning 574 575 Before attempting runtime bypasses, quickly map where pinning is enforced in the APK. Static discovery helps you plan hooks/patches and focus on the right code paths. 576 577 Tool: SSLPinDetect<sup>[[7]](#references)[[8]](#references)</sup> 578 - Open-source static-analysis utility that decompiles the APK to Smali (via apktool) and scans for curated regex patterns of SSL/TLS pinning implementations. 579 - Reports exact file path, line number, and a code snippet for each match. 580 - Covers common frameworks and custom code paths: OkHttp CertificatePinner, custom javax.net.ssl.X509TrustManager.checkServerTrusted, SSLContext.init with custom TrustManagers/KeyManagers, and Network Security Config XML pins. 581 582 Install 583 - Prereqs: Python >= 3.8, Java on PATH, apktool 584 585 ```bash 586 git clone https://github.com/aancw/SSLPinDetect 587 cd SSLPinDetect 588 pip install -r requirements.txt 589 ``` 590 591 Usage 592 ```bash 593 # Basic 594 python sslpindetect.py -f app.apk -a apktool.jar 595 596 # Verbose (timings + per-match path:line + snippet) 597 python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v 598 ``` 599 600 Example pattern rules (JSON) 601 Use or extend signatures to detect proprietary/custom pinning styles. You can load your own JSON and scan at scale. 602 603 ```json 604 { 605 "OkHttp Certificate Pinning": [ 606 "Lcom/squareup/okhttp/CertificatePinner;", 607 "Lokhttp3/CertificatePinner;", 608 "setCertificatePinner" 609 ], 610 "TrustManager Override": [ 611 "Ljavax/net/ssl/X509TrustManager;", 612 "checkServerTrusted" 613 ] 614 } 615 ``` 616 617 Notes and tips 618 - Fast scanning on large apps via multi-threading and memory-mapped I/O; pre-compiled regex reduces overhead/false positives. 619 - Pattern collection: https://github.com/aancw/smali-sslpin-patterns<sup>[[9]](#references)</sup> 620 - Typical detection targets to triage next: 621 - OkHttp: CertificatePinner usage, setCertificatePinner, okhttp3/okhttp package references 622 - Custom TrustManagers: javax.net.ssl.X509TrustManager, checkServerTrusted overrides 623 - Custom SSL contexts: SSLContext.getInstance + SSLContext.init with custom managers 624 - Declarative pins in res/xml network security config and manifest references 625 - Use the matched locations to plan Frida hooks, static patches, or config reviews before dynamic testing. 626 627 628 #### Bypassing SSL Pinning 629 630 When SSL Pinning is implemented, bypassing it becomes necessary to inspect HTTPS traffic. Various methods are available for this purpose: 631 632 - Automatically **modify** the **apk** to **bypass** SSLPinning with [**apk-mitm**](https://github.com/shroudedcode/apk-mitm). The best pro of this option, is that you won't need root to bypass the SSL Pinning, but you will need to delete the application and reinstall the new one, and this won't always work. 633 - You could use **Frida** (discussed below) to bypass this protection. Here you have a guide to use Burp+Frida+Genymotion: [https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/](https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/) 634 - You can also try to **automatically bypass SSL Pinning** using [**objection**](/hacktricks/mobile-pentesting/android-app-pentesting/frida-tutorial/objection-tutorial)**:** `objection --gadget com.package.app explore --startup-command "android sslpinning disable"` 635 - You can also try to **automatically bypass SSL Pinning** using **MobSF dynamic analysis** (explained below) 636 - If you still think that there is some traffic that you aren't capturing you can try to **forward the traffic to burp using iptables**. Read this blog: [https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62](https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62) 637 638 #### Looking for Common Web Vulnerabilities 639 640 It's important to also search for common web vulnerabilities within the application. Detailed information on identifying and mitigating these vulnerabilities is beyond the scope of this summary but is extensively covered elsewhere. 641 642 ### Frida 643 644 [Frida](https://www.frida.re) is a dynamic instrumentation toolkit for developers, reverse-engineers, and security researchers.\ 645 **You can access running application and hook methods on run time to change the behaviour, change values, extract values, run different code...**\ 646 If you want to pentest Android applications you need to know how to use Frida. 647 648 - Learn how to use Frida: [**Frida tutorial**](frida-tutorial/index.html) 649 - Some "GUI" for actions with Frida: [**https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security**](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security) 650 - Ojection is great to automate the use of Frida: [**https://github.com/sensepost/objection**](https://github.com/sensepost/objection) **,** [**https://github.com/dpnishant/appmon**](https://github.com/dpnishant/appmon) 651 - You can find some Awesome Frida scripts here: [**https://codeshare.frida.re/**](https://codeshare.frida.re) 652 - Try to bypass anti-debugging / anti-frida mechanisms loading Frida as in indicated in [https://erfur.github.io/blog/dev/code-injection-without-ptrace](https://erfur.github.io/blog/dev/code-injection-without-ptrace) (tool [linjector](https://github.com/erfur/linjector-rs)) 653 654 #### Anti-instrumentation & SSL pinning bypass workflow 655 656 [Android Anti Instrumentation And Ssl Pinning Bypass](/hacktricks/mobile-pentesting/android-app-pentesting/android-anti-instrumentation-and-ssl-pinning-bypass) 657 658 ### **Dump Memory - Fridump** 659 660 Check if the application is storing sensitive information inside the memory that it shouldn't be storing like passwords or mnemonics. 661 662 Using [**Fridump3**](https://github.com/rootbsd/fridump3) you can dump the memory of the app with: 663 664 ```bash 665 # With PID 666 python3 fridump3.py -u <PID> 667 668 # With name 669 frida-ps -Uai 670 python3 fridump3.py -u "<Name>" 671 ``` 672 673 This will dump the memory in ./dump folder, and in there you could grep with something like: 674 675 ```bash 676 strings * | grep -E "^[a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+$" 677 ``` 678 679 ### **Sensitive data in Keystore** 680 681 In Android the Keystore is the best place to store sensitive data, however, with enough privileges it's still **possible to access it**. As applications tends to store here **sensitive data in clear text** the pentests should check for it as root user or someones with physical access to the device could be able to steal this data. 682 683 Even if an app stored date in the keystore, the data should be encrypted. 684 685 To access the data inside the keystore you could use this Frida script: [https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js](https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js) 686 687 ```bash 688 frida -U -f com.example.app -l frida-scripts/tracer-cipher.js 689 ``` 690 691 ## Android Physical Attacks 692 693 [Android Physical Attacks](/hacktricks/mobile-pentesting/android-app-pentesting/android-physical-attacks) 694 695 ### **Fingerprint/Biometrics Bypass** 696 697 Using the following Frida script it could be possible to **bypass fingerprint authentication** Android applications might be performing in order to **protect certain sensitive areas:** 698 699 ```bash 700 frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f <app.package> 701 ``` 702 703 ### **Background Images** 704 705 When you put an application in background, Android stores a **snapshot of the application** so when it's recovered to foreground it starts loading the image before the app so ot looks like the app was loaded faster. 706 707 However, if this snapshot contains **sensitive information**, someone with access to the snapshot might **steal that info** (note that you need root to access it). 708 709 The snapshots are usually stored around: **`/data/system_ce/0/snapshots`** 710 711 Android provides a way to **prevent the screenshot capture by setting the FLAG_SECURE** layout parameter. By using this flag, the window contents are treated as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays. 712 713 ```bash 714 getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); 715 ``` 716 717 ### **Android Application Analyzer** 718 719 This tool can help manage multiple utilities during dynamic analysis: [Android Application Analyzer](https://github.com/NotSoSecure/android_application_analyzer). 720 721 ### Intent Injection 722 723 Developers often create proxy components like activities, services, and broadcast receivers that handle these Intents and pass them to methods such as `startActivity(...)` or `sendBroadcast(...)`, which can be risky. 724 725 The danger lies in allowing attackers to trigger non-exported app components or access sensitive content providers by misdirecting these Intents. A notable example is the `WebView` component converting URLs to `Intent` objects via `Intent.parseUri(...)` and then executing them, potentially leading to malicious Intent injections. 726 727 ### Essential Takeaways 728 729 - **Intent Injection** is similar to web's Open Redirect issue. 730 - Exploits involve passing `Intent` objects as extras, which can be redirected to execute unsafe operations. 731 - It can expose non-exported components and content providers to attackers. 732 - `WebView`’s URL to `Intent` conversion can facilitate unintended actions. 733 734 ### Android Client Side Injections and others 735 736 Probably you know about this kind of vulnerabilities from the Web. You have to be specially careful with this vulnerabilities in an Android application: 737 738 - **SQL Injection:** When dealing with dynamic queries or Content-Providers ensure you are using parameterized queries. 739 - **JavaScript Injection (XSS):** Verify that JavaScript and Plugin support is disabled for any WebViews (disabled by default). [More info here](/hacktricks/mobile-pentesting/android-app-pentesting/webview-attacks#javascript-enabled). 740 - **Local File Inclusion:** WebViews should have access to the file system disabled (enabled by default) - `(webview.getSettings().setAllowFileAccess(false);)`. [More info here](/hacktricks/mobile-pentesting/android-app-pentesting/webview-attacks#javascript-enabled). 741 - **Eternal cookies**: In several cases when the android application finish the session the cookie isn't revoked or it could be even saved to disk 742 - [**Secure Flag** in cookies](../../pentesting-web/hacking-with-cookies/index.html#cookies-flags) 743 744 --- 745 746 ## Automatic Analysis 747 748 ### [MobSF](https://github.com/MobSF/Mobile-Security-Framework-MobSF) 749 750 **Static analysis** 751 752  753 754 **Vulnerability assessment of the application** using a nice web-based frontend. You can also perform dynamic analysis (but you need to prepare the environment). 755 756 ```bash 757 docker pull opensecurity/mobile-security-framework-mobsf 758 docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest 759 ``` 760 761 Notice that MobSF can analyse **Android**(apk)**, IOS**(ipa) **and Windows**(apx) applications (_Windows applications must be analyzed from a MobSF installed in a Windows host_).\ 762 Also, if you create a **ZIP** file with the source code if an **Android** or an **IOS** app (go to the root folder of the application, select everything and create a ZIPfile), it will be able to analyse it also. 763 764 MobSF also allows you to **diff/Compare** analysis and to integrate **VirusTotal** (you will need to set your API key in _MobSF/settings.py_ and enable it: `VT_ENABLED = TRUE` `VT_API_KEY = <Your API key>` `VT_UPLOAD = TRUE`). You can also set `VT_UPLOAD` to `False`, then the **hash** will be **upload** instead of the file. 765 766 ### Assisted Dynamic analysis with MobSF 767 768 **MobSF** can also be very helpful for **dynamic analysis** in **Android**, but in that case you will need to install MobSF and **genymotion** in your host (a VM or Docker won't work). _Note: You need to **start first a VM in genymotion** and **then MobSF.**_\ 769 The **MobSF dynamic analyser** can: 770 771 - **Dump application data** (URLs, logs, clipboard, screenshots made by you, screenshots made by "**Exported Activity Tester**", emails, SQLite databases, XML files, and other created files). All of this is done automatically except for the screenshots, you need to press when you want a screenshot or you need to press "**Exported Activity Tester**" to obtain screenshots of all the exported activities. 772 - Capture **HTTPS traffic** 773 - Use **Frida** to obtain **runtime** **information** 774 775 From android **versions > 5**, it will **automatically start Frida** and will set global **proxy** settings to **capture** traffic. It will only capture traffic from the tested application. 776 777 **Frida** 778 779 By default, it will also use some Frida Scripts to **bypass SSL pinning**, **root detection** and **debugger detection** and to **monitor interesting APIs**.\ 780 MobSF can also **invoke exported activities**, grab **screenshots** of them and **save** them for the report. 781 782 To **start** the dynamic testing press the green bottom: "**Start Instrumentation**". Press the "**Frida Live Logs**" to see the logs generated by the Frida scripts and "**Live API Monitor**" to see all the invocation to hooked methods, arguments passed and returned values (this will appear after pressing "Start Instrumentation").\ 783 MobSF also allows you to load your own **Frida scripts** (to send the results of your Friday scripts to MobSF use the function `send()`). It also has **several pre-written scripts** you can load (you can add more in `MobSF/DynamicAnalyzer/tools/frida_scripts/others/`), just **select them**, press "**Load**" and press "**Start Instrumentation**" (you will be able to see the logs of that scripts inside "**Frida Live Logs**"). 784 785  786 787 Moreover, you have some Auxiliary Frida functionalities: 788 789 - **Enumerate Loaded Classes**: It will print all the loaded classes 790 - **Capture Strings**: It will print all the capture strings while using the application (super noisy) 791 - **Capture String Comparisons**: Could be very useful. It will **show the 2 strings being compared** and if the result was True or False. 792 - **Enumerate Class Methods**: Put the class name (like "java.io.File") and it will print all the methods of the class. 793 - **Search Class Pattern**: Search classes by pattern 794 - **Trace Class Methods**: **Trace** a **whole class** (see inputs and outputs of all methods of th class). Remember that by default MobSF traces several interesting Android Api methods. 795 796 Once you have selected the auxiliary module you want to use you need to press "**Start Intrumentation**" and you will see all the outputs in "**Frida Live Logs**". 797 798 **Shell** 799 800 Mobsf also brings you a shell with some **adb** commands, **MobSF commands**, and common **shell** **commands** at the bottom of the dynamic analysis page. Some interesting commands: 801 802 ```bash 803 help 804 shell ls 805 activities 806 exported_activities 807 services 808 receivers 809 ``` 810 811 **HTTP tools** 812 813 When http traffic is capture you can see an ugly view of the captured traffic on "**HTTP(S) Traffic**" bottom or a nicer view in "**Start HTTPTools**" green bottom. From the second option, you can **send** the **captured requests** to **proxies** like Burp or Owasp ZAP.\ 814 To do so, _power on Burp -->_ _turn off Intercept --> in MobSB HTTPTools select the request_ --> press "**Send to Fuzzer**" --> _select the proxy address_ ([http://127.0.0.1:8080\\](http://127.0.0.1:8080)). 815 816 Once you finish the dynamic analysis with MobSF you can press on "**Start Web API Fuzzer**" to **fuzz http requests** an look for vulnerabilities. 817 818 > [!TIP] 819 > After dynamic analysis with MobSF, the proxy settings may be left misconfigured and may not be repairable from the GUI. Reset them with: 820 > 821 > ``` 822 > adb shell settings put global http_proxy :0 823 > ``` 824 825 ### Assisted Dynamic Analysis with Inspeckage 826 827 You can get the tool from [**Inspeckage**](https://github.com/ac-pm/Inspeckage).\ 828 This tool with use some **Hooks** to let you know **what is happening in the application** while you perform a **dynamic analysis**. 829 830 ### [Yaazhini](https://www.vegabird.com/yaazhini/) 831 832 This is a **great tool to perform static analysis with a GUI** 833 834  835 836 ### [Qark](https://github.com/linkedin/qark) 837 838 This tool is designed to look for several **security related Android application vulnerabilities**, either in **source code** or **packaged APKs**. The tool is also **capable of creating a "Proof-of-Concept" deployable APK** and **ADB commands**, to exploit some of the found vulnerabilities (Exposed activities, intents, tapjacking...). As with Drozer, there is no need to root the test device. 839 840 ```bash 841 pip3 install --user qark # --user is only needed if not using a virtualenv 842 qark --apk path/to/my.apk 843 qark --java path/to/parent/java/folder 844 qark --java path/to/specific/java/file.java 845 ``` 846 847 ### [**ReverseAPK**](https://github.com/1N3/ReverseAPK.git) 848 849 - Displays all extracted files for easy reference 850 - Automatically decompile APK files to Java and Smali format 851 - Analyze AndroidManifest.xml for common vulnerabilities and behavior 852 - Static source code analysis for common vulnerabilities and behavior 853 - Device info 854 - and more 855 856 ```bash 857 reverse-apk relative/path/to/APP.apk 858 ``` 859 860 ### [SUPER Android Analyzer](https://github.com/SUPERAndroidAnalyzer/super) 861 862 SUPER is a command-line application that can be used in Windows, MacOS X and Linux, that analyzes _.apk_ files in search for vulnerabilities. It does this by decompressing APKs and applying a series of rules to detect those vulnerabilities. 863 864 All rules are centered in a `rules.json` file, and each company or tester could create its own rules to analyze what they need. 865 866 Download the latest binaries from in the [download page](https://superanalyzer.rocks/download.html) 867 868 ```text 869 super-analyzer {apk_file} 870 ``` 871 872 ### [StaCoAn](https://github.com/vincentcox/StaCoAn) 873 874  875 876 StaCoAn is a **cross-platform** tool that helps developers, bug-bounty hunters, and ethical hackers perform [static code analysis](https://en.wikipedia.org/wiki/Static_program_analysis) on mobile applications. 877 878 The concept is that you drag and drop your mobile application file (an .apk or .ipa file) on the StaCoAn application and it will generate a visual and portable report for you. You can tweak the settings and wordlists to get a customized experience. 879 880 Download[ latest release](https://github.com/vincentcox/StaCoAn/releases): 881 882 ```text 883 ./stacoan 884 ``` 885 886 ### [AndroBugs](https://github.com/AndroBugs/AndroBugs_Framework) 887 888 AndroBugs Framework is an Android vulnerability analysis system that helps developers or hackers find potential security vulnerabilities in Android applications.\ 889 [Windows releases](https://github.com/AndroBugs/AndroBugs_Framework/releases) 890 891 ```text 892 python androbugs.py -f [APK file] 893 androbugs.exe -f [APK file] 894 ``` 895 896 ### [Androwarn](https://github.com/maaaaz/androwarn) 897 898 **Androwarn** is a tool whose main aim is to detect and warn the user about potential malicious behaviours developped by an Android application. 899 900 The detection is performed with the **static analysis** of the application's Dalvik bytecode, represented as **Smali**, with the [`androguard`](https://github.com/androguard/androguard) library. 901 902 This tool looks for **common behavior of "bad" applications** like: Telephony identifiers exfiltration, Audio/video flow interception, PIM data modification, Arbitrary code execution... 903 904 ```text 905 python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3 906 ``` 907 908 ### [MARA Framework](https://github.com/xtiankisutsa/MARA_Framework) 909 910  911 912 **MARA** is a **M**obile **A**pplication **R**everse engineering and **A**nalysis Framework. It is a tool that puts together commonly used mobile application reverse engineering and analysis tools, to assist in testing mobile applications against the OWASP mobile security threats. Its objective is to make this task easier and friendlier to mobile application developers and security professionals. 913 914 It is able to: 915 916 - Extract Java and Smali code using different tools 917 - Analyze APKs using: [smalisca](https://github.com/dorneanu/smalisca), [ClassyShark](https://github.com/google/android-classyshark), [androbugs](https://github.com/AndroBugs/AndroBugs_Framework), [androwarn](https://github.com/maaaaz/androwarn), [APKiD](https://github.com/rednaga/APKiD) 918 - Extract private information from the APK using regexps. 919 - Analyze the Manifest. 920 - Analyze found domains using: [pyssltest](https://github.com/moheshmohan/pyssltest), [testssl](https://github.com/drwetter/testssl.sh) and [whatweb](https://github.com/urbanadventurer/WhatWeb) 921 - Deobfuscate APK via [apk-deguard.com](http://www.apk-deguard.com) 922 923 ### Koodous 924 925 Useful to detect malware: [https://koodous.com/](https://koodous.com) 926 927 ## Obfuscating/Deobfuscating code 928 929 Note that depending the service and configuration you use to obfuscate the code. Secrets may or may not ended obfuscated. 930 931 ### [ProGuard](<https://en.wikipedia.org/wiki/ProGuard_(software)>) 932 933 From [Wikipedia](<https://en.wikipedia.org/wiki/ProGuard_(software)>): **ProGuard** is an open source command-line tool that shrinks, optimizes and obfuscates Java code. It is able to optimize bytecode as well as detect and remove unused instructions. ProGuard is free software and is distributed under the GNU General Public License, version 2. 934 935 ProGuard is distributed as part of the Android SDK and runs when building the application in release mode. 936 937 ### [DexGuard](https://www.guardsquare.com/dexguard) 938 939 Find a step-by-step guide to deobfuscate the apk in [https://blog.lexfo.fr/dexguard.html](https://blog.lexfo.fr/dexguard.html) 940 941 (From that guide) Last time we checked, the Dexguard mode of operation was: 942 943 - load a resource as an InputStream; 944 - feed the result to a class inheriting from FilterInputStream to decrypt it; 945 - do some useless obfuscation to waste a few minutes of time from a reverser; 946 - feed the decrypted result to a ZipInputStream to get a DEX file; 947 - finally load the resulting DEX as a Resource using the `loadDex` method. 948 949 ### [DeGuard](http://apk-deguard.com) 950 951 **DeGuard reverses the process of obfuscation performed by Android obfuscation tools. This enables numerous security analyses, including code inspection and predicting libraries.** 952 953 You can upload an obfuscated APK to their platform. 954 955 ### [Deobfuscate Android App](https://github.com/In3tinct/deobfuscate-android-app) 956 957 This is a LLM tool to find any potential security vulnerabilities in android apps and deobfuscate android app code. Uses Google's Gemini public API. 958 959 ### [Simplify](https://github.com/CalebFenton/simplify) 960 961 It is a **generic Android deobfuscator.** Simplify **virtually executes an app** to understand its behavior and then **tries to optimize the code** so it behaves identically but is easier for a human to understand. Each optimization is generic, so it does not depend on a specific obfuscation technique. 962 963 ### [APKiD](https://github.com/rednaga/APKiD) 964 965 APKiD gives you information about **how an APK was made**. It identifies many **compilers**, **packers**, **obfuscators**, and other weird stuff. It's [_PEiD_](https://www.aldeid.com/wiki/PEiD) for Android. 966 967 ### Manual 968 969 [Read this tutorial to learn some tricks on **how to reverse custom obfuscation**](/hacktricks/mobile-pentesting/android-app-pentesting/manual-deobfuscation) 970 971 ## Labs 972 973 ### [Androl4b](https://github.com/sh4hin/Androl4b) 974 975 AndroL4b is an Android security virtual machine based on ubuntu-mate includes the collection of latest framework, tutorials and labs from different security geeks and researchers for reverse engineering and malware analysis. 976 977 ## References 978 979 - [1] [Play Integrity API: How It Works & How to Bypass It](https://m4kr0.vercel.app/posts/play-integrity-api-how-it-works--how-to-bypass-it/) 980 - [2] [OWASP Mobile Application Security](https://owasp.org/www-project-mobile-app-security/) 981 - [3] [Android App Reverse Engineering 101](https://maddiestone.github.io/AndroidAppRE/) - Android quick course 982 - [4] [Android Application Security Series](https://manifestsecurity.com/android-application-security/) 983 - [5] [Android-Security-Teryaagh](https://github.com/Ralireza/Android-Security-Teryaagh) 984 - [6] [Mobile Hacking Workshop - Community Day](https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec) 985 - [7] [SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis](https://petruknisme.medium.com/sslpindetect-advanced-ssl-pinning-detection-for-android-security-analysis-1390e9eca097) 986 - [8] [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect) 987 - [9] [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns) 988 - [10] [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools) 989 - [11] [MalFixer](https://github.com/Cleafy/Malfixer) 990 - [12] [CoRPhone — Android in-memory JNI execution and packaging pipeline](https://github.com/0xdevil/corphone) 991 - [13] [justapk — multi-source APK downloader with Cloudflare bypass](https://github.com/TheQmaks/justapk) 992 - [14] [Jezail rooted Android pentesting toolkit (REST API + Flutter UI)](https://github.com/zahidaz/jezail) 993 - [15] [ISO 8583 Under Fire: Finding Vulnerabilities in a Payment Socket](https://m4kr0.vercel.app/posts/iso-8583-under-fire-finding-vulnerabilities-in-a-payment-socket/) 994 - [16] [Fuyao Enterprise: Building an Ad-Fraud Empire with AI and Kids' Coding Blocks](https://bitsight.com/blog/fuyao-enterprise-building-ad-fraud-empire-ai-and-kids-coding-blocks) 995 - [17] [Application Security Wiki](https://appsecwiki.com/#/) - It is a great list of resources 996 - [18] [clearbluejar.github.io - Desuperpacking Meta Superpacked Apks With Github Actions](https://clearbluejar.github.io/posts/desuperpacking-meta-superpacked-apks-with-github-actions) 997 - [19] [android-developers.googleblog.com - Run Arm Apps On Android Emulator](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html) 998 - [20] [Zero-Click File Drop on Xiaomi ShareMe (MiDrop)](https://blog.byterialab.com/zero-click-file-drop-on-xiaomi-shareme-midrop/) 999 - [21] [Byterialab mishare-zero-click-file-drop PoC repository](https://github.com/Byterialab/mishare-zero-click-file-drop)