Skip to content

Commit 00bb5cf

Browse files
authored
Optimize the CWE-79 document (ev-flow#645)
* Optimize the CWE-79 document * Optimize the CWE-79 document
1 parent b7eafcd commit 00bb5cf

File tree

1 file changed

+35
-18
lines changed

1 file changed

+35
-18
lines changed

docs/source/quark_script.rst

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,51 +1387,67 @@ Quark Script Result
13871387
13881388
13891389
1390-
Detect CWE-79 in Android Application (Vuldroid.apk)
1391-
------------------------------------------------------
1390+
Detect CWE-79 in Android Application
1391+
-------------------------------------
1392+
1393+
This scenario seeks to find **Improper Neutralization of Input During Web Page Generation (‘Cross-site Scripting’)** in the APK file.
13921394

1393-
This scenario seeks to find **Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').** See `CWE-79 <https://cwe.mitre.org/data/definitions/79.html>`_ for more details.
1395+
CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
1396+
============================================================================================
13941397

1395-
Let’s use this `APK <https://github.com/jaiswalakshansh/Vuldroid>`_ and the above APIs to show how the Quark script finds this vulnerability.
1398+
We analyze the definition of CWE-79 and identify its characteristics.
13961399

1397-
First, we design a detection rule ``loadUrlFromIntent.json`` to spot on behavior loading URL from intent data to the WebView instance.
1400+
See `CWE-79 <https://cwe.mitre.org/data/definitions/79.html>`_ for more details.
13981401

1399-
Next, we use API ``quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)`` and ``methodInstance.getArguments()`` to check if the Javascript execution is enabled in the WebView. Finally, we check if there are any famous XSS filters. If **NO**, that may cause CWE-79 vulnerability.
1402+
.. image:: https://imgur.com/jAwgD0x.png
1403+
1404+
Code of CWE-79 in Vuldroid.apk
1405+
===============================
14001406

1407+
We use the `Vuldroid.apk <https://github.com/jaiswalakshansh/Vuldroid>`_ sample to explain the vulnerability code of CWE-79.
1408+
1409+
.. image:: https://imgur.com/lC6EKun.png
14011410

14021411
Quark Script CWE-79.py
1403-
========================
1412+
=======================
1413+
1414+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
1415+
1416+
First, we design a detection rule ``loadUrlFromIntent.json`` to spot the behavior loading URL from intent data to the WebView instance.
1417+
1418+
Next, we use API ``quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)`` and ``methodInstance.getArguments()`` to check if the Javascript execution is enabled in the WebView. Finally, we check if there are any famous XSS filters. If NO, that may cause CWE-79 vulnerability.
14041419

14051420
.. code-block:: python
1406-
1421+
14071422
from quark.script import runQuarkAnalysis, Rule
14081423
14091424
SAMPLE_PATH = "Vuldroid.apk"
14101425
RULE_PATH = "loadUrlFromIntent.json"
14111426
14121427
XSS_FILTERS = [
14131428
[
1414-
"Lorg/owasp/esapi/Validator;", "getValidSafeHTML",
1429+
"Lorg/owasp/esapi/Validator;",
1430+
"getValidSafeHTML",
14151431
"(Ljava/lang/String; Ljava/lang/String; I Z)Ljava/lang/String;",
14161432
],
14171433
[
1418-
"Lorg/owasp/esapi/Encoder;", "encodeForHTML",
1434+
"Lorg/owasp/esapi/Encoder;",
1435+
"encodeForHTML",
14191436
"(Ljava/lang/String;)Ljava/lang/String;",
14201437
],
14211438
[
1422-
"Lorg/owasp/esapi/Encoder;", "encodeForJavaScript",
1439+
"Lorg/owasp/esapi/Encoder;",
1440+
"encodeForJavaScript",
14231441
"(Ljava/lang/String;)Ljava/lang/String;",
14241442
],
14251443
[
1426-
"Lorg/owasp/html/PolicyFactory;", "sanitize",
1444+
"Lorg/owasp/html/PolicyFactory;",
1445+
"sanitize",
14271446
"(Ljava/lang/String;)Ljava/lang/String;",
14281447
],
14291448
]
14301449
1431-
targetMethod = [
1432-
"Landroid/webkit/WebSettings;", "setJavaScriptEnabled",
1433-
"(Z)V"
1434-
]
1450+
targetMethod = ["Landroid/webkit/WebSettings;", "setJavaScriptEnabled", "(Z)V"]
14351451
14361452
ruleInstance = Rule(RULE_PATH)
14371453
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
@@ -1446,13 +1462,14 @@ Quark Script CWE-79.py
14461462
14471463
if enableJS:
14481464
XSSFiltersInCaller = [
1449-
filterAPI for filterAPI in XSS_FILTERS if quarkResult.findMethodInCaller(caller, filterAPI)
1465+
filterAPI
1466+
for filterAPI in XSS_FILTERS
1467+
if quarkResult.findMethodInCaller(caller, filterAPI)
14501468
]
14511469
14521470
if not XSSFiltersInCaller:
14531471
print(f"CWE-79 is detected in method, {caller.fullName}")
14541472
1455-
14561473
Quark Rule: loadUrlFromIntent.json
14571474
====================================
14581475

0 commit comments

Comments
 (0)