Skip to content

Commit 6cc5bae

Browse files
authored
Optimize the document of Quark Script CWE-89 (#742)
1 parent 3be7526 commit 6cc5bae

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

docs/source/quark_script.rst

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -826,37 +826,40 @@ Quark Script Result
826826
The CWE-312 vulnerability is found. The cleartext is "password"
827827
828828
829-
Detect CWE-89 in Android Application
830-
----------------------------------------
829+
Detect CWE-89 in Android Application
830+
-------------------------------------
831831

832832
This scenario seeks to find **SQL injection** in the APK file.
833833

834834
CWE-89 Improper Neutralization of Special Elements used in an SQL Command
835-
============================================================================
836-
835+
==========================================================================
837836

838837
We analyze the definition of CWE-89 and identify its characteristics.
839838

840839
See `CWE-89 <https://cwe.mitre.org/data/definitions/89.html>`_ for more details.
841840

842-
.. image:: https://i.imgur.com/iJ1yIBb.jpg
841+
.. image:: https://imgur.com/Yx9vIS2.jpg
842+
843+
Code of CWE-89 in AndroGoat.apk
844+
================================
843845

846+
We use the `AndroGoat.apk <https://github.com/satishpatnayak/AndroGoat>`_ sample to explain the vulnerability code of CWE-89.
844847

845-
Code of CWE-89 in androgoat.apk
846-
=========================================
848+
.. image:: https://imgur.com/QWvu8te.jpg
847849

848-
We use the `androgoat.apk <https://github.com/satishpatnayak/AndroGoat>`_ sample to explain the vulnerability code of CWE-89.
850+
CWE-89 Detection Process Using Quark Script API
851+
================================================
849852

850-
.. image:: https://i.imgur.com/bdQqWFb.jpg
853+
.. image:: https://imgur.com/gvPBB3v.jpg
851854

855+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
852856

857+
First, we design a detection rule ``executeSQLCommand.json`` to spot on behavior using SQL command Execution. Then, we use API ``behaviorInstance.isArgFromMethod(targetMethod)`` to check if ``append`` uses the value of ``getText`` as the argument. If yes, we confirmed that the SQL command string is built from user input, which will cause CWE-89 vulnerability.
853858

854859
Quark Script: CWE-89.py
855860
========================
856861

857-
Let's use the above APIs to show how the Quark script finds this vulnerability.
858-
859-
First, we design a detection rule ``executeSQLCommand.json`` to spot on behavior using SQL command Execution. Then, we use API ``behaviorInstance.isArgFromMethod(targetMethod)`` to check if ``append`` uses the value of ``getText`` as the argument. If yes, we confirmed that the SQL command string is built from user input, which will cause CWE-89 vulnerability.
862+
.. image:: https://imgur.com/B6Mfp2L.jpg
860863

861864
.. code-block:: python
862865
@@ -866,7 +869,7 @@ First, we design a detection rule ``executeSQLCommand.json`` to spot on behavior
866869
RULE_PATH = "executeSQLCommand.json"
867870
868871
targetMethod = [
869-
"Landroid/widget/EditText;", # class name
872+
"Landroid/widget/EditText;", # class name
870873
"getText", # method name
871874
"()Landroid/text/Editable;", # descriptor
872875
]
@@ -880,9 +883,10 @@ First, we design a detection rule ``executeSQLCommand.json`` to spot on behavior
880883
):
881884
print(f"CWE-89 is detected in {SAMPLE_PATH}")
882885
883-
884886
Quark Rule: executeSQLCommand.json
885-
====================================
887+
===================================
888+
889+
.. image:: https://imgur.com/aYnt5oq.jpg
886890

887891
.. code-block:: json
888892
@@ -905,11 +909,10 @@ Quark Rule: executeSQLCommand.json
905909
"label": []
906910
}
907911
908-
909912
Quark Script Result
910-
=====================
913+
====================
911914

912-
.. code-block:: text
915+
.. code-block:: TEXT
913916
914917
$ python3 CWE-89.py
915918

0 commit comments

Comments
 (0)