Skip to content

Commit 5882cef

Browse files
authored
Optimize the document of Quark Script CWE-312 and CWE-798 (#48)
1 parent 2bb149e commit 5882cef

File tree

4 files changed

+44
-46
lines changed

4 files changed

+44
-46
lines changed

.github/workflows/testQuarkScript.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
build:
1111

12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313

1414

1515
steps:
@@ -57,7 +57,7 @@ jobs:
5757
git clone "https://github.com/quark-engine/apk-samples.git"
5858
mv -vn $GITHUB_WORKSPACE/CWE-*/CWE-*.py test_ground/
5959
mv -vn $GITHUB_WORKSPACE/CWE-*/*.json test_ground/
60-
mv -vn $GITHUB_WORKSPACE/CWE-*/*.js test_ground/
60+
# mv -vn $GITHUB_WORKSPACE/CWE-*/*.js test_ground/
6161
mv -vn ./apk-samples/vulnerable-samples/*.apk test_ground/
6262
6363

@@ -74,4 +74,3 @@ jobs:
7474
echo $line
7575
fi
7676
done
77-

CWE-312/README.md

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

3+
This scenario seeks to find **cleartext storage of sensitive data** in the APK file.
34

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
86

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

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.
1310

14-
![image](https://i.imgur.com/cy2EiZx.jpg)
11+
![image](https://imgur.com/mD2uXUy.jpg)
1512

1613
## Code of CWE-312 in ovaa.apk
1714

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+
![image](https://imgur.com/MfnYIYy.jpg)
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.
2022

21-
![image](https://i.imgur.com/KsFsxTu.jpg)
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.
2226

23-
## Quark Script CWE-312.py
27+
![image](https://imgur.com/eNjm3ES.jpg)
2428

25-
Let\'s use the above APIs to show how the Quark script finds this
26-
vulnerability.
29+
## Quark Script: CWE-312.py
2730

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+
![image](https://imgur.com/rxMPZX8.jpg)
3332

34-
``` python
33+
```python
3534
from quark.script.frida import runFridaHook
3635
from quark.script.ares import checkClearText
3736

@@ -62,7 +61,7 @@ for putString in fridaResult.behaviorOccurList:
6261

6362
## Frida Script: agent.js
6463

65-
``` javascript
64+
```javascript
6665
// -*- coding: utf-8 -*-
6766
// This file is part of Quark-Engine - https://github.com/quark-engine/quark-engine
6867
// See the file 'LICENSE' for copying permission.
@@ -125,7 +124,7 @@ rpc.exports["watchMethodCall"] = (classAndMethodName, methodParamTypes) => watch
125124

126125
## Quark Script Result
127126

128-
``` TEXT
127+
```TEXT
129128
$ python3 CWE-312.py
130129
The CWE-312 vulnerability is found. The cleartext is "[email protected]"
131130
The CWE-312 vulnerability is found. The cleartext is "password"

CWE-312/agent.js

Whitespace-only changes.

CWE-798/README.md

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

3-
This scenario seeks to find hard-coded credentials in the APK file.
3+
This scenario seeks to find **hard-coded credentials** in the APK file.
44

5-
## CWE-798 Use of Hard-coded Credentials
5+
## CWE-798: Use of Hard-coded Credentials
66

77
We analyze the definition of CWE-798 and identify its characteristics.
88

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

12-
![image](https://i.imgur.com/0G9APpf.jpg)
11+
![image](https://imgur.com/rF8J8hE.png)
1312

1413
## Code of CWE-798 in ovaa.apk
1514

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

19-
![image](https://i.imgur.com/ikaJlDW.jpg)
17+
![image](https://imgur.com/Cg7DacP.png)
2018

21-
## Quark Script: CWE-798.py
2219

23-
Let\'s use the above APIs to show how the Quark script finds this
24-
vulnerability.
20+
## CWE-798 Detection Process Using Quark Script API
21+
22+
![image](https://imgur.com/R8CfDqD.png)
23+
24+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
25+
26+
First, we design a detection rule ``findSecretKeySpec.json`` to spot on behavior using the constructor ``SecretKeySpec``. Second, we get all the parameter values from this constructor. Then, we parse the AES key from the parameter values. Finally, we check if the AES key is hardcoded in the APK file. If the answer is **YES**, BINGO!!! We find hard-coded credentials in the APK file.
2527

26-
First, we design a detection rule `findSecretKeySpec.json` to spot on
27-
behavior using the method `SecretKeySpec`. Then, we get all the
28-
parameter values that are input to this method. And we parse the AES key
29-
out of the parameter values. Finally, we check if the AES key is
30-
hardcoded in the APK file. If the answer is YES, BINGO!!! We find
31-
hard-coded credentials in the APK file.
28+
## Quark Script: CWE-798.py
29+
30+
![image](https://imgur.com/IOyrqDc.png)
3231

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

@@ -54,7 +53,9 @@ for secretKeySpec in quarkResult.behaviorOccurList:
5453

5554
## Quark Rule: findSecretKeySpec.json
5655

57-
``` json
56+
![image](https://imgur.com/2BYOE70.png)
57+
58+
```json
5859
{
5960
"crime": "Detect APK using SecretKeySpec.",
6061
"permission": [],
@@ -77,8 +78,7 @@ for secretKeySpec in quarkResult.behaviorOccurList:
7778

7879
## Quark Script Result
7980

80-
``` TEXT
81-
$ python3 findSecretKeySpec.py
82-
81+
```TEXT
82+
$ python3 CWE-798.py
8383
Found hard-coded AES key 49u5gh249gh24985ghf429gh4ch8f23f
8484
```

0 commit comments

Comments
 (0)