Skip to content

Commit d28c7dc

Browse files
authored
Optimize the document of Quark Script CWE-319, 327, and 328 (#59)
1 parent 4de585b commit d28c7dc

File tree

7 files changed

+61
-63
lines changed

7 files changed

+61
-63
lines changed

CWE-319/CWE-319.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
if cleartextProtocolUrl:
2323
print(f"CWE-319 detected!")
2424
print(f"Here are the found URLs with cleartext protocol:")
25-
print("\n".join(cleartextProtocolUrl))
25+
print("\n".join(cleartextProtocolUrl))

CWE-319/README.md

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

3-
4-
This scenario seeks to find **Cleartext Transmission of Sensitive
5-
Information** in the APK file.
3+
This scenario seeks to find **Cleartext Transmission of Sensitive Information** in the APK file.
64

75
## CWE-319 Cleartext Transmission of Sensitive Information
86

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

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

14-
![image](https://imgur.com/tk8rtYf.jpg)
11+
![image](https://imgur.com/hjEYP5b.jpg)
1512

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

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

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

23-
## Quark Script: CWE-319.py
19+
## CWE-319 Detection Process Using Quark Script API
20+
21+
![image](https://imgur.com/H1FgUtE.jpg)
22+
23+
Let’s use the above APIs to show how the Quark script finds this vulnerability. This sample uses the package `Retrofit` to request Web APIs, but the APIs use cleartext protocols.
2424

25-
Let\'s use the above APIs to show how the Quark script finds this
26-
vulnerability. This sample uses the package Retrofit to request Web
27-
APIs, but the APIs use cleartext protocols.
25+
We first design a detection rule `setRetrofitBaseUrl.json` to spot on behavior that sets the base URL of the Retrofit instance. Then, we loop through a custom list of cleartext protocol schemes and use API `behaviorInstance.hasString(pattern, isRegex)` to filter if there are arguments that are URL strings with cleartext protocol.
2826

29-
We first design a detection rule `setRetrofitBaseUrl.json` to spot on
30-
behavior that sets the base URL of the Retrofit instance. Then, we loop
31-
through a custom list of cleartext protocol schemes and use API
32-
`behaviorInstance.hasString(pattern, isRegex)` to filter arguments that
33-
are URL strings with cleartext protocol.
27+
If the answer is **YES**, CWE-319 vulnerability is caused.
3428

35-
``` python
29+
## Quark Script: CWE-319.py
30+
31+
![image](https://imgur.com/CktArDJ.jpg)
32+
33+
```python
3634
from quark.script import runQuarkAnalysis, Rule
3735

3836
SAMPLE_PATH = "./ovaa.apk"
@@ -62,7 +60,9 @@ for setRetrofitBaseUrl in quarkResult.behaviorOccurList:
6260

6361
## Quark Rule: setRetrofitBaseUrl.json
6462

65-
``` json
63+
![image](https://imgur.com/751Dhce.jpg)
64+
65+
```json
6666
{
6767
"crime": "Set Retrofit Base Url",
6868
"permission": [],
@@ -86,7 +86,7 @@ for setRetrofitBaseUrl in quarkResult.behaviorOccurList:
8686

8787
## Quark Script Result
8888

89-
``` TEXT
89+
```TEXT
9090
$ python3 CWE-319.py
9191
CWE-319 detected!
9292
Here are the found URLs with cleartext protocol:

CWE-327/CWE-327.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
for algo in WEAK_ALGORITHMS:
1616
if useCryptoAlgo.hasString(algo):
17-
print(f"CWE-327 is detected in method, {caller.fullName}")
17+
print(f"CWE-327 is detected in method, {caller.fullName}")

CWE-327/README.md

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

3-
This scenario seeks to find **Use of a Broken or Risky Cryptographic
4-
Algorithm** in the APK file.
3+
This scenario seeks to find **Use of a Broken or Risky Cryptographic Algorithm** in the APK file.
54

6-
# CWE-327 Use of a Broken or Risky Cryptographic Algorithm
5+
## CWE-327 Use of a Broken or Risky Cryptographic Algorithm
76

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

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

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

1513
## Code of CWE-327 in InjuredAndroid.apk
1614

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

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

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

24-
Let's use the above APIs to show how the Quark script finds this
25-
vulnerability.
25+
We first design a detection rule `useOfCryptographicAlgo.json` to spot on behavior using cryptographic algorithms. Then, we use API `behaviorInstance.hasString(pattern, isRegex)` with a list to check if the algorithm is risky. If **YES**, that may cause the exposure of sensitive data.
2626

27-
We first design a detection rule `useOfCryptographicAlgo.json` to spot
28-
on behavior using cryptographic algorithms. Then, we use API
29-
`behaviorInstance.hasString(pattern, isRegex)` with a list to check if
30-
the algorithm is risky. If YES, that may cause the exposure of sensitive
31-
data.
27+
## Quark Script CWE-327.py
28+
29+
![image](https://imgur.com/4fa3yS0.jpg)
3230

33-
``` python
31+
```python
3432
from quark.script import runQuarkAnalysis, Rule
3533

3634
SAMPLE_PATH = "InjuredAndroid.apk"
@@ -52,7 +50,9 @@ for useCryptoAlgo in quarkResult.behaviorOccurList:
5250

5351
## Quark Rule: useOfCryptographicAlgo.json
5452

55-
``` json
53+
![image](https://imgur.com/rjRykWM.jpg)
54+
55+
```json
5656
{
5757
"crime": "Use of cryptographic algorithm",
5858
"permission": [],
@@ -75,7 +75,7 @@ for useCryptoAlgo in quarkResult.behaviorOccurList:
7575

7676
## Quark Script Result
7777

78-
``` TEXT
78+
```TEXT
7979
$ python3 CWE-327.py
8080
CWE-327 is detected in method, Lb3nac/injuredandroid/k; b (Ljava/lang/String;)Ljava/lang/String;
8181
CWE-327 is detected in method, Lb3nac/injuredandroid/k; a (Ljava/lang/String;)Ljava/lang/String;

CWE-327/useOfCryptographicAlgo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
],
1616
"score": 1,
1717
"label": []
18-
}
18+
}

CWE-328/CWE-328.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
print(
3838
f"CWE-328 is detected in {SAMPLE_PATH},\n\t"
3939
f"and it occurs in method, {setHashAlgo.fullName}"
40-
)
40+
)

CWE-328/README.md

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

3-
4-
This scenario seeks to find **the use of weak Hash**.
3+
This scenario seeks to find the **Use of Weak Hash**.
54

65
## CWE-328 Use of Weak Hash
76

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

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

13-
![image](https://imgur.com/1jkGcSq.png)
11+
![image](https://imgur.com/DUaOaKi.jpg)
1412

1513
## Code of CWE-328 in allsafe.apk
1614

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

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

22-
## Quark Script: CWE-328.py
19+
## CWE-328 Detection Process Using Quark Script API
20+
21+
![image](https://imgur.com/bM7WJKo.jpg)
2322

24-
Let's use the above APIs to show how the Quark script finds this
25-
vulnerability.
23+
Let's use the above APIs to show how the Quark script finds this vulnerability.
24+
25+
First, we use API `findMethodInAPK(samplePath, targetMethod)` to find the method `MessageDigest.getInstance()` or `SecretKeyFactory.getInstance()`. Next, we use API `methodInstance.getArguments()` with a list to check if the method uses weak hashing algorithms. If **YES**, that causes CWE-328 vulnerability.
26+
27+
## Quark Script: CWE-328.py
2628

27-
First, we use API `findMethodInAPK(samplePath, targetMethod)` to find
28-
the method `MessageDigest.getInstance()` or
29-
`SecretKeyFactory.getInstance()`. Next, we use API
30-
`methodInstance.getArguments()` with a list to check if the method uses
31-
weak hashing algorithms. If **YES**, that causes CWE-328 vulnerability.
29+
![image](https://imgur.com/wb9Baa3.jpg)
3230

33-
``` python
31+
```python
3432
from quark.script import findMethodInAPK
3533

3634
SAMPLE_PATH = "./allsafe.apk"
@@ -75,7 +73,7 @@ for setHashAlgo in methodsFound:
7573

7674
## Quark Script Result
7775

78-
``` TEXT
76+
```TEXT
7977
$ python3 CWE-328.py
8078
CWE-328 is detected in ./allsafe.apk,
8179
and it occurs in method, Linfosecadventures/allsafe/challenges/SQLInjection; md5 (Ljava/lang/String;)Ljava/lang/String;

0 commit comments

Comments
 (0)