Optimize the document of Quark Script CWE-73 and 78 #53
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-73 in Android Application
This scenario seeks to find External Control of File Name or Path in the APK file.
CWE-73 External Control of File Name or Path
We analyze the definition of CWE-73 and identify its characteristics.
See CWE-73 for more details.
Code of CWE-73 in ovaa.apk
We use the ovaa.apk sample to explain the vulnerability code of CWE-73.
CWE-73 Detection Process Using Quark Script API
Let’s use the above APIs to show how Quark script finds this vulnerability.
First, we design a detection rule
useLastPathSegmentAsFileName.json
to spot behavior that uses the last path segment as the file name.Second, we use the 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 opening files. If YES, the APK performs file operations using external input as a path, which may cause CWE-73 vulnerability.Quark Script: CWE-73.py
Quark Rule: useLastPathSegmentAsFileName.json
Quark Script Result
Detect CWE-78 in Android Application
This scenario seeks to find Improper Neutralization of Special Elements used in an OS Command in the APK file.
CWE-78 Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
We analyze the definition of CWE-78 and identify its characteristics.
See CWE-78 for more details.
Code of CWE-78 in Vuldroid.apk
We use the Vuldroid.apk sample to explain the vulnerability code of CWE-78.
CWE-78 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
ExternalStringsCommands.json
to spot on behavior using external strings as commands.Next, we use Quark API
behaviorInstance.getMethodsInArgs()
to get the methods that passed the external command.Then we check if the method neutralizes any special elements in the argument.
If the neutralization is not complete, then it may cause CWE-78 vulnerability.
Quark Script: CWE-78.py
Quark Rule: ExternalStringCommand.json
Quark Script Result