Skip to content

Commit 52ef997

Browse files
authored
Optimize the document of Quark Script CWE-94 (#724)
1 parent d9ad85e commit 52ef997

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

docs/source/quark_script.rst

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -491,67 +491,76 @@ Quark Script Result
491491
492492
493493
494-
Detect CWE-94 in Android Application
495-
------------------------------------------------
494+
Detect CWE-94 in Android Application
495+
-------------------------------------
496496

497497
This scenario seeks to find **code injection** in the APK file.
498498

499-
CWE-94 Improper Control of Generation of Code
500-
================================================
499+
CWE-94: Improper Control of Generation of Code
500+
===============================================
501501

502502
We analyze the definition of CWE-94 and identify its characteristics.
503503

504504
See `CWE-94 <https://cwe.mitre.org/data/definitions/94.html>`_ for more details.
505505

506-
.. image:: https://imgur.com/faWwd3p.jpg
506+
.. image:: https://imgur.com/M9Jlgrn.png
507507

508508
Code of CWE-94 in ovaa.apk
509-
=========================================
509+
===========================
510510

511511
We use the `ovaa.apk <https://github.com/oversecured/ovaa>`_ sample to explain the vulnerability code of CWE-94.
512512

513-
.. image:: https://imgur.com/duobWF2.jpg
513+
.. image:: https://imgur.com/MdlAnvu.png
514514

515-
Quark Script: CWE-94.py
516-
========================
515+
CWE-94 Detection Process Using Quark Script API
516+
================================================
517517

518518
Let's use the above APIs to show how the Quark script finds this vulnerability.
519519

520520
First, we design a detection rule ``loadExternalCode.json`` to spot on behavior using the method ``createPackageContext``. Then, we find the caller method that calls the ``createPackageContext``. Finally, we check if the method ``checkSignatures`` is called in the caller method for verification.
521521

522+
.. image:: https://imgur.com/6cPBMWP.jpg
523+
524+
Quark Script: CWE-94.py
525+
========================
526+
527+
.. image:: https://imgur.com/Aw26Lv2.jpg
528+
522529
.. code-block:: python
523530
524-
from quark.script import runQuarkAnalysis, Rule
531+
from quark.script import runQuarkAnalysis, Rule
525532
526-
SAMPLE_PATH = "ovaa.apk"
527-
RULE_PATH = "loadExternalCode.json"
533+
SAMPLE_PATH = "ovaa.apk"
534+
RULE_PATH = "loadExternalCode.json"
528535
529-
targetMethod = [
530-
"Landroid/content/pm/PackageManager;",
531-
"checkSignatures",
532-
"(Ljava/lang/String;Ljava/lang/String;)I"
533-
]
536+
targetMethod = [
537+
"Landroid/content/pm/PackageManager;",
538+
"checkSignatures",
539+
"(Ljava/lang/String;Ljava/lang/String;)I"
540+
]
534541
535-
ruleInstance = Rule(RULE_PATH)
536-
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
542+
ruleInstance = Rule(RULE_PATH)
543+
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
537544
538-
for ldExternalCode in quarkResult.behaviorOccurList:
545+
for ldExternalCode in quarkResult.behaviorOccurList:
539546
540-
callerMethod = [
541-
ldExternalCode.methodCaller.className,
542-
ldExternalCode.methodCaller.methodName,
543-
ldExternalCode.methodCaller.descriptor
544-
]
547+
callerMethod = [
548+
ldExternalCode.methodCaller.className,
549+
ldExternalCode.methodCaller.methodName,
550+
ldExternalCode.methodCaller.descriptor
551+
]
545552
546-
if not quarkResult.findMethodInCaller(callerMethod, targetMethod):
547-
print(f"Method: {targetMethod[1]} not found!")
548-
print(f"CWE-94 is detected in {SAMPLE_PATH}")
553+
if not quarkResult.findMethodInCaller(callerMethod, targetMethod):
554+
print(f"Method: {targetMethod[1]} not found!")
555+
print(f"CWE-94 is detected in {SAMPLE_PATH}")
549556
550557
Quark Rule: loadExternalCode.json
551558
==================================
552559

560+
.. image:: https://imgur.com/IHENeJx.jpg
561+
553562
.. code-block:: json
554-
563+
555564
{
556565
"crime": "Load external code from other APK.",
557566
"permission": [],
@@ -571,9 +580,8 @@ Quark Rule: loadExternalCode.json
571580
"label": []
572581
}
573582
574-
575583
Quark Script Result
576-
===================
584+
====================
577585

578586
.. code-block:: TEXT
579587
@@ -583,6 +591,7 @@ Quark Script Result
583591
584592
585593
594+
586595
Detect CWE-921 in Android Application
587596
--------------------------------------
588597

0 commit comments

Comments
 (0)