|
1 | 1 | # Detect CWE-312 in Android Application
|
2 | 2 |
|
| 3 | +This scenario seeks to find **cleartext storage of sensitive data** in the APK file. |
3 | 4 |
|
4 |
| -This scenario seeks to find **cleartext storage of sensitive data** in |
5 |
| -the APK file. |
6 |
| - |
7 |
| -## CWE-312 Cleartext Storage of Sensitive Information |
| 5 | +## CWE-312: Cleartext Storage of Sensitive Information |
8 | 6 |
|
9 | 7 | We analyze the definition of CWE-312 and identify its characteristics.
|
10 | 8 |
|
11 |
| -See [CWE-312](https://cwe.mitre.org/data/definitions/312.html) for more |
12 |
| -details. |
| 9 | +See [CWE-312](https://cwe.mitre.org/data/definitions/312.html) for more details. |
13 | 10 |
|
14 |
| - |
| 11 | + |
15 | 12 |
|
16 | 13 | ## Code of CWE-312 in ovaa.apk
|
17 | 14 |
|
18 |
| -We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to |
19 |
| -explain the vulnerability code of CWE-312. |
| 15 | +We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to explain the vulnerability code of CWE-312. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +## CWE-312 Detection Process Using Quark Script API |
| 20 | + |
| 21 | +Let’s use the above APIs to show how the Quark script finds this vulnerability. |
20 | 22 |
|
21 |
| - |
| 23 | +We have designed a [Frida](https://frida.re/) script ``agent.js`` to hook a specified method and get the arguments when the method is called. It can be found in [quark-engine/quark/script/frida](https://github.com/quark-engine/quark-engine/tree/master/quark/script/frida). |
| 24 | + |
| 25 | +To begin with, we hook the method ``putString`` to catch its arguments. Then, we check if sensitive information like email or password is passed. Finally, we use ``checkClearText`` imported from [Ares](https://github.com/bee-san/Ares) to check if the arguments are cleartext. If both **YES**, CWE-312 vulnerability might be caused. |
22 | 26 |
|
23 |
| -## Quark Script CWE-312.py |
| 27 | + |
24 | 28 |
|
25 |
| -Let\'s use the above APIs to show how the Quark script finds this |
26 |
| -vulnerability. |
| 29 | +## Quark Script: CWE-312.py |
27 | 30 |
|
28 |
| -First, we designed a [Frida](https://frida.re) script `agent.js` to hook |
29 |
| -the target method and get the arguments when the target method is |
30 |
| -called. Then we hook the method `putString` to catch its arguments. |
31 |
| -Finally, we use [Ares](https://github.com/bee-san/Ares) to check if |
32 |
| -the arguments are encrypted. |
| 31 | + |
33 | 32 |
|
34 |
| -``` python |
| 33 | +```python |
35 | 34 | from quark.script.frida import runFridaHook
|
36 | 35 | from quark.script.ares import checkClearText
|
37 | 36 |
|
@@ -62,7 +61,7 @@ for putString in fridaResult.behaviorOccurList:
|
62 | 61 |
|
63 | 62 | ## Frida Script: agent.js
|
64 | 63 |
|
65 |
| -``` javascript |
| 64 | +```javascript |
66 | 65 | // -*- coding: utf-8 -*-
|
67 | 66 | // This file is part of Quark-Engine - https://github.com/quark-engine/quark-engine
|
68 | 67 | // See the file 'LICENSE' for copying permission.
|
@@ -125,7 +124,7 @@ rpc.exports["watchMethodCall"] = (classAndMethodName, methodParamTypes) => watch
|
125 | 124 |
|
126 | 125 | ## Quark Script Result
|
127 | 126 |
|
128 |
| -``` TEXT |
| 127 | +```TEXT |
129 | 128 | $ python3 CWE-312.py
|
130 | 129 | The CWE-312 vulnerability is found. The cleartext is "[email protected]"
|
131 | 130 | The CWE-312 vulnerability is found. The cleartext is "password"
|
|
0 commit comments