Chapter 30 Exercises: Mobile Application Security
Exercise 30.1: Android Manifest Analysis (Beginner)
Analyze the following AndroidManifest.xml excerpt and identify all security issues:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.medsecure.provider"
android:debuggable="true">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.READ_SMS" />
<application
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:label="MedSecure Provider">
<activity android:name=".LoginActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="medsecure" android:host="login" />
</intent-filter>
</activity>
<activity android:name=".PatientDetailActivity"
android:exported="true" />
<provider
android:name=".data.PatientContentProvider"
android:authorities="com.medsecure.provider.patients"
android:exported="true"
android:grantUriPermissions="true" />
<receiver android:name=".PushReceiver"
android:exported="true" />
<service android:name=".SyncService"
android:exported="true" />
</application>
</manifest>
For each issue: (a) identify the vulnerability, (b) explain the risk, (c) provide the corrected configuration.
Exercise 30.2: Hardcoded Secrets Discovery (Beginner)
Given the following code snippets from a decompiled Android application, identify all hardcoded secrets and explain the risk of each:
public class ApiClient {
private static final String API_KEY = "sk_live_4eC39HqLyjWDarjtT1zdp7dc";
private static final String BASE_URL = "https://api.medsecure-example.com";
private static final String AWS_ACCESS_KEY = "AKIAIOSFODNN7EXAMPLE";
private static final String ENCRYPTION_KEY = "MedSecure2024!@#$";
public void authenticate(String username, String password) {
SharedPreferences prefs = context.getSharedPreferences("auth", MODE_PRIVATE);
prefs.edit().putString("password", password).apply();
Log.d("AUTH", "Login attempt: " + username + ":" + password);
}
}
For each secret: identify it, explain the risk, and describe the secure alternative.
Exercise 30.3: Frida Scripting Basics (Intermediate)
Write Frida scripts to accomplish the following tasks on an Android application:
- Hook the
SharedPreferences.getString()method to log all key-value reads - Hook the
android.util.Logclass to capture all debug log messages - Hook the
java.net.URLconstructor to log all URLs the application connects to - Bypass a method called
isDeviceSecure()in classcom.app.SecurityCheckthat returns a boolean
Test your scripts against the DIVA (Damn Insecure and Vulnerable App) or a similar practice application.
Exercise 30.4: SSL Pinning Bypass (Intermediate)
You are testing a mobile banking application that implements certificate pinning. You have configured Burp Suite as a proxy and installed the Burp CA certificate on your test device, but the application refuses to connect.
- Explain why the application rejects the proxy certificate despite having the Burp CA installed
- Write a Frida script to bypass certificate pinning for OkHttp3
- Write a Frida script to bypass certificate pinning for Android's default
HttpsURLConnection - Describe how Objection can be used as an alternative approach
- Discuss the limitations of certificate pinning bypass and when it might fail
Exercise 30.5: Local Data Storage Assessment (Intermediate)
Perform a complete local data storage assessment on a practice Android application:
- Install DIVA or InsecureBankv2 on an emulator or rooted device
- Use the application (log in, browse features, enter data)
- Examine the following storage locations for sensitive data: - SharedPreferences files - SQLite databases - Internal storage files - External storage files - Application cache - Log files
- Document all sensitive data found, the storage location, and whether it was encrypted
- Write a remediation recommendation for each finding
Exercise 30.6: APK Reverse Engineering (Intermediate)
Using jadx and apktool, perform a complete static analysis of a practice APK:
- Decompile the APK using both tools
- Analyze the AndroidManifest.xml for security issues
- Search for hardcoded strings (API keys, URLs, credentials)
- Identify the app's network communication patterns
- Review the authentication flow
- Check for cryptographic implementations and assess their security
- Look for debug/test code that should not be in production
- Create a summary report with findings categorized by OWASP Mobile Top 10
Exercise 30.7: OWASP Mobile Top 10 Mapping (Intermediate)
For each of the following vulnerability descriptions, identify the OWASP Mobile Top 10 category and explain how you would test for it:
- The app stores the user's session token in SharedPreferences without encryption
- The app allows login with only a 4-digit PIN that can be brute-forced
- The app uses DES encryption for local database encryption
- The app's API returns the user's SSN in the profile response, though the app only displays the last 4 digits
- The app has a hidden admin menu accessible via a specific gesture sequence
- The app does not validate the server's SSL certificate
- The app requests camera, microphone, contacts, and SMS permissions for a note-taking function
- The app's client-side checks for premium features can be bypassed with Frida
Exercise 30.8: Mobile API Testing (Intermediate)
Set up and test a mobile API endpoint:
- Using Burp Suite, capture the traffic between a test mobile app and its backend
- Document all API endpoints discovered
- Test for the following vulnerabilities: - Broken Object Level Authorization (change resource IDs) - Mass assignment (add extra parameters to requests) - Missing rate limiting on the login endpoint - Excessive data exposure in responses - Missing input validation
- Write a brief penetration test report for the API findings
Exercise 30.9: Root/Jailbreak Detection Bypass (Advanced)
Research and implement bypasses for common root/jailbreak detection methods:
- Research at least five common root detection checks on Android: - File existence checks (su binary, Superuser.apk) - Build property checks (test-keys) - Package manager checks (Magisk, SuperSU) - Runtime.exec checks - Native library checks
- Write a comprehensive Frida script that bypasses all five methods
- Test your script against a practice app with root detection
- Discuss the arms race between detection and bypass — what advanced techniques make bypass more difficult?
Exercise 30.10: Cross-Platform App Analysis (Intermediate)
Analyze a React Native mobile application:
- Obtain a React Native APK (or build one for testing)
- Extract the JavaScript bundle from the APK:
assets/index.android.bundle - Analyze the JavaScript code for: - Hardcoded API endpoints and keys - Authentication logic - Business logic that should be server-side - Debug/development flags
- Compare the difficulty of analyzing React Native vs. native Java/Kotlin
- Discuss the security implications of using cross-platform frameworks
Exercise 30.11: Dynamic Analysis with MobSF (Intermediate)
Install and use the Mobile Security Framework (MobSF) for automated analysis:
- Deploy MobSF using Docker
- Upload a practice APK for static analysis
- Review the automated findings: - Manifest analysis results - Code analysis findings - Hardcoded secrets detection - Network security assessment
- Perform dynamic analysis (if emulator is available)
- Compare MobSF's automated findings with your manual analysis
- Identify false positives and false negatives in MobSF's results
Exercise 30.12: iOS Keychain Assessment (Advanced)
On a jailbroken iOS device or simulator with the appropriate tools:
- Install a practice iOS application
- Use Objection to dump the Keychain entries created by the app
- Analyze each Keychain item: - What protection class is used (WhenUnlocked, AfterFirstUnlock, Always)? - Is the data accessible when the device is locked? - Is the item configured for backup?
- Use Frida to hook Keychain API calls and observe what data is stored and retrieved
- Assess whether the Keychain is being used correctly for the type of data being stored
Exercise 30.13: BLE Security Testing (Advanced)
MedSecure's app communicates with IoT medical devices over Bluetooth Low Energy (BLE):
- Research BLE security vulnerabilities relevant to healthcare devices
- Using a BLE-capable device and tools like nRF Connect or BTLE-Sniffer: - Scan for BLE devices in the testing area - Connect to a test BLE device - Enumerate services and characteristics - Test for unencrypted communication - Test for authentication requirements
- Write a Frida script that hooks the Android BluetoothGatt class to intercept BLE communication
- Discuss the unique risks of BLE vulnerabilities in medical device contexts
Exercise 30.14: Mobile App Penetration Test Report (Advanced)
Perform a complete mobile application penetration test against a practice app (DIVA, InsecureBankv2, or similar) and produce a professional report including:
- Executive Summary
- Scope and Methodology
- Findings with: - Severity rating - OWASP Mobile Top 10 mapping - Description and evidence (screenshots) - Impact assessment - Remediation recommendation
- Positive observations (security controls that were effective)
- Strategic recommendations
Exercise 30.15: MedSecure Mobile Threat Model (Advanced)
Create a comprehensive threat model for MedSecure's provider mobile application:
- Identify all assets (patient data, authentication tokens, BLE commands, session data)
- Map the data flows (app to API, app to BLE device, app to local storage)
- Identify threat actors (malicious app on same device, network attacker, physical device access, rogue BLE device)
- For each data flow, identify threats using STRIDE: - Spoofing - Tampering - Repudiation - Information Disclosure - Denial of Service - Elevation of Privilege
- Propose mitigations for each identified threat
- Prioritize mitigations based on risk and implementation effort