You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CWE-117/README.md
+13-5Lines changed: 13 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,22 +8,28 @@ We analyze the definition of CWE-117 and identify its characteristics.
8
8
9
9
See [CWE-117](https://cwe.mitre.org/data/definitions/117.html) for more details.
10
10
11
-

11
+

12
12
13
13
## Code of CWE-117 in allsafe.apk
14
14
15
15
We use the [allsafe.apk](https://github.com/t0thkr1s/allsafe) sample to explain the vulnerability code of CWE-117.
16
16
17
-

17
+

18
18
19
-
## Quark Script CWE-117.py
19
+
## CWE-117 Detection Process Using Quark Script API
20
+
21
+

20
22
21
23
First, we design a detection rule ``writeContentToLog.json`` to spot on behavior using the method that writes contents to the log file.
22
24
23
25
Then, we use ``methodInstance.getArguments()`` to get all parameter values of this method. And we check if these parameters contain keywords of APIs for neutralization, such as ``escape``, ``replace``, ``format``, and ``setFilter``.
24
26
25
27
If the answer is **YES**, that may result in secret context leakage into the log file, or the attacker may perform log forging attacks.
26
28
29
+
## Quark Script CWE-117.py
30
+
31
+

32
+
27
33
```python
28
34
from quark.script import Rule, runQuarkAnalysis
29
35
@@ -51,9 +57,11 @@ for logOutputBehavior in quarkResult.behaviorOccurList:
51
57
52
58
## Quark Rule: writeContentToLog.json
53
59
60
+

61
+
54
62
```json
55
63
{
56
-
"crime": "Write contents to the log.",
64
+
"crime": "Write contents to the log",
57
65
"permission": [],
58
66
"api": [
59
67
{
@@ -77,4 +85,4 @@ for logOutputBehavior in quarkResult.behaviorOccurList:
77
85
```TEXT
78
86
$ python CWE-117.py
79
87
CWE-117 is detected in method, Linfosecadventures/allsafe/challenges/InsecureLogging; lambda$onCreateView$0 (Lcom/google/android/material/textfield/TextInputEditText; Landroid/widget/TextView; I Landroid/view/KeyEvent;)Z
Copy file name to clipboardExpand all lines: CWE-295/README.md
+17-10Lines changed: 17 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,23 +8,29 @@ We analyze the definition of CWE-295 and identify its characteristics.
8
8
9
9
See [CWE-295](https://cwe.mitre.org/data/definitions/295.html) for more details.
10
10
11
-

11
+

12
12
13
13
## Code of CWE-295 in InsecureShop.apk
14
14
15
15
We use the [InsecureShop.apk](https://github.com/hax0rgb/InsecureShop) sample to explain the vulnerability code of CWE-295.
16
16
17
-

17
+

18
18
19
-
## Quark Script CWE-295.py
19
+
## CWE-295 Detection Process Using Quark Script API
20
+
21
+

20
22
21
23
To begin with, we use the API ``findMethodInAPK(samplePath, targetMethod)`` to locate all callers of method ``SslErrorHandler.proceed``.
22
24
23
-
Next, we must verify whether the caller overrides the method ``WebViewClient.onReceivedSslErroris``.
25
+
Next, we must verify whether the caller overrides the method ``WebViewClient.onReceivedSslError``.
26
+
27
+
Therefore, we check if the caller has the same method name and descriptor as ``WebViewClient.onReceivedSslError``, then use ``findSuperclassHierarchy()`` to see if its class extends ``Landroid/webkit/WebViewClient``.
24
28
25
-
Therefore, we check if the method name and descriptor of the caller match those of ``WebViewClient.onReceivedSslErroris``. After that, we use the API ``methodInstance.findSuperclassHierarchy()`` to check if the superclasses of the caller include ``Landroid/webkit/WebViewClient``.
29
+
If both are **YES**, the APK will proceed with HTTPS connections without certificate validation when an SSL error occurs, which may cause CWE-295 vulnerability.
26
30
27
-
If both are **YES**, the APK will call ``SslErrorHandler.procees`` without certificate validation when an SSL error occurs, which may cause CWE-295 vulnerability.
for sslProceedCaller in findMethodInAPK(SAMPLE_PATH, TARGET_METHOD):
@@ -56,4 +63,4 @@ for sslProceedCaller in findMethodInAPK(SAMPLE_PATH, TARGET_METHOD):
56
63
```TEXT
57
64
$ python3 CWE-295.py
58
65
CWE-295 is detected in method, Lcom/insecureshop/util/CustomWebViewClient; onReceivedSslError (Landroid/webkit/WebView; Landroid/webkit/SslErrorHandler; Landroid/net/http/SslError;)V
Copy file name to clipboardExpand all lines: CWE-89/README.md
+19-19Lines changed: 19 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,31 +6,29 @@ This scenario seeks to find **SQL injection** in the APK file.
6
6
7
7
We analyze the definition of CWE-89 and identify its characteristics.
8
8
9
-
See [CWE-89](https://cwe.mitre.org/data/definitions/89.html) for more
10
-
details.
9
+
See [CWE-89](https://cwe.mitre.org/data/definitions/89.html) for more details.
11
10
12
-

11
+

13
12
14
-
## Code of CWE-89 in androgoat.apk
13
+
## Code of CWE-89 in AndroGoat.apk
15
14
16
-
We use the [androgoat.apk](https://github.com/satishpatnayak/AndroGoat)
17
-
sample to explain the vulnerability code of CWE-89.
15
+
We use the [AndroGoat.apk](https://github.com/satishpatnayak/AndroGoat) sample to explain the vulnerability code of CWE-89.
18
16
19
-

17
+

20
18
21
-
## Quark Script: CWE-89.py
19
+
## CWE-89 Detection Process Using Quark Script API
20
+
21
+

22
+
23
+
Let’s use the above APIs to show how the Quark script finds this vulnerability.
22
24
23
-
Let\'s use the above APIs to show how the Quark script finds this
24
-
vulnerability.
25
+
First, we design a detection rule `executeSQLCommand.json` to spot on behavior using SQL command Execution. Then, we use API `behaviorInstance.isArgFromMethod(targetMethod)` to check if `append` uses the value of `getText` as the argument. If yes, we confirmed that the SQL command string is built from user input, which will cause CWE-89 vulnerability.
25
26
26
-
First, we design a detection rule `executeSQLCommand.json` to spot on
27
-
behavior using SQL command Execution. Then, we use API
28
-
`behaviorInstance.isArgFromMethod(targetMethod)` to check if `append`
29
-
uses the value of `getText` as the argument. If yes, we confirmed that
30
-
the SQL command string is built from user input, which will cause CWE-89
31
-
vulnerability.
27
+
## Quark Script: CWE-89.py
28
+
29
+

32
30
33
-
```python
31
+
```python
34
32
from quark.script import runQuarkAnalysis, Rule
35
33
36
34
SAMPLE_PATH="AndroGoat.apk"
@@ -54,7 +52,9 @@ for sqlCommandExecution in quarkResult.behaviorOccurList:
54
52
55
53
## Quark Rule: executeSQLCommand.json
56
54
57
-
```json
55
+

56
+
57
+
```json
58
58
{
59
59
"crime": "Execute SQL Command",
60
60
"permission": [],
@@ -77,7 +77,7 @@ for sqlCommandExecution in quarkResult.behaviorOccurList:
0 commit comments