Skip to content

Commit 9a1569c

Browse files
authored
Optimize the document of Quark Script CWE-22 (#730)
1 parent 918c9f4 commit 9a1569c

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

docs/source/quark_script.rst

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,37 +1780,43 @@ Quark Script Result
17801780
17811781
17821782
Detect CWE-22 in Android Application
1783-
----------------------------------------
1783+
-------------------------------------
17841784

17851785
This scenario seeks to find **the improper limitation of a pathname to a restricted directory (‘Path Traversal’)**.
17861786

17871787
CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
1788-
=========================================================================================
1788+
=======================================================================================
17891789

17901790
We analyze the definition of CWE-22 and identify its characteristics.
17911791

17921792
See `CWE-22 <https://cwe.mitre.org/data/definitions/22.html>`_ for more details.
17931793

1794-
.. image:: https://imgur.com/agRPwp8.png
1794+
.. image:: https://imgur.com/XnOUZsV.png
17951795

17961796
Code of CWE-22 in ovaa.apk
1797-
===============================
1797+
===========================
17981798

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

1801-
.. image:: https://imgur.com/WFpfzFk.png
1801+
.. image:: https://imgur.com/bgWgeT7.png
18021802

1803+
CWE-22 Detection Process Using Quark Script API
1804+
================================================
18031805

1804-
Quark Script: CWE-22.py
1805-
=========================
1806+
.. image:: https://imgur.com/N69bQK2.png
18061807

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

18091810
First, we design a detection rule ``accessFileInExternalDir.json`` to spot behavior accessing a file in an external directory.
18101811

1811-
Next, we use API ``methodInstance.getArguments()`` to get the argument for the file path and use ``quarkResultInstance.isHardcoded(argument)`` to check if the argument is hardcoded into the APK. If No, the argument is from external input.
1812+
Next, we use API ``methodInstance.getArguments()`` to get the argument for the file path and use ``quarkResultInstance.isHardcoded(argument)`` to check if the argument is hardcoded into the APK. If **No**, the argument is from external input.
1813+
1814+
Finally, we use Quark API ``quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)`` to check if there are any APIs in the caller method for string matching. If **NO**, the APK does not neutralize special elements within the argument, which may cause CWE-22 vulnerability.
18121815

1813-
Finally, we use Quark API ``quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)`` to check if there are any APIs in the caller method for string matching. If NO, the APK does not neutralize special elements within the argument, which may cause CWE-22 vulnerability.
1816+
Quark Scipt: CWE-22.py
1817+
=======================
1818+
1819+
.. image:: https://imgur.com/4b2e4tN.png
18141820

18151821
.. code-block:: python
18161822
@@ -1832,24 +1838,26 @@ Finally, we use Quark API ``quarkResultInstance.findMethodInCaller(callerMethod,
18321838
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
18331839
18341840
for accessExternalDir in quarkResult.behaviorOccurList:
1841+
18351842
filePath = accessExternalDir.secondAPI.getArguments()[2]
18361843
18371844
if quarkResult.isHardcoded(filePath):
1838-
continue
1845+
continue
18391846
18401847
caller = accessExternalDir.methodCaller
18411848
strMatchingAPIs = [
1842-
api
1843-
for api in STRING_MATCHING_API
1844-
if quarkResult.findMethodInCaller(caller, api)
1849+
api for api in STRING_MATCHING_API if quarkResult.findMethodInCaller(
1850+
caller, api)
18451851
]
18461852
18471853
if not strMatchingAPIs:
1848-
print(f"CWE-22 is detected in method, {caller.fullName}")
1854+
print(f"CWE-22 is detected in method, {caller.fullName}")
18491855
18501856
Quark Rule: accessFileInExternalDir.json
18511857
=========================================
18521858

1859+
.. image:: https://imgur.com/N2uKsZj.png
1860+
18531861
.. code-block:: json
18541862
18551863
{
@@ -1872,13 +1880,16 @@ Quark Rule: accessFileInExternalDir.json
18721880
}
18731881
18741882
Quark Script Result
1875-
======================
1883+
====================
18761884

18771885
.. code-block:: TEXT
1878-
1886+
18791887
$ python3 CWE-22.py
18801888
CWE-22 is detected in method, Loversecured/ovaa/providers/TheftOverwriteProvider; openFile (Landroid/net/Uri; Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;
18811889
1890+
1891+
1892+
18821893
Detect CWE-23 in Android Application
18831894
--------------------------------------
18841895

0 commit comments

Comments
 (0)