|
| 1 | +--- |
| 2 | +title: Testing Obfuscation |
| 3 | +platform: android |
| 4 | +id: MASTG-TEST-0051 |
| 5 | +type: [static, dynamic] |
| 6 | +profiles: [R] |
| 7 | +--- |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +Code obfuscation is a form of software protection that makes code more difficult to understand and analyze, thereby increasing the effort required for reverse engineering. While obfuscation doesn't prevent reverse engineering entirely, it raises the bar for attackers by making static and dynamic analysis more time-consuming and complex. |
| 12 | + |
| 13 | +This test checks whether the app implements obfuscation techniques to protect sensitive code and data. Common obfuscation techniques include: |
| 14 | + |
| 15 | +- **Name obfuscation**: Replacing meaningful class, method, and variable names with meaningless identifiers |
| 16 | +- **String encryption**: Encrypting hardcoded strings and decrypting them at runtime |
| 17 | +- **Control flow flattening**: Restructuring code to make the program flow harder to follow |
| 18 | +- **Dead code injection**: Adding non-functional code to increase analysis overhead |
| 19 | +- **Instruction substitution**: Replacing standard instructions with more complex equivalents |
| 20 | + |
| 21 | +For Android apps, obfuscation can be applied at both the Java bytecode level (using tools like ProGuard or R8) and the native code level (using tools like Obfuscator-LLVM). |
| 22 | + |
| 23 | +## Steps |
| 24 | + |
| 25 | +### Static Analysis |
| 26 | + |
| 27 | +1. Decompile the APK using @MASTG-TECH-0017. |
| 28 | +2. Review the decompiled code using @MASTG-TECH-0023 to identify obfuscation patterns: |
| 29 | + - Look for meaningless class, method, and variable names (e.g., `a`, `b`, `aa`, `ab`) |
| 30 | + - Check for encrypted or encoded string literals |
| 31 | + - Examine the control flow structure for signs of flattening or complex branching |
| 32 | + - Identify any dead code or dummy instructions |
| 33 | +3. For native libraries, analyze using @MASTG-TECH-0018 to detect: |
| 34 | + - Symbol stripping |
| 35 | + - Control flow obfuscation |
| 36 | + - Instruction substitution |
| 37 | + - API call obfuscation |
| 38 | + |
| 39 | +### Dynamic Analysis |
| 40 | + |
| 41 | +1. Use @MASTG-TOOL-0009 to analyze the APK and detect obfuscation techniques: |
| 42 | + |
| 43 | + ```bash |
| 44 | + apkid <app.apk> |
| 45 | + ``` |
| 46 | + |
| 47 | +2. Look for indicators such as: |
| 48 | + - "unreadable field names" |
| 49 | + - "unreadable method names" |
| 50 | + - Specific obfuscator signatures |
| 51 | + - Packer identification |
| 52 | + |
| 53 | +## Observation |
| 54 | + |
| 55 | +The output should include: |
| 56 | + |
| 57 | +### Static Analysis |
| 58 | + |
| 59 | +- Evidence of name obfuscation (meaningless identifiers in decompiled code) |
| 60 | +- Presence of encrypted or obfuscated strings |
| 61 | +- Complex or flattened control flow structures |
| 62 | +- Native code obfuscation indicators |
| 63 | + |
| 64 | +### Dynamic Analysis |
| 65 | + |
| 66 | +- APKiD detection results showing obfuscation techniques |
| 67 | +- Identified obfuscators, packers, or protection tools |
| 68 | + |
| 69 | +## Evaluation |
| 70 | + |
| 71 | +The test case passes if obfuscation techniques are properly implemented: |
| 72 | + |
| 73 | +- **For basic obfuscation**: Class, method, and variable names should be meaningless identifiers rather than descriptive names |
| 74 | +- **For string protection**: Sensitive strings should be encrypted or encoded, not stored in plaintext |
| 75 | +- **For control flow protection**: Code structure should show signs of flattening or complexity beyond normal compilation |
| 76 | +- **For native code**: Symbols should be stripped and code should show signs of obfuscation |
| 77 | + |
| 78 | +The test case fails if: |
| 79 | + |
| 80 | +- No obfuscation is detected in either Java bytecode or native code |
| 81 | +- Sensitive functionality uses clear, descriptive names that aid reverse engineering |
| 82 | +- Hardcoded secrets, keys, or sensitive strings are stored in plaintext |
| 83 | +- The code structure follows standard, easily readable patterns without any protection |
| 84 | + |
| 85 | +Note that the effectiveness of obfuscation should be evaluated based on the sensitivity of the protected functionality and the threat model of the application. |
0 commit comments