Optimize the document of Quark Script CWE-22 #50
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-22 in Android Application
This scenario seeks to find the improper limitation of a pathname to a restricted directory (‘Path Traversal’).
CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
We analyze the definition of CWE-22 and identify its characteristics.
See CWE-22 for more details.
Code of CWE-22 in ovaa.apk
We use the ovaa.apk sample to explain the vulnerability code of CWE-22.
CWE-22 Detection Process Using Quark Script API
Let’s use the above APIs to show how the Quark script finds this vulnerability.
First, we design a detection rule
accessFileInExternalDir.json
to spot behavior accessing a file in an external directory.Next, we use API
methodInstance.getArguments()
to get the argument for the file path and usequarkResultInstance.isHardcoded(argument)
to check if the argument is hardcoded into the APK. If No, the argument is from external input.Finally, we use Quark API
quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)
to check if there are any APIs in the caller method for string matching. If NO, the APK does not neutralize special elements within the argument, which may cause CWE-22 vulnerability.Quark Scipt: CWE-22.py
Quark Rule: accessFileInExternalDir.json
Quark Script Result