Skip to content

Commit 998947d

Browse files
committed
Update document & READMD for CWE-921 Quark script
1 parent 502f9a2 commit 998947d

File tree

7 files changed

+69
-2
lines changed

7 files changed

+69
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ __See API document [here](https://quark-engine.readthedocs.io/en/latest/quark_sc
5656
### 2022 CWE Top 25 Showcases
5757
* [CWE-798](https://quark-engine.readthedocs.io/en/latest/quark_script.html#detect-cwe-798-in-android-application-ovaa-apk)
5858
* [CWE-94](https://quark-engine.readthedocs.io/en/latest/quark_script.html#detect-cwe-94-in-android-application-ovaa-apk)
59+
* [CWE-921](https://quark-engine.readthedocs.io/en/latest/quark_script.html#detect-cwe-921-in-android-application-ovaa-apk)
5960

6061
## Quark Web Report
6162

1.96 KB
Binary file not shown.

docs/build/html/genindex.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,8 @@ <h2 id="T">T</h2>
11851185
<li><a href="quark.utils.html#quark.utils.pprint.table">table() (in module quark.utils.pprint)</a>
11861186
</li>
11871187
<li><a href="quark.core.struct.html#quark.core.struct.tableobject.TableObject">TableObject (class in quark.core.struct.tableobject)</a>
1188+
</li>
1189+
<li><a href="quark.script.html#quark.script.Behavior.test">test() (quark.script.Behavior method)</a>
11881190
</li>
11891191
<li><a href="quark.core.axmlreader.html#quark.core.axmlreader.Res_value_type.TYPE_ATTRIBUTE">TYPE_ATTRIBUTE (quark.core.axmlreader.Res_value_type attribute)</a>
11901192
</li>

docs/build/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ <h1>Quark-Engine Book<a class="headerlink" href="#quark-engine-book" title="Perm
9999
<li class="toctree-l2"><a class="reference internal" href="quark_script.html#analyzing-real-case-instastealer-using-quark-script">Analyzing real case (InstaStealer) using Quark Script</a></li>
100100
<li class="toctree-l2"><a class="reference internal" href="quark_script.html#detect-cwe-798-in-android-application-ovaa-apk">Detect CWE-798 in Android Application (ovaa.apk)</a></li>
101101
<li class="toctree-l2"><a class="reference internal" href="quark_script.html#detect-cwe-94-in-android-application-ovaa-apk">Detect CWE-94 in Android Application (ovaa.apk)</a></li>
102+
<li class="toctree-l2"><a class="reference internal" href="quark_script.html#detect-cwe-921-in-android-application-ovaa-apk">Detect CWE-921 in Android Application (ovaa.apk)</a></li>
102103
</ul>
103104
</li>
104105
<li class="toctree-l1"><a class="reference internal" href="addRules.html">Add Rules</a></li>

docs/build/html/objects.inv

7 Bytes
Binary file not shown.

docs/build/html/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/source/quark_script.rst

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ Let's use this `APK <https://github.com/oversecured/ovaa>`_ and the above APIs t
220220

221221
First, we design a detection rule ``findSecretKeySpec.json`` to spot on behavior uses method SecretKeySpec. Then, we get all the parameter values that input to this method. From the returned parameter values, we identify it's a AES key and parse the key out of the values. Finally, we dump all strings in the APK file and check if the AES key is in the strings. If the answer is YES, BINGO!!! We find hard-coded credentials in the APK file.
222222

223-
Quark Scipt: cwe-798.py
223+
Quark Scipt: CWE-798.py
224224
========================
225225

226226
.. code-block:: python
@@ -372,3 +372,66 @@ Quark Script Result
372372
373373
Method: checkSignatures not found!
374374
CWE-94 is detected in ovaa.apk
375+
376+
377+
Detect CWE-921 in Android Application (ovaa.apk)
378+
------------------------------------------------
379+
380+
This scenario seeks to find unsecure storage mechanism of data in the APK file. See `CWE-921 <https://cwe.mitre.org/data/definitions/921.html>`_ for more details.
381+
382+
Let's use this `APK <https://github.com/oversecured/ovaa>`_ and the above APIs to show how Quark script find this vulnerability.
383+
384+
First, we design a detection rule ``checkFileExistence.json`` to spot on behavior that checks if a file exist on given storage mechanism. Then, we use API ``getParamValues()`` to get the file path. Finally, CWE-921 is found if the file path contains keyword ``sdcard``.
385+
386+
Quark Script CWE-921.py
387+
========================
388+
389+
.. code-block:: python
390+
391+
from quark.script import runQuarkAnalysis, Rule
392+
393+
SAMPLE_PATH = "ovaa.apk"
394+
RULE_PATH = "checkFileExistence.json"
395+
396+
ruleInstance = Rule(RULE_PATH)
397+
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
398+
399+
for existingFile in quarkResult.behaviorOccurList:
400+
filePath = existingFile.getParamValues()[0]
401+
if "sdcard" in filePath:
402+
print(f"This file is stored inside the SDcard\n")
403+
print(f"CWE-921 is detected in {SAMPLE_PATH}.")
404+
405+
Quark Rule: checkFileExistence.json
406+
====================================
407+
408+
.. code-block:: json
409+
410+
{
411+
"crime": "Check file existence",
412+
"permission": [],
413+
"api": [
414+
{
415+
"descriptor": "(Ljava/lang/String;)V",
416+
"class": "Ljava/io/File;",
417+
"method": "<init>"
418+
},
419+
{
420+
"descriptor": "()Z",
421+
"class": "Ljava/io/File;",
422+
"method": "exists"
423+
}
424+
],
425+
"score": 1,
426+
"label": []
427+
}
428+
429+
Quark Script Result
430+
====================
431+
432+
.. code-block:: TEXT
433+
434+
$ python3 CWE-921.py
435+
This file is stored inside the SDcard
436+
437+
CWE-921 is detected in ovaa.apk.

0 commit comments

Comments
 (0)