Skip to content

Commit 178d72f

Browse files
authored
Optimize the document of Quark Script CWE-20 (#727)
1 parent 5a01434 commit 178d72f

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

docs/source/quark_script.rst

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,58 +1376,67 @@ Quark Script Result
13761376
13771377
13781378
Detect CWE-20 in Android Application
1379-
----------------------------------------
1379+
-------------------------------------
13801380

13811381
This scenario seeks to find **Improper Input Validation** in the APK file.
13821382

1383-
CWE-20 Improper Input Validation
1384-
=================================
1383+
CWE-20: Improper Input Validation
1384+
==================================
13851385

13861386
We analyze the definition of CWE-20 and identify its characteristics.
13871387

13881388
See `CWE-20 <https://cwe.mitre.org/data/definitions/20.html>`_ for more details.
13891389

1390-
.. image:: https://imgur.com/21CzFUq.jpg
1390+
.. image:: https://imgur.com/eO8fepu.jpg
13911391

13921392
Code of CWE-20 in diva.apk
1393-
===============================
1393+
===========================
13941394

13951395
We use the `diva.apk <https://github.com/payatu/diva-android>`_ sample to explain the vulnerability code of CWE-20.
13961396

1397-
.. image:: https://imgur.com/kRIuEHd.jpg
1397+
.. image:: https://imgur.com/nsuXYGU.jpg
13981398

1399-
Quark Script CWE-20.py
1400-
=======================
1399+
CWE-20 Detection Process Using Quark Script API
1400+
================================================
1401+
1402+
.. image:: https://imgur.com/C7zmwLm.jpg
14011403

14021404
Let’s use the above APIs to show how the Quark script finds this vulnerability.
14031405

14041406
First, we design a detection rule ``openUrlThatUserInput.json``, to spot the behavior of opening the URL that the user inputs. Then, we use API ``behaviorInstance.getMethodsInArgs()`` to get a list of methods that the URL in ``loadUrl`` passes through. Finally, we check if any validation method is in the list. If No, the APK does not validate user input. That causes CWE-20 vulnerability.
14051407

1408+
Quark Script CWE-20.py
1409+
=======================
1410+
1411+
.. image:: https://imgur.com/bwPqc4K.jpg
1412+
14061413
.. code-block:: python
14071414
1408-
from quark.script import runQuarkAnalysis, Rule
1409-
1410-
SAMPLE_PATH = "diva.apk"
1411-
RULE_PATH = "openUrlThatUserInput.json"
1412-
1413-
rule = Rule(RULE_PATH)
1414-
result = runQuarkAnalysis(SAMPLE_PATH, rule)
1415-
1416-
VALIDATE_METHODS = ["contains", "indexOf", "matches", "replaceAll"]
1417-
1418-
for openUrl in result.behaviorOccurList:
1419-
calledMethods = openUrl.getMethodsInArgs()
1420-
1421-
if not any(
1422-
method.methodName in VALIDATE_METHODS for method in calledMethods
1423-
):
1424-
print(f"CWE-20 is detected in method, {openUrl.methodCaller.fullName}")
1415+
from quark.script import runQuarkAnalysis, Rule
1416+
1417+
SAMPLE_PATH = "diva.apk"
1418+
RULE_PATH = "openUrlThatUserInput.json"
1419+
1420+
rule = Rule(RULE_PATH)
1421+
result = runQuarkAnalysis(SAMPLE_PATH, rule)
1422+
1423+
VALIDATE_METHODS = ["contains", "indexOf", "matches", "replaceAll"]
1424+
1425+
for openUrl in result.behaviorOccurList:
1426+
calledMethods = openUrl.getMethodsInArgs()
1427+
1428+
if not any(
1429+
method.methodName in VALIDATE_METHODS for method in calledMethods
1430+
):
1431+
print(f"CWE-20 is detected in method, {openUrl.methodCaller.fullName}")
14251432
14261433
Quark Rule: openUrlThatUserInput.json
14271434
======================================
14281435

1436+
.. image:: https://imgur.com/k4WT8Fb.jpg
1437+
14291438
.. code-block:: json
1430-
1439+
14311440
{
14321441
"crime": "Open the Url that user input",
14331442
"permission": [],
@@ -1448,12 +1457,12 @@ Quark Rule: openUrlThatUserInput.json
14481457
}
14491458
14501459
Quark Script Result
1451-
===================
1460+
====================
14521461

14531462
.. code-block:: TEXT
14541463
1455-
$ python CWE-20.py
1456-
CWE-20 is detected in method, Ljakhar/aseem/diva/InputValidation2URISchemeActivity; get (Landroid/view/View;)V
1464+
$ python CWE-20.py
1465+
CWE-20 is detected in method, Ljakhar/aseem/diva/InputValidation2URISchemeActivity; get (Landroid/view/View;)V
14571466
14581467
14591468

0 commit comments

Comments
 (0)