Skip to content

Commit 42f7600

Browse files
authored
Optimize the document of Quark Script CWE-117 (#44)
1 parent f4b5ba3 commit 42f7600

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

CWE-117/README.md

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
# Detect CWE-117 in Android Application (allsafe.apk)
2-
1+
# Detect CWE-117 in Android Application
32

43
This scenario seeks to find **Improper Output Neutralization for Logs**.
5-
See [CWE-117](https://cwe.mitre.org/data/definitions/117.html) for more
6-
details.
74

8-
Let's use this [APK](https://github.com/t0thkr1s/allsafe) and the above
9-
APIs to show how the Quark script finds this vulnerability.
5+
## CWE-117: Improper Output Neutralization for Logs
6+
7+
We analyze the definition of CWE-117 and identify its characteristics.
8+
9+
See [CWE-117](https://cwe.mitre.org/data/definitions/117.html) for more details.
10+
11+
![image](https://imgur.com/poFP2Py.jpg)
1012

11-
First, we design a detection rule `writeContentToLog.json` to spot on
12-
behavior using the method that writes contents to the log file.
13+
## Code of CWE-117 in allsafe.apk
1314

14-
Then, we use `methodInstance.getArguments()` to get all parameter values
15-
of this method. And we check if these parameters contain keywords of
16-
APIs for neutralization, such as `escape`, `replace`, `format`, and
17-
`setFilter`.
15+
We use the [allsafe.apk](https://github.com/t0thkr1s/allsafe) sample to explain the vulnerability code of CWE-117.
1816

19-
If the answer is **YES**, that may result in secret context leakage into
20-
the log file, or the attacker may perform log forging attacks.
17+
![image](https://imgur.com/AgCpFzr.jpg)
2118

2219
## Quark Script CWE-117.py
2320

24-
``` python
21+
First, we design a detection rule ``writeContentToLog.json`` to spot on behavior using the method that writes contents to the log file.
22+
23+
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+
25+
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+
27+
```python
2528
from quark.script import Rule, runQuarkAnalysis
2629

2730
SAMPLE_PATH = "allsafe.apk"
@@ -48,7 +51,7 @@ for logOutputBehavior in quarkResult.behaviorOccurList:
4851

4952
## Quark Rule: writeContentToLog.json
5053

51-
``` json
54+
```json
5255
{
5356
"crime": "Write contents to the log.",
5457
"permission": [],
@@ -71,9 +74,7 @@ for logOutputBehavior in quarkResult.behaviorOccurList:
7174

7275
## Quark Script Result
7376

74-
- **allsafe.apk**
75-
76-
``` TEXT
77+
```TEXT
7778
$ python CWE-117.py
7879
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
7980
```

0 commit comments

Comments
 (0)