Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port MASTG-TEST-0024: Testing for App Permissions (android) (by @appknox) #3076

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ScreaMy7
Copy link
Collaborator

closes #2985

@cpholguera
Copy link
Collaborator

Could you please include a MASTG-DEMO as well using our app?

This greatly helps understanding the test, so we're going to make this a requirement for everyone from now on (unless there's a good reason to schedule it for later, e.g. due to great complexity). Thanks a lot @ScreaMy7!

@ScreaMy7 ScreaMy7 requested a review from cpholguera January 23, 2025 13:47
@ScreaMy7
Copy link
Collaborator Author

ScreaMy7 commented Feb 9, 2025

@cpholguera, I have updated the format and added a demo as well. Please review.

@cpholguera cpholguera changed the title Port MASTG-TEST-0024 (by @appknox) Port MASTG-TEST-0024 - Testing for App Permissions (Android) (by @appknox) Feb 12, 2025
platform: android
title: Testing for App Permissions
id: MASTG-TEST-0x24
weakness: MASWE-0116
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new weakness is being created here:

#3119

Suggested change
weakness: MASWE-0116
weakness: MASWE-0117

platform: android
title: Application using unsafe permissions.
id: MASTG-DEMO-0023
code: [java]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
code: [java]
code: [kotlin]


### Sample

{{ AndroidManifest.xml }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{{ AndroidManifest.xml }}
{{ AndroidManifest.xml # AndroidManifest_reversed.xml }}

@@ -0,0 +1 @@
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-unsafe-app-permissons.yaml ./AndroidManifest.xml --text -o output.txt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use "reversed" code:

Suggested change
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-unsafe-app-permissons.yaml ./AndroidManifest.xml --text -o output.txt
NO_COLOR=true semgrep -c ../../../../rules/mastg-android-unsafe-app-permissons.yaml ./AndroidManifest_reversed.xml --text -o output.txt


## Evaluation

Please refer to this [permissions overview](https://developer.android.com/guide/topics/permissions/overview) for descriptions of the listed permissions that are considered dangerous.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See https://docs.google.com/document/d/1EMsVdfrDBAu0gmjWAUEs60q-fWaOmDB5oecY9d9pOlg/edit?pli=1&tab=t.0#heading=h.lare0v58fwbf

Using the observation as input, the evaluation tells you how to evaluate it and must explicitly describe what makes the test fail.

It should start with “The test case fails if …”

This one's easy: we compare the permissions we obtained with the list of dangerous ones, right? The test fails if there are any dangerous permissions in the app.

Specify the source to obtain the list of dangerous permissions (<permission> -> android:protectionLevel): https://android.googlesource.com/platform/frameworks/base/%2B/master/core/res/AndroidManifest.xml#886

Please note that this test as-is would produce a lot of false positives. We can add some more text here in the evaluation to explain that.

**Context Considerations**:

To reduce false positives,


## Overview

Testing for app permissions in Android involves evaluating how an application requests, uses, and manages permissions to ensure they do not lead to security vulnerabilities. Proper permission management should protect sensitive user data and ensure that the application complies with Android's security model. The test aims to detect misconfigurations and unnecessary permissions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing for app permissions in Android involves evaluating how an application requests, uses, and manages permissions to ensure they do not lead to security vulnerabilities. Proper permission management should protect sensitive user data and ensure that the application complies with Android's security model.

This part feels extremely generic.

  • Runtime = dangerous?
  • Why are we testing for "Dangerous App Permissions"?
  • Why is this important?
  • How does a developer add them and why would they do it instead of using other privacy-friendly options?

The test aims to detect misconfigurations and unnecessary permissions.

This doesn't seem to be what this test currently does.


- Permission Scope: Pay attention to runtime permissions (introduced in Android 6.0) versus manifest-declared permissions. Some permissions require explicit user approval at runtime.

- Refer to this [listed permissions](https://stackoverflow.com/questions/36936914/list-of-android-permissions-normal-permissions-and-dangerous-permissions-in-api) that are considered dangerous.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such a reference belongs in the test, this is just a technique and does not "evaluate" anything. Please use official sources instead.


Additional Notes:

- Permission Scope: Pay attention to runtime permissions (introduced in Android 6.0) versus manifest-declared permissions. Some permissions require explicit user approval at runtime.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we get the list of runtime permissions?

Comment on lines 70 to 76
## Using @MASTG-TOOL-0031

Apart from enforcing custom permissions via the application manifest file, you can also check permissions using dynamic instrumentation. This is not recommended, however, because it is more error-prone and can be bypassed more easily with, e.g., runtime instrumentation. It is recommended that the ContextCompat.checkSelfPermission method is called to check if an activity has a specified permission. You can use this frida script from the [frida codeshare](https://codeshare.frida.re/@ScreaMy7/hookpermissions/) to check for runtime permissions.

```bash
frida -U -l hookpermissions.js -f org.owasp.mastestapp
```
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this doesn't belong here, it feels like it could be a different technique but I don't see the test using this, so let's get it out for now.

Comment on lines 8 to 26
## Using @MASTG-TOOL-0018

You can use Jadx or Jadx-GUI to decompile APK files and access the AndroidManifest.xml file. This allows you to view the permissions declared in the application and inspect their usage in the code. Jadx is particularly useful for static analysis as it can also decompile application code, helping identify how permissions are utilized within the app logic.

Steps:

1. Open the APK file in Jadx or Jadx-GUI.
2. Navigate to the AndroidManifest.xml file to view the declared permissions.

## Using @MASTG-TOOL-0011

You can also decompile an APK using APKTool to extract the AndroidManifest.xml file.

```bash
apktool d org.owasp.mastestapp.apk
```

This command decompresses the APK and extracts all resources, including the manifest file, which lists the permissions.
APKTool is useful for detailed reverse engineering and modifying app resources if needed.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this overlaps with

https://mas.owasp.org/MASTG/techniques/android/MASTG-TECH-0117/

So you could say something like:

## Using the AndroidManifest

Extract the AndroidManifest.xml as explained in @MASTG-TECH-0117 and retrieve all [`<uses-permission>`](https://developer.android.com/guide/topics/manifest/uses-permission-element) elements.

And you can extend MASTG-TECH-0117 with jadx.

@cpholguera cpholguera changed the title Port MASTG-TEST-0024 - Testing for App Permissions (Android) (by @appknox) Port MASTG-TEST-0024: Testing for App Permissions (android) (by @appknox) Feb 24, 2025
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this test file to the MASVS-PRIVACY folder after addressing the comments below.

@cpholguera
Copy link
Collaborator

@ScreaMy7 any news on this? Thanks

@ScreaMy7
Copy link
Collaborator Author

ScreaMy7 commented Mar 5, 2025

@ScreaMy7 any news on this? Thanks

It's almost complete—I made a few changes and applied changes from the review.

reviewed and fixed.
@ScreaMy7 ScreaMy7 requested a review from cpholguera March 7, 2025 16:26
@ScreaMy7
Copy link
Collaborator Author

ScreaMy7 commented Mar 7, 2025

@cpholguera I have made the requested changes. I don't know why the URL link check failed, the link mentioned opens fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MASTG v1->v2 MASTG-TEST-0024: Testing for App Permissions (android)
2 participants