Optimize the document of Quark Script CWE-89, 117, and 295 #58
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-89 in Android Application
This scenario seeks to find SQL injection in the APK file.
CWE-89 Improper Neutralization of Special Elements used in an SQL Command
We analyze the definition of CWE-89 and identify its characteristics.
See CWE-89 for more details.
Code of CWE-89 in AndroGoat.apk
We use the AndroGoat.apk sample to explain the vulnerability code of CWE-89.
CWE-89 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
executeSQLCommand.jsonto spot on behavior using SQL command Execution. Then, we use APIbehaviorInstance.isArgFromMethod(targetMethod)to check ifappenduses the value ofgetTextas the argument. If yes, we confirmed that the SQL command string is built from user input, which will cause CWE-89 vulnerability.Quark Script: CWE-89.py
Quark Rule: executeSQLCommand.json
{ "crime": "Execute SQL Command", "permission": [], "api": [ { "class": "Ljava/lang/StringBuilder;", "method": "append", "descriptor": "(Ljava/lang/String;)Ljava/lang/StringBuilder;" }, { "class": "Landroid/database/sqlite/SQLiteDatabase;", "method": "rawQuery", "descriptor": "(Ljava/lang/String; [Ljava/lang/String;)Landroid/database/Cursor;" } ], "score": 1, "label": [] }Quark Script Result
Detect CWE-117 in Android Application
This scenario seeks to find Improper Output Neutralization for Logs.
CWE-117: Improper Output Neutralization for Logs
We analyze the definition of CWE-117 and identify its characteristics.
See CWE-117 for more details.
Code of CWE-117 in allsafe.apk
We use the allsafe.apk sample to explain the vulnerability code of CWE-117.
CWE-117 Detection Process Using Quark Script API
First, we design a detection rule
writeContentToLog.jsonto spot on behavior using the method that writes contents to the log file.Then, we use
methodInstance.getArguments()to get all parameter values of this method. And we check if these parameters contain keywords of APIs for neutralization, such asescape,replace,format, andsetFilter.If the answer is YES, that may result in secret context leakage into the log file, or the attacker may perform log forging attacks.
Quark Script CWE-117.py
Quark Rule: writeContentToLog.json
{ "crime": "Write contents to the log", "permission": [], "api": [ { "descriptor": "()Landroid/text/Editable;", "class": "Lcom/google/android/material/textfield/TextInputEditText;", "method": "getText" }, { "descriptor": "(Ljava/lang/String;Ljava/lang/String;)I", "class": "Landroid/util/Log;", "method": "d" } ], "score": 1, "label": [] }Quark Script Result
Detect CWE-295 in Android Application
This scenario seeks to find Improper Certificate Validation.
CWE-295: Improper Certificate Validation
We analyze the definition of CWE-295 and identify its characteristics.
See CWE-295 for more details.
Code of CWE-295 in InsecureShop.apk
We use the InsecureShop.apk sample to explain the vulnerability code of CWE-295.
CWE-295 Detection Process Using Quark Script API
To begin with, we use the API
findMethodInAPK(samplePath, targetMethod)to locate all callers of methodSslErrorHandler.proceed.Next, we must verify whether the caller overrides the method
WebViewClient.onReceivedSslError.Therefore, we check if the caller has the same method name and descriptor as
WebViewClient.onReceivedSslError, then usefindSuperclassHierarchy()to see if its class extendsLandroid/webkit/WebViewClient.If both are YES, the APK will proceed with HTTPS connections without certificate validation when an SSL error occurs, which may cause CWE-295 vulnerability.
Quark Script CWE-295.py
Quark Script Result