| AID | 65 |
|---|---|
| MSTG-ID | MSTG-RESILIENCE-3 |
| Audit | The app detects, and responds to, tampering with executable files and critical data within its own sandbox. |
| Guidance | Testing File Integrity Checks Overview Code integrity checks: In the -- Tampering and Reverse Engineering -- chapter, we discussed Android's APK code signature check. We also saw that determined reverse engineers can easily bypass this check by re-packaging and re-signing an app. To make this bypassing process more involved, a protection scheme can be augmented with CRC checks on the app byte-code, native libraries, and important data files. These checks can be implemented on both the Java and the native layer. The idea is to have additional controls in place so that the app only runs correctly in its unmodified state, even if the code signature is valid. Sample Implementation - Application Source Code Integrity checks often calculate a checksum or hash over selected files. Commonly protected files include AndroidManifest.xml, Sample Implementation - Storage When providing integrity on the storage itself, you can either create an HMAC over a given key-value pair (as for the Android SharedPreferences) or create an HMAC over a complete file that's provided by the file system. When using an HMAC, you can use a bouncy castle implementation or the AndroidKeyStore to HMAC the given content. Complete the following procedure when generating an HMAC with BouncyCastle: Make sure BouncyCastle or SpongyCastle is registered as a security provider. Complete the following procedure when verifying the HMAC with BouncyCastle: Make sure that BouncyCastle or SpongyCastle is registered as a security provider. When generating the HMAC based on the Android Keystore, then it is best to only do this for Android 6 and higher. Bypassing File Integrity Checks Patch the anti-debugging functionality. Disable the unwanted behavior by simply overwriting the associated byte-code or native code with NOP instructions. Refer to the -- Tampering and Reverse Engineering -- section for examples of patching, code injection, and kernel modules. Retrieve the data from the device, as described in the section on device binding. Effectiveness Assessment Run the app in an unmodified state and make sure that everything works. Apply simple patches to classes.dex and any .so libraries in the app package. Re-package and re-sign the app as described in the -- Basic Security Testing -- chapter, then run the app. The app should detect the modification and respond in some way. At the very least, the app should alert the user and/or terminate. Work on bypassing the defenses and answer the following questions: Can the mechanisms be bypassed trivially (e.g., by hooking a single API function)? For storage integrity checks An approach similar to that for application-source integrity checks applies. Answer the following questions: Can the mechanisms be bypassed trivially (e.g., by changing the contents of a file or a key-value)? |
| Category | Impede Dynamic Analysis and Tampering |
| Function | Testing File Integrity Checks (MSTG-RESILIENCE-3) |
| Reference | github.com |
Google Android Mobile Applications Audit
Review this entry