Optimize the document of Quark Script CWE-20, 94, 921 #49
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-20 in Android Application
This scenario seeks to find Improper Input Validation in the APK file.
CWE-20: Improper Input Validation
We analyze the definition of CWE-20 and identify its characteristics.
See CWE-20 for more details.
Code of CWE-20 in diva.apk
We use the diva.apk sample to explain the vulnerability code of CWE-20.
CWE-20 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
openUrlThatUserInput.json
, to spot the behavior of opening the URL that the user inputs. Then, we use APIbehaviorInstance.getMethodsInArgs()
to get a list of methods that the URL inloadUrl
passes through. Finally, we check if any validation method is in the list. If No, the APK does not validate user input. That causes CWE-20 vulnerability.Quark Script CWE-20.py
Quark Rule: openUrlThatUserInput.json
Quark Script Result
Detect CWE-94 in Android Application
This scenario seeks to find code injection in the APK file.
CWE-94: Improper Control of Generation of Code
We analyze the definition of CWE-94 and identify its characteristics.
See CWE-94 for more details.
Code of CWE-94 in ovaa.apk
We use the ovaa.apk sample to explain the vulnerability code of CWE-94.
CWE-94 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
loadExternalCode.json
to spot on behavior using the methodcreatePackageContext
. Then, we find the caller method that calls thecreatePackageContext
. Finally, we check if the methodcheckSignatures
is called in the caller method for verification.Quark Script: CWE-94.py
Quark Rule: loadExternalCode.json
Quark Script Result
Detect CWE-921 in Android Application
This scenario seeks to find the unsecured storage mechanism of sensitive data in the APK file.
CWE-921: Storage of Sensitive Data in a Mechanism without Access Control
We analyze the definition of CWE-921 and identify its characteristics.
See CWE-921 for more details.
Code of CWE-921 in ovaa.apk
We use the ovaa.apk sample to explain the vulnerability code of CWE-921.
CWE-921 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
checkFileExistence.json
to spot on behavior that checks if a file exists on a given storage mechanism. Then, we use APImethodInstance.getArguments()
to get the file path. Finally, CWE-921 is found if the file path contains the keywordsdcard
.Quark Script: CWE-921.py
Quark Rule: checkFileExistence.json
Quark Script Result