-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
3721 lines (3473 loc) · 359 KB
/
index.html
File metadata and controls
3721 lines (3473 loc) · 359 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="./">
<head>
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Quark Script — quark-script v26.1.1 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=9edc463e" />
<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=55dbfdaa"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="#" class="icon icon-home">
quark-script
<img src="_static/quark-logo.png" class="logo" alt="Logo"/>
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<!-- Local TOC -->
<div class="local-toc"><ul>
<li><a class="reference internal" href="#">Ecosystem for Mobile Security Tools</a><ul>
<li><a class="reference internal" href="#innovative-interactive">Innovative & Interactive</a></li>
<li><a class="reference internal" href="#dynamic-static-analysis">Dynamic & Static Analysis</a></li>
<li><a class="reference internal" href="#re-usable-sharable">Re-Usable & Sharable</a></li>
<li><a class="reference internal" href="#more-apis-to-come">More APIs to come</a></li>
</ul>
</li>
<li><a class="reference internal" href="#quickstart">Quickstart</a><ul>
<li><a class="reference internal" href="#step-1-environments-requirements">Step 1: Environments Requirements</a></li>
<li><a class="reference internal" href="#step-2-install-quark-engine">Step 2: Install Quark Engine</a></li>
<li><a class="reference internal" href="#step-3-prepare-quark-script-detection-rule-and-the-sample-file">Step 3: Prepare Quark Script, Detection Rule and the Sample File</a></li>
<li><a class="reference internal" href="#step-4-run-the-script">Step 4: Run the script</a></li>
</ul>
</li>
<li><a class="reference internal" href="#introduce-of-quark-script-apis">Introduce of Quark Script APIs</a><ul>
<li><a class="reference internal" href="#findmethodinapk-samplepath-targetmethod">findMethodInAPK(samplePath, targetMethod)</a></li>
<li><a class="reference internal" href="#checkmethodcalls-samplepath-targetmethod-checkmethods">checkMethodCalls(samplePath, targetMethod, checkMethods)</a></li>
<li><a class="reference internal" href="#findmethodimpls-samplepath-targetmethod">findMethodImpls(samplePath, targetMethod)</a></li>
<li><a class="reference internal" href="#ismethodreturnalwaystrue-samplepath-targetmethod">isMethodReturnAlwaysTrue(samplePath, targetMethod)</a></li>
<li><a class="reference internal" href="#rule-rule-json">Rule(rule.json)</a></li>
<li><a class="reference internal" href="#runquarkanalysis-sample-path-ruleinstance">runQuarkAnalysis(SAMPLE_PATH, ruleInstance)</a></li>
<li><a class="reference internal" href="#quarkresultinstance-behavioroccurlist">quarkResultInstance.behaviorOccurList</a></li>
<li><a class="reference internal" href="#quarkresultinstance-getallstrings-none">quarkResultInstance.getAllStrings(none)</a></li>
<li><a class="reference internal" href="#quarkresultinstance-ishardcoded-argument">quarkResultInstance.isHardcoded(argument)</a></li>
<li><a class="reference internal" href="#quarkresultinstance-findmethodincaller-callermethod-targetmethod">quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)</a></li>
<li><a class="reference internal" href="#behaviorinstance-firstapi-fullname">behaviorInstance.firstAPI.fullName</a></li>
<li><a class="reference internal" href="#behaviorinstance-secondapi-fullname">behaviorInstance.secondAPI.fullName</a></li>
<li><a class="reference internal" href="#behaviorinstance-hasstring-pattern-isregex">behaviorInstance.hasString(pattern, isRegex)</a></li>
<li><a class="reference internal" href="#behaviorinstance-hasurl-none">behaviorInstance.hasUrl(none)</a></li>
<li><a class="reference internal" href="#behaviorinstance-methodcaller">behaviorInstance.methodCaller</a></li>
<li><a class="reference internal" href="#behaviorinstance-getparamvalues-none">behaviorInstance.getParamValues(none)</a></li>
<li><a class="reference internal" href="#behaviorinstance-isargfrommethod-targetmethod">behaviorInstance.isArgFromMethod(targetMethod)</a></li>
<li><a class="reference internal" href="#behaviorinstance-getmethodsinargs-none">behaviorInstance.getMethodsInArgs(none)</a></li>
<li><a class="reference internal" href="#methodinstance-getxreffrom-none">methodInstance.getXrefFrom(none)</a></li>
<li><a class="reference internal" href="#methodinstance-getxrefto-none">methodInstance.getXrefTo(none)</a></li>
<li><a class="reference internal" href="#methodinstance-getarguments-none">methodInstance.getArguments(none)</a></li>
<li><a class="reference internal" href="#methodinstance-findsuperclasshierarchy-none">methodInstance.findSuperclassHierarchy(none)</a></li>
<li><a class="reference internal" href="#objection-host">Objection(host)</a></li>
<li><a class="reference internal" href="#objinstance-hookmethod-method-watchargs-watchbacktrace-watchret">objInstance.hookMethod(method, watchArgs, watchBacktrace, watchRet)</a></li>
<li><a class="reference internal" href="#runfridahook-apkpackagename-targetmethod-methodparamtypes-secondtowait">runFridaHook(apkPackageName, targetMethod, methodParamTypes, secondToWait)</a></li>
<li><a class="reference internal" href="#checkcleartext-inputstring">checkClearText(inputString)</a></li>
<li><a class="reference internal" href="#getactivities-samplepath">getActivities(samplePath)</a></li>
<li><a class="reference internal" href="#activityinstance-hasintentfilter-none">activityInstance.hasIntentFilter(none)</a></li>
<li><a class="reference internal" href="#activityinstance-isexported-none">activityInstance.isExported(none)</a></li>
<li><a class="reference internal" href="#getreceivers-samplepath">getReceivers(samplePath)</a></li>
<li><a class="reference internal" href="#receiverinstance-hasintentfilter-none">receiverInstance.hasIntentFilter(none)</a></li>
<li><a class="reference internal" href="#receiverinstance-isexported-none">receiverInstance.isExported(none)</a></li>
<li><a class="reference internal" href="#getapplication-samplepath">getApplication(samplePath)</a></li>
<li><a class="reference internal" href="#applicationinstance-isdebuggable-none">applicationInstance.isDebuggable(none)</a></li>
<li><a class="reference internal" href="#getproviders-samplepath">getProviders(samplePath)</a></li>
<li><a class="reference internal" href="#providerinstance-isexported-none">providerInstance.isExported(none)</a></li>
</ul>
</li>
<li><a class="reference internal" href="#analyzing-real-case-instastealer-using-quark-script">Analyzing real case (InstaStealer) using Quark Script</a><ul>
<li><a class="reference internal" href="#quark-script-that-dynamic-hooks-the-method-containing-urls">Quark Script that dynamic hooks the method containing urls</a></li>
<li><a class="reference internal" href="#quark-script-result">Quark Script Result</a></li>
<li><a class="reference internal" href="#logs-on-the-objection-terminal-hooking">Logs on the Objection terminal (hooking)</a></li>
<li><a class="reference internal" href="#method-callcomponentmethod-with-urls-is-detected-triggered">Method (callComponentMethod) with urls is detected triggered!</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-798-in-android-application">Detect CWE-798 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-798-use-of-hard-coded-credentials">CWE-798: Use of Hard-coded Credentials</a></li>
<li><a class="reference internal" href="#code-of-cwe-798-in-ovaa-apk">Code of CWE-798 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-798-detection-process-using-quark-script-api">CWE-798 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-798-py">Quark Script: CWE-798.py</a></li>
<li><a class="reference internal" href="#quark-rule-findsecretkeyspec-json">Quark Rule: findSecretKeySpec.json</a></li>
<li><a class="reference internal" href="#id5">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-94-in-android-application">Detect CWE-94 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-94-improper-control-of-generation-of-code">CWE-94: Improper Control of Generation of Code</a></li>
<li><a class="reference internal" href="#code-of-cwe-94-in-ovaa-apk">Code of CWE-94 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-94-detection-process-using-quark-script-api">CWE-94 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-94-py">Quark Script: CWE-94.py</a></li>
<li><a class="reference internal" href="#quark-rule-loadexternalcode-json">Quark Rule: loadExternalCode.json</a></li>
<li><a class="reference internal" href="#id7">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-921-in-android-application">Detect CWE-921 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-921-storage-of-sensitive-data-in-a-mechanism-without-access-control">CWE-921: Storage of Sensitive Data in a Mechanism without Access Control</a></li>
<li><a class="reference internal" href="#code-of-cwe-921-in-ovaa-apk">Code of CWE-921 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-921-detection-process-using-quark-script-api">CWE-921 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-921-py">Quark Script: CWE-921.py</a></li>
<li><a class="reference internal" href="#quark-rule-checkfileexistence-json">Quark Rule: checkFileExistence.json</a></li>
<li><a class="reference internal" href="#id9">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-312-in-android-application">Detect CWE-312 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-312-cleartext-storage-of-sensitive-information">CWE-312: Cleartext Storage of Sensitive Information</a></li>
<li><a class="reference internal" href="#code-of-cwe-312-in-ovaa-apk">Code of CWE-312 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-312-detection-process-using-quark-script-api">CWE-312 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-312-py">Quark Script: CWE-312.py</a></li>
<li><a class="reference internal" href="#frida-script-agent-js">Frida Script: agent.js</a></li>
<li><a class="reference internal" href="#id11">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-89-in-android-application">Detect CWE-89 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-89-improper-neutralization-of-special-elements-used-in-an-sql-command">CWE-89 Improper Neutralization of Special Elements used in an SQL Command</a></li>
<li><a class="reference internal" href="#code-of-cwe-89-in-androgoat-apk">Code of CWE-89 in AndroGoat.apk</a></li>
<li><a class="reference internal" href="#cwe-89-detection-process-using-quark-script-api">CWE-89 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-89-py">Quark Script: CWE-89.py</a></li>
<li><a class="reference internal" href="#quark-rule-executesqlcommand-json">Quark Rule: executeSQLCommand.json</a></li>
<li><a class="reference internal" href="#id12">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-926-in-android-application">Detect CWE-926 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-926-improper-export-of-android-application-components">CWE-926 Improper Export of Android Application Components</a></li>
<li><a class="reference internal" href="#code-of-cwe-926-in-dvba-apk">Code of CWE-926 in dvba.apk</a></li>
<li><a class="reference internal" href="#cwe-926-detection-process-using-quark-script-api">CWE-926 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-926-py">Quark Script: CWE-926.py</a></li>
<li><a class="reference internal" href="#id13">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-749-in-android-application">Detect CWE-749 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-749-exposed-dangerous-method-or-function">CWE-749 Exposed Dangerous Method or Function</a></li>
<li><a class="reference internal" href="#code-of-cwe-749-in-mstg-android-java-apk">Code of CWE-749 in MSTG-Android-Java.apk</a></li>
<li><a class="reference internal" href="#cwe-749-detection-process-using-quark-script-api">CWE-749 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-749-py">Quark Script: CWE-749.py</a></li>
<li><a class="reference internal" href="#quark-rule-configurejsexecution-json">Quark Rule: configureJsExecution.json</a></li>
<li><a class="reference internal" href="#id14">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-532-in-android-application">Detect CWE-532 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-532-insertion-of-sensitive-information-into-log-file">CWE-532: Insertion of Sensitive Information into Log File</a></li>
<li><a class="reference internal" href="#code-of-cwe-532-in-dvba-apk">Code of CWE-532 in dvba.apk</a></li>
<li><a class="reference internal" href="#cwe-532-detection-process-using-quark-script-api">CWE-532 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-532-py">Quark Script: CWE-532.py</a></li>
<li><a class="reference internal" href="#id16">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-780-in-android-application">Detect CWE-780 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-780-use-of-rsa-algorithm-without-oaep">CWE-780 Use of RSA Algorithm without OAEP</a></li>
<li><a class="reference internal" href="#code-of-cwe-780-in-dvba-apk">Code of CWE-780 in dvba.apk</a></li>
<li><a class="reference internal" href="#cwe-780-detection-process-using-quark-script-api">CWE-780 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-780-py">Quark Script: CWE-780.py</a></li>
<li><a class="reference internal" href="#quark-rule-useofcryptographicalgo-json">Quark Rule: useOfCryptographicAlgo.json</a></li>
<li><a class="reference internal" href="#id18">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-319-in-android-application">Detect CWE-319 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-319-cleartext-transmission-of-sensitive-information">CWE-319 Cleartext Transmission of Sensitive Information</a></li>
<li><a class="reference internal" href="#code-of-cwe-319-in-ovaa-apk">Code of CWE-319 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-319-detection-process-using-quark-script-api">CWE-319 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-319-py">Quark Script: CWE-319.py</a></li>
<li><a class="reference internal" href="#quark-rule-setretrofitbaseurl-json">Quark Rule: setRetrofitBaseUrl.json</a></li>
<li><a class="reference internal" href="#id20">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-327-in-android-application">Detect CWE-327 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-327-use-of-a-broken-or-risky-cryptographic-algorithm">CWE-327 Use of a Broken or Risky Cryptographic Algorithm</a></li>
<li><a class="reference internal" href="#code-of-cwe-327-in-injuredandroid-apk">Code of CWE-327 in InjuredAndroid.apk</a></li>
<li><a class="reference internal" href="#cwe-327-detection-process-using-quark-script-api">CWE-327 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-327-py">Quark Script CWE-327.py</a></li>
<li><a class="reference internal" href="#id21">Quark Rule: useOfCryptographicAlgo.json</a></li>
<li><a class="reference internal" href="#id22">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-20-in-android-application">Detect CWE-20 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-20-improper-input-validation">CWE-20: Improper Input Validation</a></li>
<li><a class="reference internal" href="#code-of-cwe-20-in-diva-apk">Code of CWE-20 in diva.apk</a></li>
<li><a class="reference internal" href="#cwe-20-detection-process-using-quark-script-api">CWE-20 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-20-py">Quark Script CWE-20.py</a></li>
<li><a class="reference internal" href="#quark-rule-openurlthatuserinput-json">Quark Rule: openUrlThatUserInput.json</a></li>
<li><a class="reference internal" href="#id23">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-79-in-android-application">Detect CWE-79 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-79-improper-neutralization-of-input-during-web-page-generation-cross-site-scripting">CWE-79: Improper Neutralization of Input During Web Page Generation (‘Cross-site Scripting’)</a></li>
<li><a class="reference internal" href="#code-of-cwe-79-in-vuldroid-apk">Code of CWE-79 in Vuldroid.apk</a></li>
<li><a class="reference internal" href="#cwe-79-detection-process-using-quark-script-api">CWE-79 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-79-py">Quark Script CWE-79.py</a></li>
<li><a class="reference internal" href="#quark-rule-loadurlfromintent-json">Quark Rule: loadUrlFromIntent.json</a></li>
<li><a class="reference internal" href="#id24">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-328-in-android-application">Detect CWE-328 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-328-use-of-weak-hash">CWE-328 Use of Weak Hash</a></li>
<li><a class="reference internal" href="#code-of-cwe-328-in-allsafe-apk">Code of CWE-328 in allsafe.apk</a></li>
<li><a class="reference internal" href="#cwe-328-detection-process-using-quark-script-api">CWE-328 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-328-py">Quark Script: CWE-328.py</a></li>
<li><a class="reference internal" href="#id25">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-295-in-android-application">Detect CWE-295 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-295-improper-certificate-validation">CWE-295: Improper Certificate Validation</a></li>
<li><a class="reference internal" href="#code-of-cwe-295-in-insecureshop-apk">Code of CWE-295 in InsecureShop.apk</a></li>
<li><a class="reference internal" href="#cwe-295-detection-process-using-quark-script-api">CWE-295 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-295-py">Quark Script CWE-295.py</a></li>
<li><a class="reference internal" href="#id26">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-489-in-android-application">Detect CWE-489 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-489-active-debug-code">CWE-489: Active Debug Code</a></li>
<li><a class="reference internal" href="#code-of-cwe-489-in-allsafe-apk">Code of CWE-489 in allsafe.apk</a></li>
<li><a class="reference internal" href="#cwe-489-detection-process-using-quark-script-api">CWE-489 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-489-py">Quark Script CWE-489.py</a></li>
<li><a class="reference internal" href="#id28">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-22-in-android-application">Detect CWE-22 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-22-improper-limitation-of-a-pathname-to-a-restricted-directory-path-traversal">CWE-22: Improper Limitation of a Pathname to a Restricted Directory (‘Path Traversal’)</a></li>
<li><a class="reference internal" href="#code-of-cwe-22-in-ovaa-apk">Code of CWE-22 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-22-detection-process-using-quark-script-api">CWE-22 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-scipt-cwe-22-py">Quark Scipt: CWE-22.py</a></li>
<li><a class="reference internal" href="#quark-rule-accessfileinexternaldir-json">Quark Rule: accessFileInExternalDir.json</a></li>
<li><a class="reference internal" href="#id30">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-23-in-android-application">Detect CWE-23 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-23-relative-path-traversal">CWE-23: Relative Path Traversal</a></li>
<li><a class="reference internal" href="#code-of-cwe-23-in-ovaa-apk">Code of CWE-23 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-23-detection-process-using-quark-script-api">CWE-23 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-23-py">Quark Script: CWE-23.py</a></li>
<li><a class="reference internal" href="#id32">Quark Rule: accessFileInExternalDir.json</a></li>
<li><a class="reference internal" href="#id33">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-338-in-android-application">Detect CWE-338 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-338-use-of-cryptographically-weak-pseudo-random-number-generator-prng">CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)</a></li>
<li><a class="reference internal" href="#code-of-cwe-338-in-pivaa-apk">Code of CWE-338 in pivaa.apk</a></li>
<li><a class="reference internal" href="#cwe-338-detection-process-using-quark-script-api">CWE-338 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-338-py">Quark Script CWE-338.py</a></li>
<li><a class="reference internal" href="#quark-rule-usemethodofprng-json">Quark Rule: useMethodOfPRNG.json</a></li>
<li><a class="reference internal" href="#id34">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-88-in-android-application">Detect CWE-88 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-88-improper-neutralization-of-argument-delimiters-in-a-command">CWE-88 Improper Neutralization of Argument Delimiters in a Command</a></li>
<li><a class="reference internal" href="#code-of-cwe-88-in-vuldroid-apk">Code of CWE-88 in vuldroid.apk</a></li>
<li><a class="reference internal" href="#cwe-88-detection-process-using-quark-script-api">CWE-88 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-88-py">Quark Script: CWE-88.py</a></li>
<li><a class="reference internal" href="#quark-rule-externalstringcommand-json">Quark Rule: ExternalStringCommand.json</a></li>
<li><a class="reference internal" href="#id36">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-925-in-android-application">Detect CWE-925 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-925-improper-verification-of-intent-by-broadcast-receiver">CWE-925 Improper Verification of Intent by Broadcast Receiver</a></li>
<li><a class="reference internal" href="#code-of-cwe-925-in-insecurebankv2-apk">Code of CWE-925 in InsecureBankv2.apk</a></li>
<li><a class="reference internal" href="#cwe-925-detection-process-using-quark-script-api">CWE-925 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-925-py">Quark Script CWE-925.py</a></li>
<li><a class="reference internal" href="#id37">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-73-in-android-application">Detect CWE-73 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-73-external-control-of-file-name-or-path">CWE-73 External Control of File Name or Path</a></li>
<li><a class="reference internal" href="#code-of-cwe-73-in-ovaa-apk">Code of CWE-73 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-73-detection-process-using-quark-script-api">CWE-73 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-73-py">Quark Script: CWE-73.py</a></li>
<li><a class="reference internal" href="#quark-rule-uselastpathsegmentasfilename-json">Quark Rule: useLastPathSegmentAsFileName.json</a></li>
<li><a class="reference internal" href="#id39">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-78-in-android-application">Detect CWE-78 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-78-improper-neutralization-of-special-elements-used-in-an-os-command-os-command-injection">CWE-78 Improper Neutralization of Special Elements used in an OS Command (‘OS Command Injection’)</a></li>
<li><a class="reference internal" href="#code-of-cwe-78-in-vuldroid-apk">Code of CWE-78 in Vuldroid.apk</a></li>
<li><a class="reference internal" href="#cwe-78-detection-process-using-quark-script-api">CWE-78 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-78-py">Quark Script: CWE-78.py</a></li>
<li><a class="reference internal" href="#id41">Quark Rule: ExternalStringCommand.json</a></li>
<li><a class="reference internal" href="#id42">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-117-in-android-application">Detect CWE-117 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-117-improper-output-neutralization-for-logs">CWE-117: Improper Output Neutralization for Logs</a></li>
<li><a class="reference internal" href="#code-of-cwe-117-in-allsafe-apk">Code of CWE-117 in allsafe.apk</a></li>
<li><a class="reference internal" href="#cwe-117-detection-process-using-quark-script-api">CWE-117 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-117-py">Quark Script CWE-117.py</a></li>
<li><a class="reference internal" href="#quark-rule-writecontenttolog-json">Quark Rule: writeContentToLog.json</a></li>
<li><a class="reference internal" href="#id44">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-940-in-android-application">Detect CWE-940 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-940-improper-verification-of-source-of-a-communication-channel">CWE-940: Improper Verification of Source of a Communication Channel</a></li>
<li><a class="reference internal" href="#code-of-cwe-940-in-ovaa-apk">Code of CWE-940 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-940-detection-process-using-quark-script-api">CWE-940 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-940-py">Quark Script: CWE-940.py</a></li>
<li><a class="reference internal" href="#id46">Quark Rule: LoadUrlFromIntent.json</a></li>
<li><a class="reference internal" href="#id47">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-502-in-android-application">Detect CWE-502 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-502-deserialization-of-untrusted-data">CWE-502: Deserialization of Untrusted Data</a></li>
<li><a class="reference internal" href="#code-of-cwe-502-in-pivaa-apk">Code of CWE-502 in pivaa.apk</a></li>
<li><a class="reference internal" href="#cwe-502-detection-process-using-quark-script-api">CWE-502 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-502-py">Quark Script CWE-502.py</a></li>
<li><a class="reference internal" href="#quark-rule-deserializedata-json">Quark Rule: deserializeData.json</a></li>
<li><a class="reference internal" href="#id49">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-601-in-android-application">Detect CWE-601 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-601-url-redirection-to-untrusted-site-open-redirect">CWE-601: URL Redirection to Untrusted Site (‘Open Redirect’)</a></li>
<li><a class="reference internal" href="#code-of-cwe-601-in-ovaa-apk">Code of CWE-601 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-601-detection-process-using-quark-script-api">CWE-601 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-601-py">Quark Script: CWE-601.py</a></li>
<li><a class="reference internal" href="#id51">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-329-in-android-application">Detect CWE-329 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-329-generation-of-predictable-iv-with-cbc-mode">CWE-329: Generation of Predictable IV with CBC Mode</a></li>
<li><a class="reference internal" href="#code-of-cwe-329-in-insecurebankv2-apk">Code of CWE-329 in InsecureBankv2.apk</a></li>
<li><a class="reference internal" href="#cwe-329-detection-process-using-quark-script-api">CWE-329 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-329-py">Quark Script CWE-329.py</a></li>
<li><a class="reference internal" href="#quark-rule-initializecipherwithiv-json">Quark Rule: initializeCipherWithIV.json</a></li>
<li><a class="reference internal" href="#id53">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-297-in-android-application">Detect CWE-297 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-297-improper-validation-of-certificate-with-host-mismatch">CWE-297: Improper Validation of Certificate with Host Mismatch</a></li>
<li><a class="reference internal" href="#code-of-cwe-297-in-pivaa-apk">Code of CWE-297 in pivaa.apk</a></li>
<li><a class="reference internal" href="#cwe-297-detection-process-using-quark-script-api">CWE-297 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-297-py">Quark Script CWE-297.py</a></li>
<li><a class="reference internal" href="#id55">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-1204-in-android-application">Detect CWE-1204 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-1204-generation-of-weak-initialization-vector-iv">CWE-1204: Generation of Weak Initialization Vector (IV)</a></li>
<li><a class="reference internal" href="#code-of-cwe-1204-in-insecurebankv2-apk">Code of CWE-1204 in InsecureBankv2.apk</a></li>
<li><a class="reference internal" href="#cwe-1204-detection-process-using-quark-script-api">CWE-1204 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-scipt-cwe-1204-py">Quark Scipt: CWE-1204.py</a></li>
<li><a class="reference internal" href="#id57">Quark Rule: initializeCipherWithIV.json</a></li>
<li><a class="reference internal" href="#id58">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-24-in-android-application">Detect CWE-24 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-24-path-traversal-filedir">CWE-24: Path Traversal: ‘../filedir’</a></li>
<li><a class="reference internal" href="#code-of-cwe-24-in-ovaa-apk">Code of CWE-24 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-24-detection-process-using-quark-script-api">CWE-24 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-24-py">Quark Script: CWE-24.py</a></li>
<li><a class="reference internal" href="#id60">Quark Rule: accessFileInExternalDir.json</a></li>
<li><a class="reference internal" href="#id61">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-359-in-android-application">Detect CWE-359 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-359-exposure-of-private-personal-information-to-an-unauthorized-actor">CWE-359: Exposure of Private Personal Information to an Unauthorized Actor</a></li>
<li><a class="reference internal" href="#code-of-cwe-359-in-ovaa-apk">Code of CWE-359 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-359-detection-process-using-quark-script-api">CWE-359 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-359-py">Quark Script: CWE-359.py</a></li>
<li><a class="reference internal" href="#quark-rule-accessfilewithunsafeuripath-json">Quark Rule: accessFileWithUnsafeUriPath.json</a></li>
<li><a class="reference internal" href="#id63">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-256-in-android-application">Detect CWE-256 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-256-plaintext-storage-of-a-password">CWE-256: Plaintext Storage of a Password</a></li>
<li><a class="reference internal" href="#code-of-cwe-256-in-ovaa-apk">Code of CWE-256 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-256-detection-process-using-quark-script-api">CWE-256 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-256-py">Quark Script CWE-256.py</a></li>
<li><a class="reference internal" href="#quark-rule-putstrandcommit-json">Quark Rule: putStrAndCommit.json</a></li>
<li><a class="reference internal" href="#id65">Quark Script Result</a></li>
</ul>
</li>
<li><a class="reference internal" href="#detect-cwe-927-in-android-application">Detect CWE-927 in Android Application</a><ul>
<li><a class="reference internal" href="#cwe-927-use-of-implicit-intent-for-sensitive-communication">CWE-927: Use of Implicit Intent for Sensitive Communication</a></li>
<li><a class="reference internal" href="#code-of-cwe-927-in-ovaa-apk">Code of CWE-927 in ovaa.apk</a></li>
<li><a class="reference internal" href="#cwe-927-detection-process-using-quark-script-api">CWE-927 Detection Process Using Quark Script API</a></li>
<li><a class="reference internal" href="#quark-script-cwe-927-py">Quark Script CWE-927.py</a></li>
<li><a class="reference internal" href="#quark-rule-startactivitywithintent-json">Quark Rule: startActivityWithIntent.json</a></li>
<li><a class="reference internal" href="#id67">Quark Script Result</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="#">quark-script</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="#" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item active">Quark Script</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="ecosystem-for-mobile-security-tools">
<h1>Ecosystem for Mobile Security Tools<a class="headerlink" href="#ecosystem-for-mobile-security-tools" title="Link to this heading"></a></h1>
<section id="innovative-interactive">
<h2>Innovative & Interactive<a class="headerlink" href="#innovative-interactive" title="Link to this heading"></a></h2>
<p>The goal of Quark Script aims to provide an innovative way for mobile security researchers to analyze or <strong>pentest</strong> the targets.</p>
<p>Based on Quark, we integrate decent tools as Quark Script APIs and make them exchange valuable intelligence to each other. This enables security researchers to <strong>interact</strong> with staged results and perform <strong>creative</strong> analysis with Quark Script.</p>
</section>
<section id="dynamic-static-analysis">
<h2>Dynamic & Static Analysis<a class="headerlink" href="#dynamic-static-analysis" title="Link to this heading"></a></h2>
<p>In Quark script, we integrate not only static analysis tools (e.g. Quark itself) but also dynamic analysis tools (e.g. <a class="reference external" href="https://github.com/sensepost/objection">objection</a>).</p>
</section>
<section id="re-usable-sharable">
<h2>Re-Usable & Sharable<a class="headerlink" href="#re-usable-sharable" title="Link to this heading"></a></h2>
<p>Once the user creates a Quark script for specific analysis scenario. The script can be used in another targets. Also, the script can be shared to other security researchers. This enables the exchange of knowledges.</p>
</section>
<section id="more-apis-to-come">
<h2>More APIs to come<a class="headerlink" href="#more-apis-to-come" title="Link to this heading"></a></h2>
<p>Quark Script is now in a beta version. We’ll keep releasing practical APIs and analysis scenarios.</p>
</section>
</section>
<section id="quickstart">
<h1>Quickstart<a class="headerlink" href="#quickstart" title="Link to this heading"></a></h1>
<div class="line-block">
<div class="line">In this tutorial, we will learn how to install and run Quark Script with a very easy example.</div>
<div class="line">We show how to detect CWE-798 in ovaa.apk.</div>
</div>
<section id="step-1-environments-requirements">
<h2>Step 1: Environments Requirements<a class="headerlink" href="#step-1-environments-requirements" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p>Quark Script requires Python 3.10 or above.</p></li>
</ul>
</section>
<section id="step-2-install-quark-engine">
<h2>Step 2: Install Quark Engine<a class="headerlink" href="#step-2-install-quark-engine" title="Link to this heading"></a></h2>
<p>You can install Quark Engine by running:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pip3 install quark-engine
</pre></div>
</div>
</section>
<section id="step-3-prepare-quark-script-detection-rule-and-the-sample-file">
<h2>Step 3: Prepare Quark Script, Detection Rule and the Sample File<a class="headerlink" href="#step-3-prepare-quark-script-detection-rule-and-the-sample-file" title="Link to this heading"></a></h2>
<ol class="arabic simple">
<li><p>Get the CWE-798 Quark Script and the detection rule <a class="reference external" href="https://quark-engine.readthedocs.io/en/latest/quark_script.html#detect-cwe-798-in-android-application-ovaa-apk">here</a>.</p></li>
<li><p>Get the sampe file (ovaa.apk) <a class="reference external" href="https://github.com/dark-warlord14/ovaa/releases/tag/1.0">here</a>.</p></li>
<li><p>Put the script, detection rule, and sample file in the same directory.</p></li>
<li><p>Edit accordingly to the file names:</p></li>
</ol>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">SAMPLE_PATH</span> <span class="o">=</span> <span class="s2">"ovaa.apk"</span>
<span class="n">RULE_PATH</span> <span class="o">=</span> <span class="s2">"findSecretKeySpec.json"</span>
</pre></div>
</div>
<p>Now you are ready to run the script!</p>
</section>
<section id="step-4-run-the-script">
<h2>Step 4: Run the script<a class="headerlink" href="#step-4-run-the-script" title="Link to this heading"></a></h2>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ python3 CWE-798.py
</pre></div>
</div>
<p>You should now see the detection result in the terminal.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Found</span> <span class="n">hard</span><span class="o">-</span><span class="n">coded</span> <span class="n">AES</span> <span class="n">key</span> <span class="mi">49</span><span class="n">u5gh249gh24985ghf429gh4ch8f23f</span>
</pre></div>
</div>
</section>
</section>
<section id="introduce-of-quark-script-apis">
<h1>Introduce of Quark Script APIs<a class="headerlink" href="#introduce-of-quark-script-apis" title="Link to this heading"></a></h1>
<section id="findmethodinapk-samplepath-targetmethod">
<h2>findMethodInAPK(samplePath, targetMethod)<a class="headerlink" href="#findmethodinapk-samplepath-targetmethod" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find the target method in APK</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: Target file</p></li>
<li><p>targetMethod: A python list contains class name, method name, and descriptor of target method</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: Python list contains caller method instance of target method</p></li>
</ul>
</section>
<section id="checkmethodcalls-samplepath-targetmethod-checkmethods">
<h2>checkMethodCalls(samplePath, targetMethod, checkMethods)<a class="headerlink" href="#checkmethodcalls-samplepath-targetmethod-checkmethods" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check any of the specific methods shown in the target method.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: target file</p></li>
<li><p>targetMethod: python list contains the class name, method name, and descriptor of the target method or a Method Object</p></li>
<li><p>checkMethods: python list contains the class name, method name, and descriptor of the target method</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: bool that indicates if the specific methods are called or defined within a target method or not</p></li>
</ul>
</section>
<section id="findmethodimpls-samplepath-targetmethod">
<h2>findMethodImpls(samplePath, targetMethod)<a class="headerlink" href="#findmethodimpls-samplepath-targetmethod" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find all implementations of a specified method in the APK.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: target file</p></li>
<li><p>targetMethod: python list contains the class name, method name, and descriptor of the target method</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: python list contains the method implementations of the target method</p></li>
</ul>
</section>
<section id="ismethodreturnalwaystrue-samplepath-targetmethod">
<h2>isMethodReturnAlwaysTrue(samplePath, targetMethod)<a class="headerlink" href="#ismethodreturnalwaystrue-samplepath-targetmethod" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if a method always returns True.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: target file</p></li>
<li><p>targetMethod: python list contains the class name, method name, and descriptor of the target method</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="rule-rule-json">
<h2>Rule(rule.json)<a class="headerlink" href="#rule-rule-json" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Making detection rule a rule instance</p></li>
<li><p><strong>params</strong>: Path of a single Quark rule</p></li>
<li><p><strong>return</strong>: Quark rule instance</p></li>
</ul>
</section>
<section id="runquarkanalysis-sample-path-ruleinstance">
<h2>runQuarkAnalysis(SAMPLE_PATH, ruleInstance)<a class="headerlink" href="#runquarkanalysis-sample-path-ruleinstance" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Given detection rule and target sample, this instance runs the basic Quark analysis.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>SAMPLE_PATH: Target file</p></li>
<li><p>ruleInstance: Quark rule object</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: quarkResult instance</p></li>
</ul>
</section>
<section id="quarkresultinstance-behavioroccurlist">
<h2>quarkResultInstance.behaviorOccurList<a class="headerlink" href="#quarkresultinstance-behavioroccurlist" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: List that stores instances of detected behavior in different part of the target file.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: detected behavior instance</p></li>
</ul>
</section>
<section id="quarkresultinstance-getallstrings-none">
<h2>quarkResultInstance.getAllStrings(none)<a class="headerlink" href="#quarkresultinstance-getallstrings-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get all strings inside the target APK file.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing all strings inside the target APK file.</p></li>
</ul>
</section>
<section id="quarkresultinstance-ishardcoded-argument">
<h2>quarkResultInstance.isHardcoded(argument)<a class="headerlink" href="#quarkresultinstance-ishardcoded-argument" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the argument is hardcoded into the APK.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>argument: string value that is passed in when a method is invoked</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="quarkresultinstance-findmethodincaller-callermethod-targetmethod">
<h2>quarkResultInstance.findMethodInCaller(callerMethod, targetMethod)<a class="headerlink" href="#quarkresultinstance-findmethodincaller-callermethod-targetmethod" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find target method in caller method.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>callerMethod: python list contains class name, method name and descriptor of caller method.</p></li>
<li><p>targetMethod: python list contains class name, method name and descriptor of target method.</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: python list contains target method instances.</p></li>
</ul>
</section>
<section id="behaviorinstance-firstapi-fullname">
<h2>behaviorInstance.firstAPI.fullName<a class="headerlink" href="#behaviorinstance-firstapi-fullname" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Show the name of the first key API called in this behavior.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: API name</p></li>
</ul>
</section>
<section id="behaviorinstance-secondapi-fullname">
<h2>behaviorInstance.secondAPI.fullName<a class="headerlink" href="#behaviorinstance-secondapi-fullname" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Show the name of the second key API called in this behavior.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: API name</p></li>
</ul>
</section>
<section id="behaviorinstance-hasstring-pattern-isregex">
<h2>behaviorInstance.hasString(pattern, isRegex)<a class="headerlink" href="#behaviorinstance-hasstring-pattern-isregex" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the arguments of the two APIs contain the string.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>pattern: string that may appear in the arguments</p></li>
<li><p>isRegex: consider the string as a regular expression if True, defaults to False</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: the matched string</p></li>
</ul>
</section>
<section id="behaviorinstance-hasurl-none">
<h2>behaviorInstance.hasUrl(none)<a class="headerlink" href="#behaviorinstance-hasurl-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the behavior contains urls.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing all detected urls.</p></li>
</ul>
</section>
<section id="behaviorinstance-methodcaller">
<h2>behaviorInstance.methodCaller<a class="headerlink" href="#behaviorinstance-methodcaller" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find method who calls this behavior (API1 & API2).</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: method instance</p></li>
</ul>
</section>
<section id="behaviorinstance-getparamvalues-none">
<h2>behaviorInstance.getParamValues(none)<a class="headerlink" href="#behaviorinstance-getparamvalues-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get parameter values that API1 sends to API2 in the behavior.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing parameter values.</p></li>
</ul>
</section>
<section id="behaviorinstance-isargfrommethod-targetmethod">
<h2>behaviorInstance.isArgFromMethod(targetMethod)<a class="headerlink" href="#behaviorinstance-isargfrommethod-targetmethod" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if there are any arguments from the target method.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>targetMethod: python list contains class name, method name, and descriptor of target method</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="behaviorinstance-getmethodsinargs-none">
<h2>behaviorInstance.getMethodsInArgs(none)<a class="headerlink" href="#behaviorinstance-getmethodsinargs-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get the methods which the arguments in API2 has passed through.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing method instances</p></li>
</ul>
</section>
<section id="methodinstance-getxreffrom-none">
<h2>methodInstance.getXrefFrom(none)<a class="headerlink" href="#methodinstance-getxreffrom-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find out who call this method.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing caller methods.</p></li>
</ul>
</section>
<section id="methodinstance-getxrefto-none">
<h2>methodInstance.getXrefTo(none)<a class="headerlink" href="#methodinstance-getxrefto-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find out who this method called.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing tuples (callee methods, index).</p></li>
</ul>
</section>
<section id="methodinstance-getarguments-none">
<h2>methodInstance.getArguments(none)<a class="headerlink" href="#methodinstance-getarguments-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get arguments from method.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: python list containing arguments.</p></li>
</ul>
</section>
<section id="methodinstance-findsuperclasshierarchy-none">
<h2>methodInstance.findSuperclassHierarchy(none)<a class="headerlink" href="#methodinstance-findsuperclasshierarchy-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Find all superclasses of this method object.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: Python list contains all superclass names of this method.</p></li>
</ul>
</section>
<section id="objection-host">
<h2>Objection(host)<a class="headerlink" href="#objection-host" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Create an instance for Objection (dynamic analysis tool).</p></li>
<li><p><strong>params</strong>: Monitoring IP:port</p></li>
<li><p><strong>return</strong>: objection instance</p></li>
</ul>
</section>
<section id="objinstance-hookmethod-method-watchargs-watchbacktrace-watchret">
<h2>objInstance.hookMethod(method, watchArgs, watchBacktrace, watchRet)<a class="headerlink" href="#objinstance-hookmethod-method-watchargs-watchbacktrace-watchret" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Hook the target method with Objection.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>method: the target API. (type: str or method instance)</p></li>
<li><p>watchArgs: Return Args information if True. (type: boolean)</p></li>
<li><p>watchBacktrace: Return backtrace information if True. (type: boolean)</p></li>
<li><p>watchRet: Return the return information of the target API if True. (type: boolean)</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: none</p></li>
</ul>
</section>
<section id="runfridahook-apkpackagename-targetmethod-methodparamtypes-secondtowait">
<h2>runFridaHook(apkPackageName, targetMethod, methodParamTypes, secondToWait)<a class="headerlink" href="#runfridahook-apkpackagename-targetmethod-methodparamtypes-secondtowait" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Track calls to the specified method for given seconds.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>apkPackageName: the package name of the target APP</p></li>
<li><p>targetMethod: the target API</p></li>
<li><p>methodParamTypes: string that holds the parameters used by the target API</p></li>
<li><p>secondToWait: seconds to wait for method calls, defaults to 10</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: FridaResult instance</p></li>
</ul>
</section>
<section id="checkcleartext-inputstring">
<h2>checkClearText(inputString)<a class="headerlink" href="#checkcleartext-inputstring" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check the decrypted value of the input string.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>inputString: string to be checked</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: the decrypted value</p></li>
</ul>
</section>
<section id="getactivities-samplepath">
<h2>getActivities(samplePath)<a class="headerlink" href="#getactivities-samplepath" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get activities from the manifest of target sample.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: the file path of target sample</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: python list containing activities</p></li>
</ul>
</section>
<section id="activityinstance-hasintentfilter-none">
<h2>activityInstance.hasIntentFilter(none)<a class="headerlink" href="#activityinstance-hasintentfilter-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the activity has an intent-filter.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="activityinstance-isexported-none">
<h2>activityInstance.isExported(none)<a class="headerlink" href="#activityinstance-isexported-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the activity set <code class="docutils literal notranslate"><span class="pre">android:exported=true</span></code>.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="getreceivers-samplepath">
<h2>getReceivers(samplePath)<a class="headerlink" href="#getreceivers-samplepath" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get receivers from a target sample.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: target sample</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: python list containing receivers</p></li>
</ul>
</section>
<section id="receiverinstance-hasintentfilter-none">
<h2>receiverInstance.hasIntentFilter(none)<a class="headerlink" href="#receiverinstance-hasintentfilter-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the receiver has an intent-filter.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="receiverinstance-isexported-none">
<h2>receiverInstance.isExported(none)<a class="headerlink" href="#receiverinstance-isexported-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the receiver is exported.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="getapplication-samplepath">
<h2>getApplication(samplePath)<a class="headerlink" href="#getapplication-samplepath" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get the application element from the manifest file of the target sample.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: the file path of the target sample</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: the application element of the target sample</p></li>
</ul>
</section>
<section id="applicationinstance-isdebuggable-none">
<h2>applicationInstance.isDebuggable(none)<a class="headerlink" href="#applicationinstance-isdebuggable-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the application element sets <code class="docutils literal notranslate"><span class="pre">android:debuggable=true</span></code>.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
<section id="getproviders-samplepath">
<h2>getProviders(samplePath)<a class="headerlink" href="#getproviders-samplepath" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Get provider elements from the manifest file of the target sample.</p></li>
<li><dl class="simple">
<dt><strong>params</strong>:</dt><dd><ol class="arabic simple">
<li><p>samplePath: the file path of target sample</p></li>
</ol>
</dd>
</dl>
</li>
<li><p><strong>return</strong>: python list containing provider elements</p></li>
</ul>
</section>
<section id="providerinstance-isexported-none">
<h2>providerInstance.isExported(none)<a class="headerlink" href="#providerinstance-isexported-none" title="Link to this heading"></a></h2>
<ul class="simple">
<li><p><strong>Description</strong>: Check if the provider element set <code class="docutils literal notranslate"><span class="pre">android:exported=true</span></code>.</p></li>
<li><p><strong>params</strong>: none</p></li>
<li><p><strong>return</strong>: True/False</p></li>
</ul>
</section>
</section>
<section id="analyzing-real-case-instastealer-using-quark-script">
<h1>Analyzing real case (InstaStealer) using Quark Script<a class="headerlink" href="#analyzing-real-case-instastealer-using-quark-script" title="Link to this heading"></a></h1>
<section id="quark-script-that-dynamic-hooks-the-method-containing-urls">
<h2>Quark Script that dynamic hooks the method containing urls<a class="headerlink" href="#quark-script-that-dynamic-hooks-the-method-containing-urls" title="Link to this heading"></a></h2>
<p>The scenario is simple! We’d like to dynamic hooking the methods in the malware that contains urls. We can use APIs above to write Quark Script.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">quark.script</span><span class="w"> </span><span class="kn">import</span> <span class="n">runQuarkAnalysis</span><span class="p">,</span> <span class="n">Rule</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">quark.script.objection</span><span class="w"> </span><span class="kn">import</span> <span class="n">Objection</span>
<span class="n">SAMPLE_PATH</span> <span class="o">=</span> <span class="s2">"6f032.apk"</span>
<span class="n">RULE_PATH</span> <span class="o">=</span> <span class="s2">"00211.json"</span>
<span class="n">ruleInstance</span> <span class="o">=</span> <span class="n">Rule</span><span class="p">(</span><span class="n">RULE_PATH</span><span class="p">)</span>
<span class="n">quarkResult</span> <span class="o">=</span> <span class="n">runQuarkAnalysis</span><span class="p">(</span><span class="n">SAMPLE_PATH</span><span class="p">,</span> <span class="n">ruleInstance</span><span class="p">)</span>
<span class="k">for</span> <span class="n">behaviorInstance</span> <span class="ow">in</span> <span class="n">quarkResult</span><span class="o">.</span><span class="n">behaviorOccurList</span><span class="p">:</span>
<span class="n">detectedUrl</span> <span class="o">=</span> <span class="n">behaviorInstance</span><span class="o">.</span><span class="n">hasUrl</span><span class="p">()</span>
<span class="k">if</span> <span class="n">detectedUrl</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Detected Behavior -> </span><span class="si">{</span><span class="n">ruleInstance</span><span class="o">.</span><span class="n">crime</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Detected Url -> </span><span class="si">{</span><span class="n">detectedUrl</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="n">method</span> <span class="o">=</span> <span class="n">behaviorInstance</span><span class="o">.</span><span class="n">methodCaller</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="se">\n</span><span class="s2">The detected behavior was called by -> </span><span class="si">{</span><span class="n">method</span><span class="o">.</span><span class="n">fullName</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">Attempt to hook the method:"</span><span class="p">)</span>
<span class="n">obj</span> <span class="o">=</span> <span class="n">Objection</span><span class="p">(</span><span class="s2">"127.0.0.1:8888"</span><span class="p">)</span>
<span class="n">obj</span><span class="o">.</span><span class="n">hookMethod</span><span class="p">(</span><span class="n">method</span><span class="p">,</span>
<span class="n">watchArgs</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">watchBacktrace</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">watchRet</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="se">\t</span><span class="s2">Hook -> </span><span class="si">{</span><span class="n">method</span><span class="o">.</span><span class="n">fullName</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="k">for</span> <span class="n">methodCaller</span> <span class="ow">in</span> <span class="n">method</span><span class="o">.</span><span class="n">getXrefFrom</span><span class="p">():</span>
<span class="n">obj</span><span class="o">.</span><span class="n">hookMethod</span><span class="p">(</span><span class="n">methodCaller</span><span class="p">,</span>
<span class="n">watchArgs</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">watchBacktrace</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">watchRet</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="se">\t</span><span class="s2">Hook -> </span><span class="si">{</span><span class="n">methodCaller</span><span class="o">.</span><span class="n">fullName</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="k">for</span> <span class="n">methodCallee</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="n">method</span><span class="o">.</span><span class="n">getXrefTo</span><span class="p">():</span>
<span class="n">obj</span><span class="o">.</span><span class="n">hookMethod</span><span class="p">(</span><span class="n">methodCallee</span><span class="p">,</span>
<span class="n">watchArgs</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">watchBacktrace</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">watchRet</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">"</span><span class="se">\t</span><span class="s2">Hook -> </span><span class="si">{</span><span class="n">methodCallee</span><span class="o">.</span><span class="n">fullName</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">See the hook results in Objection's terminal."</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Please make sure you have the dynamic analysis environment ready before executing the script.</p>
<ol class="arabic simple">
<li><p>Objection installed and running. Check the guideline <a class="reference external" href="https://github.com/sensepost/objection/wiki/Installation">here</a>.</p></li>
<li><p>Android Virtual Machine with frida installed. Check the guideline <a class="reference external" href="https://frida.re/docs/android/">here</a>.</p></li>
<li><p>Or a rooted Android Device (Google Pixel 6) with frida installed. Check the root guideline <a class="reference external" href="https://forum.xda-developers.com/t/guide-root-pixel-6-with-magisk-android-12-1.4388733/">here</a>, frida install guideline is the <a class="reference external" href="https://frida.re/docs/android/">same</a> with Android Virtual Machine.</p></li>
</ol>
</div>
</section>
<section id="quark-script-result">
<h2>Quark Script Result<a class="headerlink" href="#quark-script-result" title="Link to this heading"></a></h2>
<img alt="https://i.imgur.com/elztZdC.png" src="https://i.imgur.com/elztZdC.png" />
</section>
<section id="logs-on-the-objection-terminal-hooking">
<h2>Logs on the Objection terminal (hooking)<a class="headerlink" href="#logs-on-the-objection-terminal-hooking" title="Link to this heading"></a></h2>
<img alt="https://i.imgur.com/XrtfgjY.jpg" src="https://i.imgur.com/XrtfgjY.jpg" />
</section>
<section id="method-callcomponentmethod-with-urls-is-detected-triggered">
<h2>Method (callComponentMethod) with urls is detected triggered!<a class="headerlink" href="#method-callcomponentmethod-with-urls-is-detected-triggered" title="Link to this heading"></a></h2>
<img alt="https://i.imgur.com/ryV3f57.jpg" src="https://i.imgur.com/ryV3f57.jpg" />
</section>
</section>
<section id="detect-cwe-798-in-android-application">
<h1>Detect CWE-798 in Android Application<a class="headerlink" href="#detect-cwe-798-in-android-application" title="Link to this heading"></a></h1>
<p>This scenario seeks to find <strong>hard-coded credentials</strong> in the APK file.</p>
<section id="cwe-798-use-of-hard-coded-credentials">
<h2>CWE-798: Use of Hard-coded Credentials<a class="headerlink" href="#cwe-798-use-of-hard-coded-credentials" title="Link to this heading"></a></h2>
<p>We analyze the definition of CWE-798 and identify its characteristics.</p>
<p>See <a class="reference external" href="https://cwe.mitre.org/data/definitions/798.html">CWE-798</a> for more details.</p>
<img alt="https://imgur.com/rF8J8hE.png" src="https://imgur.com/rF8J8hE.png" />
</section>
<section id="code-of-cwe-798-in-ovaa-apk">
<h2>Code of CWE-798 in ovaa.apk<a class="headerlink" href="#code-of-cwe-798-in-ovaa-apk" title="Link to this heading"></a></h2>
<p>We use the <a class="reference external" href="https://github.com/oversecured/ovaa">ovaa.apk</a> sample to explain the vulnerability code of CWE-798.</p>
<img alt="https://imgur.com/Cg7DacP.png" src="https://imgur.com/Cg7DacP.png" />
</section>
<section id="cwe-798-detection-process-using-quark-script-api">
<h2>CWE-798 Detection Process Using Quark Script API<a class="headerlink" href="#cwe-798-detection-process-using-quark-script-api" title="Link to this heading"></a></h2>
<img alt="https://imgur.com/R8CfDqD.png" src="https://imgur.com/R8CfDqD.png" />
<p>Let’s use the above APIs to show how the Quark script finds this vulnerability.</p>
<p>First, we design a detection rule <code class="docutils literal notranslate"><span class="pre">findSecretKeySpec.json</span></code> to spot on behavior using the constructor <code class="docutils literal notranslate"><span class="pre">SecretKeySpec</span></code>. Second, we get all the parameter values from this constructor. Then, we parse the AES key from the parameter values. Finally, we check if the AES key is hardcoded in the APK file. If the answer is <strong>YES</strong>, BINGO!!! We find hard-coded credentials in the APK file.</p>
</section>
<section id="quark-script-cwe-798-py">
<h2>Quark Script: CWE-798.py<a class="headerlink" href="#quark-script-cwe-798-py" title="Link to this heading"></a></h2>
<img alt="https://imgur.com/IOyrqDc.png" src="https://imgur.com/IOyrqDc.png" />
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">re</span>
<span class="kn">from</span><span class="w"> </span><span class="nn">quark.script</span><span class="w"> </span><span class="kn">import</span> <span class="n">runQuarkAnalysis</span><span class="p">,</span> <span class="n">Rule</span>
<span class="n">SAMPLE_PATH</span> <span class="o">=</span> <span class="s2">"ovaa.apk"</span>
<span class="n">RULE_PATH</span> <span class="o">=</span> <span class="s2">"findSecretKeySpec.json"</span>
<span class="n">ruleInstance</span> <span class="o">=</span> <span class="n">Rule</span><span class="p">(</span><span class="n">RULE_PATH</span><span class="p">)</span>
<span class="n">quarkResult</span> <span class="o">=</span> <span class="n">runQuarkAnalysis</span><span class="p">(</span><span class="n">SAMPLE_PATH</span><span class="p">,</span> <span class="n">ruleInstance</span><span class="p">)</span>
<span class="k">for</span> <span class="n">secretKeySpec</span> <span class="ow">in</span> <span class="n">quarkResult</span><span class="o">.</span><span class="n">behaviorOccurList</span><span class="p">:</span>