You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This scenario seeks to find **the improper limitation of a pathname to a restricted directory ('Path Traversal')**. See `CWE-22 <https://cwe.mitre.org/data/definitions/22.html>`_ for more details.
1661
+
Detect CWE-22 in Android Application
1662
+
----------------------------------------
1664
1663
1665
-
Let’s use `ovaa.apk <https://github.com/oversecured/ovaa>`_, `InsecureBankv2.apk <https://github.com/dineshshetty/Android-InsecureBankv2/releases>`_, and the above APIs to show how the Quark script finds this vulnerability.
1664
+
This scenario seeks to find **the improper limitation of a pathname to a restricted directory (‘Path Traversal’)**.
1666
1665
1667
-
First, we design a detection rule ``accessFileInExternalDir.json`` to spot behavior accessing a file in an external directory.
1666
+
CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
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.
1669
+
We analyze the definition of CWE-22 and identify its characteristics.
1670
1670
1671
-
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.
1671
+
See `CWE-22 <https://cwe.mitre.org/data/definitions/22.html>`_ for more details.
1672
1672
1673
-
Quark Script CWE-22.py
1674
-
=======================
1673
+
.. image:: https://imgur.com/agRPwp8.png
1674
+
1675
+
Code of CWE-22 in ovaa.apk
1676
+
===============================
1677
+
1678
+
We use the `ovaa.apk <https://github.com/oversecured/ovaa>`_ sample to explain the vulnerability code of CWE-22.
1675
1679
1676
-
The Quark Script below uses ovaa.apk to demonstrate. You can change the ``SAMPLE_PATH`` to the sample you want to detect. For example, ``SAMPLE_PATH = InsecureBankv2.apk``.
1680
+
.. image:: https://imgur.com/WFpfzFk.png
1681
+
1682
+
1683
+
Quark Scipt: CWE-22.py
1684
+
=========================
1685
+
1686
+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
1687
+
1688
+
First, we design a detection rule ``accessFileInExternalDir.json`` to spot behavior accessing a file in an external directory.
1689
+
1690
+
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.
1691
+
1692
+
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.
1677
1693
1678
1694
.. code-block:: python
1679
1695
@@ -1695,20 +1711,20 @@ The Quark Script below uses ovaa.apk to demonstrate. You can change the ``SAMPLE
CWE-22 is detected in method, Loversecured/ovaa/providers/TheftOverwriteProvider; openFile (Landroid/net/Uri; Ljava/lang/String;)Landroid/os/ParcelFileDescriptor;
1746
1760
1747
-
- **InsecureBankv2.apk**
1748
-
1749
-
.. code-block:: TEXT
1750
-
1751
-
$ python3 CWE-22.py
1752
-
CWE-22 is detected in method, Lcom/android/insecurebankv2/ViewStatement; onCreate (Landroid/os/Bundle;)V
1753
-
1754
1761
Detect CWE-23 in Android Application (ovaa.apk and InsecureBankv2.apk )
This scenario aims to demonstrate the detection of the **Relative Path Traversal** vulnerability using `ovaa.apk <https://github.com/oversecured/ovaa>`_ and `InsecureBankv2.apk <https://github.com/dineshshetty/Android-InsecureBankv2/releases>`_. See `CWE-23 <https://cwe.mitre.org/data/definitions/23.html>`_ for more details.
0 commit comments