Skip to content

Commit 4510731

Browse files
authored
Optimize the document of Quark Script CWE-940 (#63)
* Optimize the document of Quark Script CWE-940 * Optimize the document of Quark Script CWE-940 * Optimize the document of Quark Script CWE-940
1 parent f6dc423 commit 4510731

3 files changed

Lines changed: 32 additions & 31 deletions

File tree

CWE-940/CWE-940.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
SAMPLE_PATH = "ovaa.apk"
44
RULE_PATH = "LoadUrlFromIntent.json"
55

6-
INTENT_SETTING_METHODS = [
6+
URL_GETTING_METHODS = [
77
"findViewById",
88
"getStringExtra",
99
"getIntent",
@@ -19,9 +19,9 @@
1919
verifiedMethodCandidates = []
2020

2121
for method in methodsInArgs:
22-
if method.methodName not in INTENT_SETTING_METHODS:
22+
if method.methodName not in URL_GETTING_METHODS:
2323
verifiedMethodCandidates.append(method)
2424

2525
if verifiedMethodCandidates == []:
2626
caller = behaviorInstance.methodCaller.fullName
27-
print(f"cwe-940 is detected in method, {caller}")
27+
print(f"CWE-940 is detected in method, {caller}")

CWE-940/LoadUrlFromIntent.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"crime": "Load Url from Intent and open WebView",
2+
"crime": "Load Url from Intent",
33
"permission": [],
44
"api": [
55
{

CWE-940/README.md

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
1-
# Detect CWE-940 in Android Application (ovaa,Vuldroid)
1+
# Detect CWE-940 in Android Application
22

3-
This scenario aims to demonstrate the detection of the **Improper
4-
Verification of Source of a Communication Channel** vulnerability using
5-
[ovaa.apk](https://github.com/oversecured/ovaa) and
6-
[Vuldroid.apk](https://github.com/jaiswalakshansh/Vuldroid). See
7-
[CWE-940](https://cwe.mitre.org/data/definitions/940.html) for more
8-
details.
3+
This scenario seeks to find the **Improper Verification of Source of a Communication Channel** in the APK file.
94

10-
To begin with, we create a detection rule named `LoadUrlFromIntent.json`
11-
to identify behavior that loads url from intent data to the WebView.
5+
## CWE-940: Improper Verification of Source of a Communication Channel
126

13-
Next, we retrieve the methods that pass the url. Following this, we
14-
check if these methods are only for setting intent, such as
15-
`findViewById`, `getStringExtra`, or `getIntent`.
7+
We analyze the definition of CWE-940 and identify its characteristics.
168

17-
If **NO**, it could imply that the APK uses communication channels
18-
without proper verification, which may cause CWE-940 vulnerability.
9+
See [CWE-940](https://cwe.mitre.org/data/definitions/940.html) for more details.
1910

20-
# Quark Script CWE-940.py
11+
![image](https://imgur.com/wia3OKo.png)
2112

22-
The Quark Script below uses ovaa.apk to demonstrate. You can change the
23-
`SAMPLE_PATH` to the sample you want to detect. For example,
24-
`SAMPLE_PATH = "Vuldroid.apk"`.
13+
## Code of CWE-940 in ovaa.apk
2514

26-
``` python
15+
We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to explain the vulnerability code of CWE-940.
16+
17+
![image](https://imgur.com/1zP5xkN.png)
18+
19+
## Quark Script: CWE-940.py
20+
21+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
22+
23+
To begin with, we create a detection rule named `LoadUrlFromIntent.json` to identify behavior that loads URLs from intent data to the `WebView`.
24+
25+
Next, we retrieve the methods that pass the URL. Then, we check if these methods are only for getting the URL, such as `findViewById`, `getStringExtra`, or `getIntent`.
26+
27+
If **YES**, it could imply that the APK uses communication channels without proper verification, which may cause CWE-940 vulnerability.
28+
29+
```python
2730
from quark.script import runQuarkAnalysis, Rule
2831

2932
SAMPLE_PATH = "ovaa.apk"
3033
RULE_PATH = "LoadUrlFromIntent.json"
3134

32-
INTENT_SETTING_METHODS = [
35+
URL_GETTING_METHODS = [
3336
"findViewById",
3437
"getStringExtra",
3538
"getIntent",
@@ -45,19 +48,19 @@ for behaviorInstance in quarkResult.behaviorOccurList:
4548
verifiedMethodCandidates = []
4649

4750
for method in methodsInArgs:
48-
if method.methodName not in INTENT_SETTING_METHODS:
51+
if method.methodName not in URL_GETTING_METHODS:
4952
verifiedMethodCandidates.append(method)
5053

5154
if verifiedMethodCandidates == []:
5255
caller = behaviorInstance.methodCaller.fullName
53-
print(f"cwe-940 is detected in method, {caller}")
56+
print(f"CWE-940 is detected in method, {caller}")
5457
```
5558

5659
## Quark Rule: LoadUrlFromIntent.json
5760

58-
``` json
61+
```
5962
{
60-
"crime": "Load Url from Intent and open WebView",
63+
"crime": "Load Url from Intent",
6164
"permission": [],
6265
"api": [
6366
{
@@ -78,9 +81,7 @@ for behaviorInstance in quarkResult.behaviorOccurList:
7881

7982
## Quark Script Result
8083

81-
- **ovaa.apk**
82-
83-
``` TEXT
84+
```
8485
$ python CWE-940.py
8586
CWE-940 is detected in method, Loversecured/ovaa/activities/WebViewActivity; onCreate (Landroid/os/Bundle;)V
8687
```

0 commit comments

Comments
 (0)