Skip to content

Commit 25da562

Browse files
authored
Optimize the document of Quark Script CWE-94
1 parent ab1c9ce commit 25da562

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

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)