@@ -2349,7 +2349,7 @@ Quark Script Result
2349
2349
2350
2350
2351
2351
Detect CWE-78 in Android Application
2352
- --------------------------------------
2352
+ -------------------------------------
2353
2353
2354
2354
This scenario seeks to find **Improper Neutralization of Special Elements used in an OS Command ** in the APK file.
2355
2355
@@ -2360,28 +2360,35 @@ We analyze the definition of CWE-78 and identify its characteristics.
2360
2360
2361
2361
See `CWE-78 <https://cwe.mitre.org/data/definitions/78.html >`_ for more details.
2362
2362
2363
- .. image :: https://imgur.com/aUB195P .png
2363
+ .. image :: https://imgur.com/HpMGGsO .png
2364
2364
2365
2365
Code of CWE-78 in Vuldroid.apk
2366
2366
===============================
2367
2367
2368
2368
We use the `Vuldroid.apk <https://github.com/jaiswalakshansh/Vuldroid >`_ sample to explain the vulnerability code of CWE-78.
2369
2369
2370
- .. image :: https://imgur.com/hO6m3Bz .png
2370
+ .. image :: https://imgur.com/7Tu0Y3H .png
2371
2371
2372
- Quark Script: CWE-78.py
2373
- ========================
2372
+ CWE-78 Detection Process Using Quark Script API
2373
+ ================================================
2374
+
2375
+ .. image :: https://imgur.com/Hi7qGjw.png
2374
2376
2375
2377
Let’s use the above APIs to show how the Quark script finds this vulnerability.
2376
2378
2377
2379
First, we design a detection rule ``ExternalStringsCommands.json `` to spot on behavior using external strings as commands.
2378
2380
2379
2381
Next, we use Quark API ``behaviorInstance.getMethodsInArgs() `` to get the methods that passed the external command.
2380
2382
2381
- Then we check if the method neutralizes any special elements found in the argument.
2383
+ Then we check if the method neutralizes any special elements in the argument.
2382
2384
2383
2385
If the neutralization is not complete, then it may cause CWE-78 vulnerability.
2384
2386
2387
+ Quark Script: CWE-78.py
2388
+ ========================
2389
+
2390
+ .. image :: https://imgur.com/UpRWgGe.png
2391
+
2385
2392
.. code-block :: python
2386
2393
2387
2394
from quark.script import runQuarkAnalysis, Rule, findMethodInAPK
@@ -2395,7 +2402,11 @@ If the neutralization is not complete, then it may cause CWE-78 vulnerability.
2395
2402
(" Ljava/lang/String;" , " indexOf" , " (I)I" ),
2396
2403
(" Ljava/lang/String;" , " indexOf" , " (Ljava/lang/String;)I" ),
2397
2404
(" Ljava/lang/String;" , " matches" , " (Ljava/lang/String;)Z" ),
2398
- (" Ljava/lang/String;" , " replaceAll" , " (Ljava/lang/String; Ljava/lang/String;)Ljava/lang/String;" )
2405
+ (
2406
+ " Ljava/lang/String;" ,
2407
+ " replaceAll" ,
2408
+ " (Ljava/lang/String; Ljava/lang/String;)Ljava/lang/String;" ,
2409
+ ),
2399
2410
])
2400
2411
2401
2412
specialElementsPattern = r " [ ;|,>` ]+ "
@@ -2407,18 +2418,19 @@ If the neutralization is not complete, then it may cause CWE-78 vulnerability.
2407
2418
2408
2419
methodCalled = set ()
2409
2420
caller = ExternalStringCommand.methodCaller
2410
-
2421
+
2411
2422
for method in ExternalStringCommand.getMethodsInArgs():
2412
2423
methodCalled.add(method.fullName)
2413
-
2424
+
2414
2425
if methodCalled.intersection(STRING_MATCHING_API ) and not ExternalStringCommand.hasString(specialElementsPattern):
2415
2426
continue
2416
2427
else :
2417
2428
print (f " CWE-78 is detected in method, { caller.fullName} " )
2418
-
2419
-
2429
+
2420
2430
Quark Rule: ExternalStringCommand.json
2421
- =========================================
2431
+ =======================================
2432
+
2433
+ .. image :: https://imgur.com/eoV8hnZ.png
2422
2434
2423
2435
.. code-block :: json
2424
2436
@@ -2441,10 +2453,8 @@ Quark Rule: ExternalStringCommand.json
2441
2453
"label" : []
2442
2454
}
2443
2455
2444
-
2445
2456
Quark Script Result
2446
- ======================
2447
- - **Vuldroid.apk **
2457
+ ====================
2448
2458
2449
2459
.. code-block :: TEXT
2450
2460
@@ -2453,6 +2463,7 @@ Quark Script Result
2453
2463
2454
2464
2455
2465
2466
+
2456
2467
Detect CWE-117 in Android Application
2457
2468
--------------------------------------
2458
2469
0 commit comments