Optimize the document of Quark Script CWE-338, 489, and 532 #60
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-338 in Android Application
This scenario seeks to find Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG).
CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)
We analyze the definition of CWE-338 and identify its characteristics.
See CWE-338 for more details.
Code of CWE-338 in pivaa.apk
We use the pivaa.apk sample to explain the vulnerability code of CWE-338.
CWE-338 Detection Process Using Quark Script API
First, we design a detection rule
useMethodOfPRNG.jsonto spot on behavior that uses Pseudo Random Number Generator (PRNG). Then, we use APImethodInstance.getXrefFrom()to get the caller method of PRNG. Finally, we use some keywords such as "token", "password", and "encrypt" to check if the PRNG is for credential usage.Quark Script CWE-338.py
Quark Rule: useMethodOfPRNG.json
{ "crime": "Use method of PRNG", "permission": [], "api": [ { "class": "Ljava/util/Random;", "method": "<init>", "descriptor": "()V" }, { "class": "Ljava/util/Random;", "method": "nextInt", "descriptor": "(I)I" } ], "score": 1, "label": [] }Quark Script Result
Detect CWE-489 in Android Application
This scenario seeks to find active debug code.
CWE-489: Active Debug Code
We analyze the definition of CWE-489 and identify its characteristics.
See CWE-489 for more details.
Code of CWE-489 in allsafe.apk
We use the allsafe.apk sample to explain the vulnerability code of CWE-489.
CWE-489 Detection Process Using Quark Script API
First, we use Quark API
getApplication(samplePath)to get the application element in the manifest file. Then we useapplicationInstance.isDebuggable()to check if the application element sets the attributeandroid:debuggableto true. If Yes, that causes CWE-489 vulnerabilities.Quark Script CWE-489.py
Quark Script Result
Detect CWE-532 in Android Application
This scenario seeks to find insertion of sensitive information into Log file in the APK file.
CWE-532: Insertion of Sensitive Information into Log File
We analyze the definition of CWE-532 and identify its characteristics.
See CWE-532 for more details.
Code of CWE-532 in dvba.apk
We use the dvba.apk sample to explain the vulnerability code of CWE-532.
CWE-532 Detection Process Using Quark Script API
Let's use the above APIs to show how the Quark script finds this vulnerability.
First, we use the API
findMethodInAPK(samplePath, targetMethod)to locatelog.dmethod. Then we use APImethodInstance.getArguments()to get the argument that input tolog.d. Finally, we use some keywords such as "token", "password", and "decrypt" to check if arguments include sensitive data. If the answer is YES, that may cause sensitive data leakage into log file.You can use your own keywords in the keywords list to detect sensitive data.
Quark Script: CWE-532.py
Quark Script Result