Add Quark script showcase of detecting CWE-359 #65
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Detect CWE-359 in Android Application
This scenario aims to demonstrate the detection of the Exposure of Private Personal Information to an Unauthorized Actor vulnerability.
CWE-359: Exposure of Private Personal Information to an Unauthorized Actor
We analyze the definition of CWE-359 and identify its characteristics.
See CWE-359 for more details.
Code of CWE-359 in ovaa.apk
We use the ovaa.apk sample to explain the vulnerability code of CWE-359.
CWE-359 Detection Process Using Quark Script API
Let’s use the above APIs to show how the Quark script finds this vulnerability.
To begin with, we create a detection rule named
accessFileWithUnsafeUriPath.jsonto identify behavior that accesses a file with an unsafe path fromUri.Next, we use API
methodInstance.methodCallerto retrieve the name of the caller that has this behavior.Then, we use API
quarkResultInstance.isHardcoded(argument)to check if the file path is hardcoded into the APK. If not, the file path is likely from external input.After that, we use API
getProviders(samplePath)andproviderInstance.isExported()to check if there is any exported provider that matches the caller class name. If yes, any external application can access the behavior.Finally, we use API
quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)to search for any APIs in the caller method that are used to match strings.If NO API is found, that implies the APK does not neutralize special elements within the argument, possibly resulting in a CWE-359 vulnerability.
Quark Script: CWE-359.py
Quark Rule: accessFileWithUnsafeUriPath.json
{ "crime": "Access a File with an unsafe path from Uri", "permission": [], "api": [ { "class": "Landroid/net/Uri;", "method": "getLastPathSegment", "descriptor": "()Ljava/lang/String;" }, { "class": "Ljava/io/File;", "method": "<init>", "descriptor": "(Ljava/io/File;Ljava/lang/String;)V" } ], "score": 1, "label": [] }Quark Script Result