Skip to content

Commit 1696ff6

Browse files
authored
Optimize the document of Quark Script CWE-78 (#734)
1 parent 5019761 commit 1696ff6

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

docs/source/quark_script.rst

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,7 @@ Quark Script Result
23492349
23502350
23512351
Detect CWE-78 in Android Application
2352-
--------------------------------------
2352+
-------------------------------------
23532353

23542354
This scenario seeks to find **Improper Neutralization of Special Elements used in an OS Command** in the APK file.
23552355

@@ -2360,28 +2360,35 @@ We analyze the definition of CWE-78 and identify its characteristics.
23602360

23612361
See `CWE-78 <https://cwe.mitre.org/data/definitions/78.html>`_ for more details.
23622362

2363-
.. image:: https://imgur.com/aUB195P.png
2363+
.. image:: https://imgur.com/HpMGGsO.png
23642364

23652365
Code of CWE-78 in Vuldroid.apk
23662366
===============================
23672367

23682368
We use the `Vuldroid.apk <https://github.com/jaiswalakshansh/Vuldroid>`_ sample to explain the vulnerability code of CWE-78.
23692369

2370-
.. image:: https://imgur.com/hO6m3Bz.png
2370+
.. image:: https://imgur.com/7Tu0Y3H.png
23712371

2372-
Quark Script: CWE-78.py
2373-
========================
2372+
CWE-78 Detection Process Using Quark Script API
2373+
================================================
2374+
2375+
.. image:: https://imgur.com/Hi7qGjw.png
23742376

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

23772379
First, we design a detection rule ``ExternalStringsCommands.json`` to spot on behavior using external strings as commands.
23782380

23792381
Next, we use Quark API ``behaviorInstance.getMethodsInArgs()`` to get the methods that passed the external command.
23802382

2381-
Then we check if the method neutralizes any special elements found in the argument.
2383+
Then we check if the method neutralizes any special elements in the argument.
23822384

23832385
If the neutralization is not complete, then it may cause CWE-78 vulnerability.
23842386

2387+
Quark Script: CWE-78.py
2388+
========================
2389+
2390+
.. image:: https://imgur.com/UpRWgGe.png
2391+
23852392
.. code-block:: python
23862393
23872394
from quark.script import runQuarkAnalysis, Rule, findMethodInAPK
@@ -2395,7 +2402,11 @@ If the neutralization is not complete, then it may cause CWE-78 vulnerability.
23952402
("Ljava/lang/String;", "indexOf", "(I)I"),
23962403
("Ljava/lang/String;", "indexOf", "(Ljava/lang/String;)I"),
23972404
("Ljava/lang/String;", "matches", "(Ljava/lang/String;)Z"),
2398-
("Ljava/lang/String;", "replaceAll", "(Ljava/lang/String; Ljava/lang/String;)Ljava/lang/String;")
2405+
(
2406+
"Ljava/lang/String;",
2407+
"replaceAll",
2408+
"(Ljava/lang/String; Ljava/lang/String;)Ljava/lang/String;",
2409+
),
23992410
])
24002411
24012412
specialElementsPattern = r"[ ;|,>`]+"
@@ -2407,18 +2418,19 @@ If the neutralization is not complete, then it may cause CWE-78 vulnerability.
24072418
24082419
methodCalled = set()
24092420
caller = ExternalStringCommand.methodCaller
2410-
2421+
24112422
for method in ExternalStringCommand.getMethodsInArgs():
24122423
methodCalled.add(method.fullName)
2413-
2424+
24142425
if methodCalled.intersection(STRING_MATCHING_API) and not ExternalStringCommand.hasString(specialElementsPattern):
24152426
continue
24162427
else:
24172428
print(f"CWE-78 is detected in method, {caller.fullName}")
2418-
2419-
2429+
24202430
Quark Rule: ExternalStringCommand.json
2421-
=========================================
2431+
=======================================
2432+
2433+
.. image:: https://imgur.com/eoV8hnZ.png
24222434

24232435
.. code-block:: json
24242436
@@ -2441,10 +2453,8 @@ Quark Rule: ExternalStringCommand.json
24412453
"label": []
24422454
}
24432455
2444-
24452456
Quark Script Result
2446-
======================
2447-
- **Vuldroid.apk**
2457+
====================
24482458

24492459
.. code-block:: TEXT
24502460
@@ -2453,6 +2463,7 @@ Quark Script Result
24532463
24542464
24552465
2466+
24562467
Detect CWE-117 in Android Application
24572468
--------------------------------------
24582469

0 commit comments

Comments
 (0)