Optimize the document of Quark Script CWE-502, 297, 1204, and 24 #61
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-502 in Android Application
This scenario seeks to find Deserialization of Untrusted Data in the APK file.
CWE-502: Deserialization of Untrusted Data
We analyze the definition of CWE-502 and identify its characteristics.
See CWE-502 for more details.
Code of CWE-502 in pivaa.apk
We use the pivaa.apk sample to explain the vulnerability code of CWE-502.
CWE-502 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 created a detection rule named
deserializeData.json
to identify behaviors that deserialize data.Next, we retrieve the methods that interact with the deserialization API. Following this, we check if the methods match any APIs for verifying data.
If NO, it could imply that the APK deserializes the untrusted data, potentially leading to a CWE-502 vulnerability.
Quark Script CWE-502.py
Quark Rule: deserializeData.json
Quark Script Result
Detect CWE-297 in Android Application
This scenario seeks to find Improper Validation of Certificate with Host Mismatch.
CWE-297: Improper Validation of Certificate with Host Mismatch
We analyze the definition of CWE-297 and identify its characteristics.
See CWE-297 for more details.
Code of CWE-297 in pivaa.apk
We use the pivaa.apk sample to explain the vulnerability code of CWE-297.
CWE-297 Detection Process Using Quark Script API
First, we use API
findMethodImpls(samplePath, targetMethod)
to locate the method that implements the hostname verification, which verifies the hostname of a certificate.Next, we use API
isMethodReturnAlwaysTrue(samplePath, targetMethod)
to check if the method always returns true.If the answer is YES, the method does not check the certificate of the host properly, which may cause CWE-297 vulnerability.
Quark Script CWE-297.py
Quark Script Result
Detect CWE-1204 in Android Application
This scenario seeks to find Generation of Weak Initialization Vector (IV).
CWE-1204: Generation of Weak Initialization Vector (IV)
We analyze the definition of CWE-1204 and identify its characteristics.
See CWE-1204 for more details.
Code of CWE-1204 in InsecureBankv2.apk
We use the InsecureBankv2.apk sample to explain the vulnerability code of CWE-1204.
CWE-1204 Detection Process Using Quark Script API
Let’s use the above APIs to show how the Quark script finds this vulnerability.
First, we created a detection rule named
initializeCipherWithIV.json
to identify behaviors that initialize a cipher object with IV.Then, we use API
behaviorInstance.isArgFromMethod(targetMethod)
to check if any random API is applied on the IV used in the cipher object. If NO, it could imply that the APK uses a weak IV, potentially leading to a CWE-1204 vulnerability.Quark Scipt: CWE-1204.py
Quark Rule: initializeCipherWithIV.json
Quark Script Result
Detect CWE-24 in Android Application
This scenario aims to demonstrate the detection of the Relative Path Traversal vulnerability.
CWE-24: Path Traversal: '../filedir'
We analyze the definition of CWE-24 and identify its characteristics.
See CWE-24 for more details.
Code of CWE-24 in ovaa.apk
We use the ovaa.apk sample to explain the vulnerability code of CWE-24.
CWE-24 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
accessFileInExternalDir.json
to identify behavior that accesses a file in an external directory.Next, we use
methodInstance.getArguments()
to retrieve the file path argument and check whether it belongs to the APK. If it does not belong to the APK, the argument is likely from external input.Finally, we use the Quark Script API
quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)
to search for any APIs in the caller method that are used to match strings, andgetParamValues(none)
to retrieve the parameters.If no API is found or
"../"
is not in parameters, that implies the APK does not neutralize the special element../
within the argument, possibly resulting in CWE-24 vulnerability.Quark Script: CWE-24.py
Quark Rule: accessFileInExternalDir.json
Quark Script Result