Day 53 of 75 days Ethical hacking
Android Permission Model and Application Sandboxing Overview
The Android permission model ensures that an application only has access to the resources or data that have been explicitly a llowed by the user or system,
protecting user data and the core functionalities from malicious or unauthorized apps. Below is a comprehensive explanation o f how Android manages
permissions and implements sandboxing for security.
Android Permission Model:
1. Permission Categories:
• Normal Permissions:
○ Low-risk permissions are automatically granted during app installation.
○ Example: Internet access, setting alarms.
• Dangerous Permissions:
○ High-risk permissions that access sensitive user data.
○ These require runtime user consent.
○ Example: Accessing camera, reading SMS, location data.
2. Permission Groups:
• Permissions are grouped for organizational purposes:
○ CAMERA: For photos and video capture.
○ LOCATION: For GPS or network-based location tracking.
○ CONTACTS: For accessing phone contacts.
3. Manifest Declaration:
• Every app must declare its permissions in the AndroidManifest.xml file.
• Example:
xml
t
<uses-permission android:name="android.permission.CAMERA" />
4. Runtime Permissions (Android 6.0 and later):
• Permissions are requested dynamically when needed.
• The user is prompted to allow or deny permissions.
• Example code for requesting permission:
java
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CODE);
}
5. Permission Workflow:
• Request Permission: When an app first requests a dangerous permission, the user sees a prompt.
• User Action: The user either allows or denies the permission.
• Result Handling:
○ If the user denies the permission, the app must handle this gracefully and provide alternative functionality.
○ Example:
j
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == REQUEST_CODE) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Permission granted
} else {
// Permission denied
}
}
}
6. Special Permissions:
• These permissions are different from normal and dangerous ones and require specific user approval in settings.
○ Draw Over Other Apps: To show a floating view in the background.
○ Modify System Settings: To change system settings like brightness or ringtone.
7. Permission Best Practices:
• Only request permissions necessary for the app's functionality.
• Inform users why a particular permission is required (provide context).
• Respect each denial and try to offer alternative functionality.
Common Vulnerabilities in Permission Model:
• Over-Permissioning: Apps request unnecessary permissions.
Android Penetration testing Page 1
• Over-Permissioning: Apps request unnecessary permissions.
• Privilege Escalation: An app may misuse permissions to indirectly allow access to another malicious app.
• Improper Handling: Improper checks while handling runtime permissions can lead to security vulnerabilities.
Pentesting the Permission Model:
During Android penetration testing, auditing permissions is crucial:
1. Manifest File Analysis: Check which permissions are requested.
○ Use tools like apktool or jadx to decompile the APK and analyze the AndroidManifest.xml file.
2. Permission Misuse:
○ Identify if the app requests unnecessary sensitive permissions.
3. Test Runtime Permissions:
○ Analyze user prompts and runtime behavior.
4. Intent and Broadcast Attacks:
○ Check for potential permission bypass via exported components like activities, services, or broadcast receivers.
Application Sandboxing:
Application Sandboxing is a core security feature in Android that ensures an app's operations and data do not interfere with other apps or the system's
sensitive resources. It provides an isolated execution environment for each app, with strict access controls.
What is Application Sandboxing?
Sandboxing means running an application in a restricted environment where:
1. Data Isolation: An app isolates its private data from other apps.
2. Resource Protection: System resources such as memory, file systems, and hardware components are protected from unauthorized access.
3. Controlled Communication: Apps can only communicate through limited and explicitly allowed interfaces (such as Intents or Content Providers).
How Sandboxing Works in Android?
1. Unique User ID (UID):
○ Android assigns a unique User ID (UID) to each application.
○ An app's data is only accessible under that UID.
○ Two apps have different UIDs (except when sharedUserId is explicitly used).
2. File System Isolation:
○ Each app’s private data is stored in the /data/data/<package_name> directory.
○ Default permissions prevent one app from directly accessing another's data.
3. Process Isolation:
○ Each app runs in its own Linux process.
○ Memory access between processes is restricted, preventing unauthorized sharing or tampering of memory.
4. System APIs:
○ Apps can only access hardware and sensitive data via system-authorized APIs.
○ Direct hardware or kernel-level access is disallowed.
5. Permission Model Integration:
○ The combination of sandboxing and permissions ensures that even if an app wants to interact outside its sandbox, explicit user consent is required.
6. SELinux (Security-Enhanced Linux):
○ Android uses SELinux to enforce mandatory access controls (MAC).
○ It ensures that even root processes or compromised system apps cannot perform unauthorized operations.
Android Penetration testing Page 2
Android Penetration testing Page 3