Skip to content

Commit d8f79e1

Browse files
authored
Optimize the document of Quark Script CWE-20, 94, 921 (#49)
1 parent 5882cef commit d8f79e1

File tree

3 files changed

+69
-70
lines changed

3 files changed

+69
-70
lines changed

CWE-20/README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
11
# Detect CWE-20 in Android Application
22

3+
This scenario seeks to find **Improper Input Validation** in the APK file.
34

4-
This scenario seeks to find **Improper Input Validation** in the APK
5-
file.
6-
7-
## CWE-20 Improper Input Validation
5+
## CWE-20: Improper Input Validation
86

97
We analyze the definition of CWE-20 and identify its characteristics.
108

11-
See [CWE-20](https://cwe.mitre.org/data/definitions/20.html) for more
12-
details.
9+
See [CWE-20](https://cwe.mitre.org/data/definitions/20.html) for more details.
1310

14-
![image](https://imgur.com/21CzFUq.jpg)
11+
![image](https://imgur.com/eO8fepu.jpg)
1512

1613
## Code of CWE-20 in diva.apk
1714

18-
We use the [diva.apk](https://github.com/payatu/diva-android) sample to
19-
explain the vulnerability code of CWE-20.
15+
We use the [diva.apk](https://github.com/payatu/diva-android) sample to explain the vulnerability code of CWE-20.
2016

21-
![image](https://imgur.com/kRIuEHd.jpg)
17+
![image](https://imgur.com/nsuXYGU.jpg)
2218

23-
## Quark Script CWE-20.py
19+
## CWE-20 Detection Process Using Quark Script API
20+
21+
![image](https://imgur.com/C7zmwLm.jpg)
22+
23+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
2424

25-
Let's use the above APIs to show how the Quark script finds this
26-
vulnerability.
25+
First, we design a detection rule ``openUrlThatUserInput.json``, to spot the behavior of opening the URL that the user inputs. Then, we use API ``behaviorInstance.getMethodsInArgs()`` to get a list of methods that the URL in ``loadUrl`` passes through. Finally, we check if any validation method is in the list. If No, the APK does not validate user input. That causes CWE-20 vulnerability.
2726

28-
First, we design a detection rule `openUrlThatUserInput.json`, to spot
29-
the behavior of opening the URL that the user inputs. Then, we use API
30-
`behaviorInstance.getMethodsInArgs()` to get a list of methods that the
31-
URL in `loadUrl` passes through. Finally, we check if any validation
32-
method is in the list. If No, the APK does not validate user input. That
33-
causes CWE-20 vulnerability.
27+
## Quark Script CWE-20.py
28+
29+
![image](https://imgur.com/bwPqc4K.jpg)
3430

35-
``` python
31+
```python
3632
from quark.script import runQuarkAnalysis, Rule
3733

3834
SAMPLE_PATH = "diva.apk"
@@ -54,7 +50,9 @@ for openUrl in result.behaviorOccurList:
5450

5551
## Quark Rule: openUrlThatUserInput.json
5652

57-
``` json
53+
![image](https://imgur.com/k4WT8Fb.jpg)
54+
55+
```json
5856
{
5957
"crime": "Open the Url that user input",
6058
"permission": [],
@@ -77,7 +75,7 @@ for openUrl in result.behaviorOccurList:
7775

7876
## Quark Script Result
7977

80-
``` TEXT
78+
```
8179
$ python CWE-20.py
8280
CWE-20 is detected in method, Ljakhar/aseem/diva/InputValidation2URISchemeActivity; get (Landroid/view/View;)V
8381
```

CWE-921/README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
# Detect CWE-921 in Android Application
22

3-
This scenario seeks to find the **unsecured storage mechanism of
4-
sensitive data** in the APK file.
3+
This scenario seeks to find the **unsecured storage mechanism of sensitive data** in the APK file.
54

6-
## CWE-921 Storage of Sensitive Data in a Mechanism without Access Control
5+
## CWE-921: Storage of Sensitive Data in a Mechanism without Access Control
76

87
We analyze the definition of CWE-921 and identify its characteristics.
98

10-
See [CWE-921](https://cwe.mitre.org/data/definitions/921.html) for more
11-
details.
9+
See [CWE-921](https://cwe.mitre.org/data/definitions/921.html) for more details.
10+
11+
![image](https://imgur.com/2zlPLHe.jpg)
1212

13-
![image](https://imgur.com/ihtjGAu.jpg)
1413

1514
## Code of CWE-921 in ovaa.apk
1615

17-
We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to
18-
explain the vulnerability code of CWE-921.
16+
We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to explain the vulnerability code of CWE-921.
1917

20-
![image](https://imgur.com/ACzJct8.jpg)
18+
![image](https://imgur.com/2u5iL1K.jpg)
2119

22-
## Quark Script: CWE-921.py
20+
## CWE-921 Detection Process Using Quark Script API
21+
22+
![image](https://imgur.com/qHOMqKy.jpg)
23+
24+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
2325

24-
Let's use the above APIs to show how the Quark script finds this
25-
vulnerability.
26+
First, we design a detection rule ``checkFileExistence.json`` to spot on behavior that checks if a file exists on a given storage mechanism. Then, we use API ``methodInstance.getArguments()`` to get the file path. Finally, CWE-921 is found if the file path contains the keyword ``sdcard``.
2627

27-
First, we design a detection rule `checkFileExistence.json` to spot on
28-
behavior that checks if a file exists on a given storage mechanism.
29-
Then, we use API `methodInstance.getArguments()` to get the file path.
30-
Finally, CWE-921 is found if the file path contains the keyword
31-
`sdcard`.
28+
## Quark Script: CWE-921.py
29+
30+
![image](https://imgur.com/HULgyIy.jpg)
3231

33-
``` python
32+
```python
3433
from quark.script import runQuarkAnalysis, Rule
3534

3635
SAMPLE_PATH = "ovaa.apk"
@@ -48,7 +47,9 @@ for existingFile in quarkResult.behaviorOccurList:
4847

4948
## Quark Rule: checkFileExistence.json
5049

51-
``` json
50+
![image](https://imgur.com/zRiYLtS.jpg)
51+
52+
```json
5253
{
5354
"crime": "Check file existence",
5455
"permission": [],
@@ -71,7 +72,7 @@ for existingFile in quarkResult.behaviorOccurList:
7172

7273
## Quark Script Result
7374

74-
``` TEXT
75+
```
7576
$ python3 CWE-921.py
7677
This file is stored inside the SDcard
7778

CWE-94/README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
11
# Detect CWE-94 in Android Application
22

3+
This scenario seeks to find **code injection** in the APK file.
34

4-
This scenario seeks to find **code injection** in the APK file.
5-
6-
## CWE-94 Improper Control of Generation of Code
5+
## CWE-94: Improper Control of Generation of Code
76

87
We analyze the definition of CWE-94 and identify its characteristics.
98

10-
See [CWE-94](https://cwe.mitre.org/data/definitions/94.html) for more
11-
details.
9+
See [CWE-94](https://cwe.mitre.org/data/definitions/94.html) for more details.
1210

13-
![image](https://imgur.com/faWwd3p.jpg)
11+
![image](https://imgur.com/M9Jlgrn.png)
1412

1513
## Code of CWE-94 in ovaa.apk
1614

17-
We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to
18-
explain the vulnerability code of CWE-94.
15+
We use the [ovaa.apk](https://github.com/oversecured/ovaa) sample to explain the vulnerability code of CWE-94.
1916

20-
![image](https://imgur.com/duobWF2.jpg)
17+
![image](https://imgur.com/MdlAnvu.png)
2118

22-
## Quark Script: CWE-94.py
19+
## CWE-94 Detection Process Using Quark Script API
20+
21+
Let's use the above APIs to show how the Quark script finds this vulnerability.
2322

24-
Let\'s use the above APIs to show how the Quark script finds this
25-
vulnerability.
23+
First, we design a detection rule ``loadExternalCode.json`` to spot on behavior using the method ``createPackageContext``. Then, we find the caller method that calls the ``createPackageContext``. Finally, we check if the method ``checkSignatures`` is called in the caller method for verification.
2624

27-
First, we design a detection rule `loadExternalCode.json` to spot on
28-
behavior using the method `createPackageContext`. Then, we find the
29-
caller method that calls the `createPackageContext`. Finally, we check
30-
if the method `checkSignatures` is called in the caller method for
31-
verification.
25+
![image](https://imgur.com/6cPBMWP.jpg)
26+
27+
## Quark Script: CWE-94.py
3228

33-
``` python
29+
![image](https://imgur.com/Aw26Lv2.jpg)
30+
31+
```python
3432
from quark.script import runQuarkAnalysis, Rule
3533

3634
SAMPLE_PATH = "ovaa.apk"
3735
RULE_PATH = "loadExternalCode.json"
3836

3937
targetMethod = [
40-
"Landroid/content/pm/PackageManager;",
41-
"checkSignatures",
42-
"(Ljava/lang/String;Ljava/lang/String;)I"
43-
]
38+
"Landroid/content/pm/PackageManager;",
39+
"checkSignatures",
40+
"(Ljava/lang/String;Ljava/lang/String;)I"
41+
]
4442

4543
ruleInstance = Rule(RULE_PATH)
4644
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
4745

4846
for ldExternalCode in quarkResult.behaviorOccurList:
4947

5048
callerMethod = [
51-
ldExternalCode.methodCaller.className,
52-
ldExternalCode.methodCaller.methodName,
53-
ldExternalCode.methodCaller.descriptor
54-
]
49+
ldExternalCode.methodCaller.className,
50+
ldExternalCode.methodCaller.methodName,
51+
ldExternalCode.methodCaller.descriptor
52+
]
5553

5654
if not quarkResult.findMethodInCaller(callerMethod, targetMethod):
5755
print(f"Method: {targetMethod[1]} not found!")
@@ -60,7 +58,9 @@ for ldExternalCode in quarkResult.behaviorOccurList:
6058

6159
## Quark Rule: loadExternalCode.json
6260

63-
``` json
61+
![image](https://imgur.com/IHENeJx.jpg)
62+
63+
```json
6464
{
6565
"crime": "Load external code from other APK.",
6666
"permission": [],
@@ -83,7 +83,7 @@ for ldExternalCode in quarkResult.behaviorOccurList:
8383

8484
## Quark Script Result
8585

86-
``` TEXT
86+
```TEXT
8787
$ python3 CWE-94.py
8888
Method: checkSignatures not found!
8989
CWE-94 is detected in ovaa.apk

0 commit comments

Comments
 (0)