Skip to content

Commit 3be7526

Browse files
authored
Optimize the document of Quark Script CWE-88 (#740)
1 parent 0429e61 commit 3be7526

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

docs/source/quark_script.rst

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,17 +2108,19 @@ We analyze the definition of CWE-88 and identify its characteristics.
21082108

21092109
See `CWE-88 <https://cwe.mitre.org/data/definitions/88.html>`_ for more details.
21102110

2111-
.. image:: https://imgur.com/7EBPGUT.png
2111+
.. image:: https://imgur.com/5vfXkIE.png
21122112

21132113
Code of CWE-88 in vuldroid.apk
2114-
=========================================
2114+
===============================
21152115

21162116
We use the `vuldroid.apk <https://github.com/jaiswalakshansh/Vuldroid>`_ sample to explain the vulnerability code of CWE-88.
21172117

2118-
.. image:: https://imgur.com/emnvGcE.png
2118+
.. image:: https://imgur.com/recX0t5.png
21192119

2120-
Quark Script: CWE-88.py
2121-
========================
2120+
CWE-88 Detection Process Using Quark Script API
2121+
================================================
2122+
2123+
.. image:: https://imgur.com/s7Ajr6M.png
21222124

21232125
Let‘s use the above APIs to show how the Quark script finds this vulnerability.
21242126

@@ -2130,44 +2132,50 @@ Then we check if the method neutralizes any special elements in the argument.
21302132

21312133
If the neutralization is not complete, then it may cause CWE-88 vulnerability.
21322134

2135+
Quark Script: CWE-88.py
2136+
========================
2137+
2138+
.. image:: https://imgur.com/f8Yee3P.png
2139+
21332140
.. code-block:: python
21342141
21352142
from quark.script import runQuarkAnalysis, Rule, findMethodInAPK
21362143
2137-
SAMPLE_PATH = "Vuldroid.apk"
2138-
RULE_PATH = "ExternalStringCommand.json"
2144+
SAMPLE_PATH = "Vuldroid.apk"
2145+
RULE_PATH = "ExternalStringCommand.json"
21392146
21402147
2141-
STRING_MATCHING_API = set([
2142-
("Ljava/lang/String;", "contains", "(Ljava/lang/CharSequence)Z"),
2143-
("Ljava/lang/String;", "indexOf", "(I)I"),
2144-
("Ljava/lang/String;", "indexOf", "(Ljava/lang/String;)I"),
2145-
("Ljava/lang/String;", "matches", "(Ljava/lang/String;)Z"),
2146-
("Ljava/lang/String;", "replaceAll", "(Ljava/lang/String; Ljava/lang/String;)Ljava/lang/String;")
2147-
])
2148+
STRING_MATCHING_API = set([
2149+
("Ljava/lang/String;", "contains", "(Ljava/lang/CharSequence)Z"),
2150+
("Ljava/lang/String;", "indexOf", "(I)I"),
2151+
("Ljava/lang/String;", "indexOf", "(Ljava/lang/String;)I"),
2152+
("Ljava/lang/String;", "matches", "(Ljava/lang/String;)Z"),
2153+
("Ljava/lang/String;", "replaceAll", "(Ljava/lang/String; Ljava/lang/String;)Ljava/lang/String;")
2154+
])
21482155
2149-
delimeter = "-"
2156+
delimeter = "-"
21502157
2151-
ruleInstance = Rule(RULE_PATH)
2152-
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
2158+
ruleInstance = Rule(RULE_PATH)
2159+
quarkResult = runQuarkAnalysis(SAMPLE_PATH, ruleInstance)
21532160
2154-
for ExternalStringCommand in quarkResult.behaviorOccurList:
2161+
for ExternalStringCommand in quarkResult.behaviorOccurList:
21552162
2156-
methodCalled = set()
2157-
caller = ExternalStringCommand.methodCaller
2163+
methodCalled = set()
2164+
caller = ExternalStringCommand.methodCaller
21582165
2159-
for method in ExternalStringCommand.getMethodsInArgs():
2160-
methodCalled.add(method.fullName)
2166+
for method in ExternalStringCommand.getMethodsInArgs():
2167+
methodCalled.add(method.fullName)
21612168
2162-
if methodCalled.intersection(STRING_MATCHING_API) and not ExternalStringCommand.hasString(delimeter):
2163-
continue
2164-
else:
2165-
print(f"CWE-88 is detected in method, {caller.fullName}")
2169+
if methodCalled.intersection(STRING_MATCHING_API) and not ExternalStringCommand.hasString(delimeter):
2170+
continue
2171+
else:
2172+
print(f"CWE-88 is detected in method, {caller.fullName}")
21662173
21672174
2168-
21692175
Quark Rule: ExternalStringCommand.json
2170-
=========================================
2176+
=======================================
2177+
2178+
.. image:: https://imgur.com/s9QNF19.png
21712179

21722180
.. code-block:: json
21732181
@@ -2190,16 +2198,16 @@ Quark Rule: ExternalStringCommand.json
21902198
"label": []
21912199
}
21922200
2193-
21942201
Quark Script Result
2195-
======================
2202+
====================
21962203

21972204
.. code-block:: TEXT
21982205
21992206
$ python3 CWE-88.py
22002207
CWE-88 is detected in method, Lcom/vuldroid/application/RootDetection; onCreate (Landroid/os/Bundle;)V
22012208
22022209
2210+
22032211
Detect CWE-925 in Android Application
22042212
--------------------------------------
22052213

0 commit comments

Comments
 (0)