forked from Cyber-Buddy/APKHunt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apkhunt.go
3167 lines (3023 loc) · 204 KB
/
apkhunt.go
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
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"os"
"runtime"
"os/exec"
"path/filepath"
"strings"
"regexp"
"strconv"
"time"
"crypto/md5"
"crypto/sha256"
)
var colorReset = "\033[0m"
var colorRed = "\033[31m"
var colorRedBold = "\033[1;31m"
var colorBrown = "\033[33m"
var colorBlue = "\033[34m"
var colorBlueBold = "\033[1;34m"
var colorCyan = "\033[36m"
var colorCyanBold = "\033[1;36m"
var colorPurple = "\033[1;35m"
func APKHunt_Intro_Func() {
log.SetFlags(0)
fmt.Printf(string(colorRedBold))
log.Println(`
_ _ __ __ _ __ _ _ _
/ _ \ | _ _ \| | / / | | | | | |
/ /_\ \| |_/ /| |/ / | |_| | _ _ _ _ | |_
| _ || __/ | \ | _ || | | |/ _ \| _|
| | | || | | |\ \ | | | || |_| || | | || |_
\_| |_/\_| \_| \_/ \_| |_/\ _ _ /|_| |_|\_ _|
------------------------------------------------
OWASP MASVS Static Analyzer
`)
fmt.Printf(string(colorReset))
log.Println("[+] APKHunt - a comprehensive static code analysis tool for Android apps")
log.Println("[+] Based on: OWASP MASVS - https://mobile-security.gitbook.io/masvs/")
log.Println("[+] Author: Sumit Kalaria & Mrunal Chawda")
log.Println("[*] Connect: Please do write to us for any suggestions/feedback.")
}
func APKHunt_basic_req_checks() {
// OS type check
if runtime.GOOS != "linux" {
APKHunt_Intro_Func()
fmt.Println("\n[+] Checking if APKHunt is being executed on Linux OS or not...")
fmt.Println("[!] Linux OS has not been identified! \n[!] Exiting...")
fmt.Println("\n[+] It is recommended to execute APKHunt on Kali Linux OS.")
os.Exit(0)
}
//grep/jadx/dex2jar filepath check
requiredUtilities := []string{"grep", "jadx", "d2j-dex2jar"}
for _, utility := range requiredUtilities {
_, err := exec.LookPath(utility)
if err != nil {
APKHunt_Intro_Func()
switch utility {
case "grep":
fmt.Printf("\n[!] grep utility has not been observed. \n[!] Kindly install it first! \n[!] Exiting...")
case "jadx":
fmt.Printf("\n[!] jadx decompiler has not been observed. \n[!] Kindly install it first! \n[!] Exiting...")
case "d2j-dex2jar":
fmt.Printf("\n[!] dex2jar has not been observed. \n[!] Kindly install it first! \n[!] Exiting...")
}
os.Exit(0)
}
}
}
func APKHunt_help() {
fmt.Printf(string(colorBrown))
fmt.Println("\n APKHunt Usage:")
fmt.Printf(string(colorReset))
fmt.Println("\t go run APKHunt.go [options] {.apk file}")
fmt.Printf(string(colorBrown))
fmt.Println("\n Options:")
fmt.Printf(string(colorReset))
fmt.Println("\t -h For help")
fmt.Println("\t -p Provide a single apk file-path")
fmt.Println("\t -m Provide the folder-path for multiple apk scanning")
fmt.Println("\t -l For logging (.txt file)")
fmt.Printf(string(colorBrown))
fmt.Println("\n Examples:")
fmt.Printf(string(colorReset))
fmt.Println("\t APKHunt.go -p /Downloads/android_app.apk")
fmt.Println("\t APKHunt.go -p /Downloads/android_app.apk -l")
fmt.Println("\t APKHunt.go -m /Downloads/android_apps/")
fmt.Println("\t APKHunt.go -m /Downloads/android_apps/ -l")
fmt.Printf(string(colorBrown))
fmt.Println("\n Note:")
fmt.Printf(string(colorReset))
fmt.Println("\t - Tested on linux only!")
fmt.Println("\t - Keep tools such as jadx, dex2jar, go, grep, etc.! installed")
}
func main() {
// APKHunt Intro
//APKHunt_Intro_Func()
//APKHunt basic requirement checks
APKHunt_basic_req_checks()
//taking command-line arguments
//checking arguments length
argLength := len(os.Args[1:])
if argLength == 0 {
APKHunt_Intro_Func()
fmt.Println("\n[!] Kindly provide the valid arguments/path. \n[!] Please use -h switch to know how-about the APKHunt!")
os.Exit(0)
}
//checking for the first argument
FirstArg := os.Args[1]
if FirstArg == "-h" {
APKHunt_Intro_Func()
APKHunt_help()
os.Exit(0)
}
if ((FirstArg != "-h") && (len(os.Args[2:]) == 0)) || ((FirstArg != "-p") && (len(os.Args[2:]) == 0)) || ((FirstArg != "-m") && (len(os.Args[2:]) == 0)) || ((FirstArg != "-l") && (len(os.Args[2:]) == 0)) {
APKHunt_Intro_Func()
fmt.Println("\n[!] Kindly provide the valid arguments/path. \n[!] Please use -h switch to know how-about the APKHunt!")
os.Exit(0)
}
//cheking for valid arguments/path
if ((FirstArg == "-p") && (len(os.Args[2:]) == 0)) || ((FirstArg == "-m") && (len(os.Args[2:]) == 0)) || ((FirstArg == "-l") && (len(os.Args[2:]) == 0)) || (FirstArg == "-l" && os.Args[2] == "-p" && len(os.Args[3:]) == 0) || (FirstArg == "-l" && os.Args[2] == "-m" && len(os.Args[3:]) == 0) {
APKHunt_Intro_Func()
fmt.Println("\n[!] Kindly provide the valid arguments/path. \n[!] Please use -h switch to know how-about the APKHunt!")
os.Exit(0)
}
//checking for apk path and log switches
if ((FirstArg == "-p") && (os.Args[2] != "") && (len(os.Args[3:]) == 0)) {
apkpath := os.Args[2]
log.SetFlags(0)
APKHunt_Intro_Func()
APKHunt_core(apkpath)
os.Exit(0)
}
if ((FirstArg == "-p") && (os.Args[2] != "") && (os.Args[3] == "-l")) {
apkpath := os.Args[2]
APKHunt_core_log(apkpath)
//APKHunt_Intro_Func()
APKHunt_core(apkpath)
os.Exit(0)
}
if ((FirstArg == "-l") && (os.Args[2] == "-p") && (os.Args[3] != "")) {
apkpath := os.Args[3]
//APKHunt_Intro_Func()
APKHunt_core_log(apkpath)
APKHunt_core(apkpath)
os.Exit(0)
}
//checking for multiple apks and log switches
if ((FirstArg == "-m") && (os.Args[2] != "") && (len(os.Args[3:]) == 0)) {
apkpath := os.Args[2]
log.SetFlags(0)
APKHunt_Intro_Func()
if _, err := os.Stat(apkpath); err != nil {
if os.IsNotExist(err) {
fmt.Printf("\n[!] Given file-path '%s' does not exist. \n[!] Kindly verify the path/filename! \n[!] Exiting...", apkpath)
os.Exit(0)
}
}
apkFiles := []string{}
countAPK := 0
filepath.Walk(apkpath, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(path) == ".apk" {
apkFiles = append(apkFiles, path)
countAPK++
}
return nil
})
fmt.Printf(string(colorBrown))
fmt.Printf("\n==>> Total number of APK files: %d \n\n", countAPK)
fmt.Printf(string(colorReset))
if countAPK == 0 {
fmt.Println("[!] No APK files found in the given directory. \n[!] Kindly verify the path/directory! \n[!] Exiting...")
os.Exit(0)
}
fmt.Printf(string(colorBrown))
fmt.Println("==>> List of the APK files:")
fmt.Printf(string(colorReset))
countAPKfiles := 0
for _, apkPath := range apkFiles {
countAPKfiles++
fmt.Println(" ",countAPKfiles,filepath.Base(apkPath))
}
fmt.Printf("\n")
countScanAPK := 0
for _, apkPath := range apkFiles {
countScanAPK++
fmt.Printf(string(colorBrown))
fmt.Println("==>> Scan has been started for the app:",countScanAPK,"-",filepath.Base(apkPath))
fmt.Printf(string(colorReset))
//APKHunt_core_log(apkPath)
APKHunt_core(apkPath)
}
os.Exit(0)
}
if (FirstArg == "-m" && os.Args[2] != "" && os.Args[3] == "-l") || (FirstArg == "-l" && os.Args[2] == "-m" && os.Args[3] != "") {
var apkpath string
if FirstArg == "-m" {
apkpath = os.Args[2]
} else {
apkpath = os.Args[3]
}
//APKHunt_Intro_Func()
if _, err := os.Stat(apkpath); err != nil {
if os.IsNotExist(err) {
fmt.Printf("\n[!] Given file-path '%s' does not exist. \n[!] Kindly verify the path/filename! \n[!] Exiting...", apkpath)
os.Exit(0)
}
}
apkFiles := []string{}
countAPK := 0
filepath.Walk(apkpath, func(path string, info os.FileInfo, err error) error {
if filepath.Ext(path) == ".apk" {
apkFiles = append(apkFiles, path)
countAPK++
}
return nil
})
fmt.Printf(string(colorBrown))
fmt.Printf("\n==>> Total number of APK files: %d \n\n", countAPK)
fmt.Printf(string(colorReset))
if countAPK == 0 {
fmt.Println("[!] No APK files found in the given directory. \n[!] Kindly verify the path/directory! \n[!] Exiting...")
os.Exit(0)
}
fmt.Printf(string(colorBrown))
fmt.Println("==>> List of the APK files:")
fmt.Printf(string(colorReset))
countAPKfiles := 0
for _, apkPath := range apkFiles {
countAPKfiles++
fmt.Println(" ",countAPKfiles,filepath.Base(apkPath))
}
fmt.Printf("\n")
countScanAPK := 0
for _, apkPath := range apkFiles {
countScanAPK++
fmt.Printf(string(colorBrown))
fmt.Println("==>> Scan has been started for the app:",countScanAPK,"-",filepath.Base(apkPath))
fmt.Printf(string(colorReset))
APKHunt_core_log(apkPath)
APKHunt_core(apkPath)
}
os.Exit(0)
}
}
func APKHunt_core_log(apkpath string) {
theTime := time.Now()
time_year := strconv.Itoa(theTime.Year())
time_month := strconv.Itoa(int(theTime.Month()))
time_day := strconv.Itoa(int(theTime.Day()))
time_hour := strconv.Itoa(int(theTime.Hour()))
time_minute := strconv.Itoa(int(theTime.Minute()))
time_second := strconv.Itoa(int(theTime.Second()))
ctime := time_year+"-"+time_month+"-"+time_day+"_"+time_hour+"-"+time_minute+"-"+time_second
apk_file_name := strings.TrimSuffix(filepath.Base(apkpath), filepath.Ext(filepath.Base(apkpath)))
log_file_path := filepath.Dir(apkpath)+`/APKHunt_`+apk_file_name+`_`+ctime+`.txt`
log_file, log_file_err := os.OpenFile(log_file_path, os.O_CREATE|os.O_RDWR, 0644)
if log_file_err != nil {
log.Fatal(log_file_err)
}
log.SetFlags(0)
mw := io.MultiWriter(os.Stdout, log_file)
log.SetOutput(mw)
APKHunt_Intro_Func()
log.Println("\n[+] Log-file path:",log_file_path)
//APKHunt_core(apkpath)
}
func APKHunt_core(apkpath string) {
//APK filepath check
if _, err := os.Stat(apkpath); err != nil {
if os.IsNotExist(err) {
log.Printf("\n[!] Given file-path '%s' does not exist. \n[!] Kindly verify the path/filename! \n[!] Exiting...", apkpath)
os.Exit(0)
}
}
if filepath.Ext(apkpath) != ".apk" {
log.Printf("\n[!] Given file '%s' does not seem to be an apk file. \n[!] Kindly verify the file! \n[!] Exiting...", apkpath)
os.Exit(0)
}
start_time := time.Now()
log.Println("\n[+] Scan has been started at:",start_time)
// APK filepath analysis
apkpathbase := filepath.Base(apkpath)
log.Printf("[+] APK Base: %s", apkpathbase)
file_size, err_fsize := os.Stat(apkpath)
if err_fsize != nil { log.Fatal(err_fsize) }
bytes := file_size.Size()
kilobytes := float32((bytes/1024))
megabytes := float32((kilobytes / 1024))
log.Println("[+] APK Size:", megabytes,"MB")
apkpathdir := filepath.Dir(apkpath)+"/"
log.Printf("[+] APK Directory: %s", apkpathdir)
ext := filepath.Ext(apkpathbase)
apkname := strings.TrimSuffix(apkpathbase, ext)
is_alphanumeric := regexp.MustCompile(`^[a-zA-Z0-9_-]*$`).MatchString(apkname)
if !is_alphanumeric{
log.Println("[!] Only Alphanumeric string with/without underscore/dash is accepted as APK file-name. Request you to rename the APK file.")
os.Exit(0)
}
apkoutpath := apkpathdir + apkname
dex2jarpath := apkoutpath + ".jar"
jadxpath := apkoutpath + "_SAST/"
log.Printf("[+] APK Static Analysis Path: %s\n", jadxpath)
file_hash, err_fhash := ioutil.ReadFile(apkpath)
if err_fhash != nil { log.Fatal(err_fhash) }
log.Printf("[+] APK Hash: MD5: %x\n", md5.Sum(file_hash))
log.Printf("[+] APK Hash: SHA256: %x\n", sha256.Sum256(file_hash))
fmt.Printf(string(colorBlue))
log.Println("\n[+] d2j-dex2jar has started converting APK to Java JAR file")
fmt.Printf(string(colorReset))
log.Println("[+] =======================================================")
cmd_apk_dex2jar, err := exec.Command("d2j-dex2jar", apkpath, "-f", "-o", dex2jarpath).CombinedOutput()
if err != nil {
log.Println(err.Error())
}
cmd_apk_dex2jar_output := string(cmd_apk_dex2jar[:])
log.Println(" ",cmd_apk_dex2jar_output)
fmt.Printf(string(colorBlue))
log.Println("[+] Jadx has started decompiling the application")
fmt.Printf(string(colorReset))
log.Println("[+] ============================================")
cmd_apk_jadx, err := exec.Command("jadx", "--deobf", apkpath, "-d", jadxpath).CombinedOutput()
if err != nil {
log.Println(err.Error())
}
cmd_apk_jadx_output := string(cmd_apk_jadx[:])
log.Println(cmd_apk_jadx_output)
and_manifest_path := jadxpath + "resources/AndroidManifest.xml"
fmt.Printf(string(colorBlue))
log.Println("[+] Capturing the data from the AndroidManifest file")
fmt.Printf(string(colorReset))
log.Println("[+] ================================================")
//fmt.Println(and_manifest_path)
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Basic Information...\n")
fmt.Printf(string(colorReset))
// AndroidManifest file - Package name
cmd_and_pkg_nm, err := exec.Command( "grep", "-i", "package", and_manifest_path).CombinedOutput()
if err != nil {
log.Println(" - Package Name has not been observed.")
}
cmd_and_pkg_nm_output := string(cmd_and_pkg_nm[:])
cmd_and_pkg_nm_regex := regexp.MustCompile(`package=".*?"`)
cmd_and_pkg_nm_regex_match := cmd_and_pkg_nm_regex.FindString(cmd_and_pkg_nm_output)
log.Println(" ",cmd_and_pkg_nm_regex_match)
//AndroidManifest file - Package version number
cmd_and_pkg_ver, err := exec.Command( "grep", "-i", "versionName", and_manifest_path).CombinedOutput()
if err != nil {
log.Println(" - android:versionName has not been observed.")
}
cmd_and_pkg_ver_output := string(cmd_and_pkg_ver[:])
cmd_and_pkg_ver_regex := regexp.MustCompile(`versionName=".*?"`)
cmd_and_pkg_ver_regex_match := cmd_and_pkg_ver_regex.FindString(cmd_and_pkg_ver_output)
log.Println(" ",cmd_and_pkg_ver_regex_match)
//AndroidManifest file - minSdkVersion
cmd_and_pkg_minSdkVersion, err := exec.Command( "grep", "-i", "minSdkVersion", and_manifest_path).CombinedOutput()
if err != nil {
log.Println(" - android:minSdkVersion has not been observed.")
}
cmd_and_pkg_minSdkVersion_output := string(cmd_and_pkg_minSdkVersion[:])
cmd_and_pkg_minSdkVersion_regex := regexp.MustCompile(`minSdkVersion=".*?"`)
cmd_and_pkg_minSdkVersion_regex_match := cmd_and_pkg_minSdkVersion_regex.FindString(cmd_and_pkg_minSdkVersion_output)
log.Println(" ",cmd_and_pkg_minSdkVersion_regex_match)
//AndroidManifest file - targetSdkVersion
cmd_and_pkg_targetSdkVersion, err := exec.Command( "grep", "-i", "targetSdkVersion", and_manifest_path).CombinedOutput()
if err != nil {
log.Println(" - android:targetSdkVersion has not been observed.")
}
cmd_and_pkg_targetSdkVersion_output := string(cmd_and_pkg_targetSdkVersion[:])
cmd_and_pkg_targetSdkVersion_regex := regexp.MustCompile(`targetSdkVersion=".*?"`)
cmd_and_pkg_targetSdkVersion_regex_match := cmd_and_pkg_targetSdkVersion_regex.FindString(cmd_and_pkg_targetSdkVersion_output)
log.Println(" ",cmd_and_pkg_targetSdkVersion_regex_match)
//AndroidManifest file - android:networkSecurityConfig="@xml/
cmd_and_pkg_nwSecConf, err := exec.Command( "grep", "-i", "android:networkSecurityConfig=", and_manifest_path).CombinedOutput()
if err != nil {
log.Println(" - android:networkSecurityConfig attribute has not been observed.")
}
cmd_and_pkg_nwSecConf_output := string(cmd_and_pkg_nwSecConf[:])
cmd_and_pkg_nwSecConf_regex := regexp.MustCompile(`android:networkSecurityConfig="@xml/.*?"`)
cmd_and_pkg_nwSecConf_regex_match := cmd_and_pkg_nwSecConf_regex.FindString(cmd_and_pkg_nwSecConf_output)
log.Println(" ",cmd_and_pkg_nwSecConf_regex_match)
nwSecConf_split := strings.Split(cmd_and_pkg_nwSecConf_regex_match, `android:networkSecurityConfig="@xml/`)
nwSecConf_split_join := strings.Join(nwSecConf_split," ")
nwSecConf_final_space := strings.Trim(nwSecConf_split_join,`"`)
nwSecConf_final := strings.Trim(nwSecConf_final_space,` `)
// AndroidManifest file - Activities
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Activities...\n")
fmt.Printf(string(colorReset))
cmd_and_actv, err := exec.Command("grep", "-ne", "<activity", and_manifest_path).CombinedOutput()
if err != nil {
log.Println("- No activities have been observed")
}
cmd_and_actv_output := string(cmd_and_actv[:])
log.Println(cmd_and_actv_output)
// AndroidManifest file - Exported Activities
exp_actv1 := `grep -ne '<activity' `
exp_actv2 := ` | grep -e 'android:exported="true"'`
exp_actv := exp_actv1+and_manifest_path+exp_actv2
log.Printf("[+] Looking for the Exported Activities specifically...\n\n")
cmd_and_exp_actv, err := exec.Command("bash", "-c", exp_actv).CombinedOutput()
if err != nil {
log.Printf("\t- No exported activities have been observed.")
}
cmd_and_exp_actv_output := string(cmd_and_exp_actv[:])
log.Println(cmd_and_exp_actv_output)
cmd_and_exp_actv_output_count := strings.Count(cmd_and_exp_actv_output, `android:exported="true"`)
log.Println(" > Total exported activities are:", cmd_and_exp_actv_output_count)
log.Printf("\n > QuickNote: It is recommended to use exported activities securely, if observed.\n")
// AndroidManifest file - Content Providers
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Content Providers...\n")
fmt.Printf(string(colorReset))
cmd_and_cont, err := exec.Command("grep", "-ne", "<provider", and_manifest_path).CombinedOutput()
if err != nil {
log.Println("\t- No Content Providers have been observed")
}
cmd_and_cont_output := string(cmd_and_cont[:])
log.Println(cmd_and_cont_output)
// AndroidManifest file - Exported Content Providers
exp_cont1 := `grep -ne '<provider' `
exp_cont2 := ` | grep -e 'android:exported="true"'`
exp_cont := exp_cont1+and_manifest_path+exp_cont2
log.Printf("[+] Looking for the Exported Content Providers specifically...\n\n")
cmd_and_exp_cont, err := exec.Command("bash", "-c", exp_cont).CombinedOutput()
if err != nil {
log.Printf("\t- No exported Content Providers have been observed.")
}
cmd_and_exp_cont_output := string(cmd_and_exp_cont[:])
log.Println(cmd_and_exp_cont_output)
cmd_and_exp_cont_output_count := strings.Count(cmd_and_exp_cont_output, `android:exported="true"`)
log.Println(" > Total exported Content Providers are:", cmd_and_exp_cont_output_count)
log.Printf("\n > QuickNote: It is recommended to use exported Content Providers securely, if observed.\n")
// AndroidManifest file - Brodcast Receivers
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Brodcast Receivers...\n")
fmt.Printf(string(colorReset))
cmd_and_brod, err := exec.Command("grep", "-ne", "<receiver", and_manifest_path).CombinedOutput()
if err != nil {
log.Println("\t- No Brodcast Receivers have been observed.")
}
cmd_and_brod_output := string(cmd_and_brod[:])
log.Println(cmd_and_brod_output)
// AndroidManifest file - Exported Brodcast Receivers
exp_brod1 := `grep -ne '<receiver' `
exp_brod2 := ` | grep -e 'android:exported="true"'`
exp_brod := exp_brod1+and_manifest_path+exp_brod2
log.Printf("[+] Looking for the Exported Brodcast Receivers specifically...\n\n")
cmd_and_exp_brod, err := exec.Command("bash", "-c", exp_brod).CombinedOutput()
if err != nil {
log.Printf("\t- No exported Brodcast Receivers have been observed.")
}
cmd_and_exp_brod_output := string(cmd_and_exp_brod[:])
log.Println(cmd_and_exp_brod_output)
cmd_and_exp_brod_output_count := strings.Count(cmd_and_exp_brod_output, `android:exported="true"`)
log.Println(" > Total exported Brodcast Receivers are:", cmd_and_exp_brod_output_count)
log.Printf("\n > QuickNote: It is recommended to use exported Brodcast Receivers securely, if observed.\n")
// AndroidManifest file - Services
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Services...\n")
fmt.Printf(string(colorReset))
cmd_and_serv, err := exec.Command("grep", "-ne", "<service", and_manifest_path).CombinedOutput()
if err != nil {
log.Println("\t- No Services have been observed.")
}
cmd_and_serv_output := string(cmd_and_serv[:])
log.Println(cmd_and_serv_output)
// AndroidManifest file - Exported Services
exp_serv1 := `grep -ne '<service' `
exp_serv2 := ` | grep -e 'android:exported="true"'`
exp_serv := exp_serv1+and_manifest_path+exp_serv2
log.Printf("[+] Looking for the Exported Services specifically...\n\n")
cmd_and_exp_serv, err := exec.Command("bash", "-c", exp_serv).CombinedOutput()
if err != nil {
log.Printf("\t- No exported Services have been observed.")
}
cmd_and_exp_serv_output := string(cmd_and_exp_serv[:])
log.Println(cmd_and_exp_serv_output)
cmd_and_exp_serv_output_count := strings.Count(cmd_and_exp_serv_output, `android:exported="true"`)
log.Println(" > Total exported Services are:", cmd_and_exp_serv_output_count)
log.Printf("\n > QuickNote: It is recommended to use exported Services securely, if observed.\n")
// AndroidManifest file - Intent Filters
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Intents Filters...\n")
fmt.Printf(string(colorReset))
cmd_and_intentFilters, err := exec.Command("grep", "-ne", "android.intent.", and_manifest_path).CombinedOutput()
if err != nil {
log.Println("\t- No Intents Filters have been observed.")
}
cmd_and_intentFilters_output := string(cmd_and_intentFilters[:])
log.Println(cmd_and_intentFilters_output)
log.Printf(" > QuickNote: It is recommended to use Intent Filters securely, if observed.\n")
// APK Component Summary
fmt.Printf(string(colorBrown))
log.Println("\n==>> APK Component Summary")
fmt.Printf(string(colorReset))
log.Println("[+] --------------------------------")
log.Println(" Exported Activities:", cmd_and_exp_actv_output_count)
log.Println(" Exported Content Providers:", cmd_and_exp_cont_output_count)
log.Println(" Exported Broadcast Receivers:", cmd_and_exp_brod_output_count)
log.Println(" Exported Services:", cmd_and_exp_serv_output_count)
// SAST - Recursive file reading
globpath := jadxpath+"sources/"
globpath_res := jadxpath+"resources/"
log.Printf("\n")
fmt.Printf(string(colorCyanBold))
log.Println(`[+] Let's start the static assessment based on "OWASP MASVS"`)
fmt.Printf(string(colorReset))
fmt.Println("[+] ========================================================")
// Read .java files - /sources folder
var files []string
err_globpath := filepath.Walk(globpath, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err_globpath != nil {
panic(err_globpath)
}
// Read .xml files - /resources folder
var files_res []string
err_globpath_res := filepath.Walk(globpath_res, func(path string, info os.FileInfo, err error) error {
files_res = append(files_res, path)
return nil
})
if err_globpath_res != nil {
panic(err_globpath_res)
}
// OWASP MASVS - V2: Data Storage and Privacy Requirements
log.Printf("\n")
fmt.Printf(string(colorBlueBold))
log.Println(`[+] Hunting begins based on "V2: Data Storage and Privacy Requirements"`)
fmt.Printf(string(colorReset))
log.Println("[+] -------------------------------------------------------------------")
// MASVS V2 - MSTG-STORAGE-2 - Shared Preferences
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Shared Preferences related instances...\n")
fmt.Printf(string(colorReset))
var countSharedPref = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_getSharedPreferences, err := exec.Command("grep", "-nr", "-F", "getSharedPreferences(", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Shared Preferences instances have not been observed.")
}
cmd_and_pkg_getSharedPreferences_output := string(cmd_and_pkg_getSharedPreferences[:])
if (strings.Contains(cmd_and_pkg_getSharedPreferences_output,"getSharedPreferences")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_getSharedPreferences_output)
countSharedPref++
}
}
}
//fmt.Println(int(countSharedPref))
if (int(countSharedPref) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended to use shared preferences appropriately, if observed. Please note that, Misuse of the SharedPreferences API can often lead to the exposure of sensitive data. MODE_WORLD_READABLE allows all applications to access and read the file contents. Applications compiled with an android:targetSdkVersion value less than 17 may be affected, if they run on an OS version that was released before Android 4.2 (API level 17).")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-922: Insecure Storage of Sensitive Information")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-2 - SQLite Database
fmt.Printf(string(colorPurple))
log.Println("\n==>> The SQLite Database Storage related instances...\n")
fmt.Printf(string(colorReset))
var countSqliteDb = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_sqlitedatbase, err := exec.Command("grep", "-nr", "-e", "openOrCreateDatabase", "-e", "getWritableDatabase", "-e", "getReadableDatabase", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Storage instances of SQLite Database has not been observed")
}
cmd_and_pkg_sqlitedatbase_output := string(cmd_and_pkg_sqlitedatbase[:])
if (strings.Contains(cmd_and_pkg_sqlitedatbase_output,"openOrCreateDatabase")) || (strings.Contains(cmd_and_pkg_sqlitedatbase_output,"getWritableDatabase")) || (strings.Contains(cmd_and_pkg_sqlitedatbase_output,"getReadableDatabase")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_sqlitedatbase_output)
countSqliteDb++
}
}
}
if (int(countSqliteDb) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that sensitive data should not be stored in unencrypted SQLite databases, if observed. Please note that, SQLite databases should be password-encrypted.")
fmt.Printf(string(colorCyan))
log.Println("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-922: Insecure Storage of Sensitive Information")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-2 - Firebase Database
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Firebase Database instances...\n")
fmt.Printf(string(colorReset))
var countFireDB = 0
for _, sources_file := range files_res {
if filepath.Ext(sources_file) == ".xml" {
cmd_and_pkg_firebase, err := exec.Command("grep", "-nr", "-F", ".firebaseio.com", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Firebase Database instances have not been observed")
}
cmd_and_pkg_firebase_output := string(cmd_and_pkg_firebase[:])
if (strings.Contains(cmd_and_pkg_firebase_output,"firebaseio")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_firebase_output)
countFireDB++
}
}
}
if (int(countFireDB) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that Firebase Realtime database instances should not be misconfigured, if observed. Please note that, An attacker can read the content of the database without any authentication, if rules are set to allow open access or access is not restricted to specific users for specific data sets.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-200: Exposure of Sensitive Information to an Unauthorized Actor")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-2 - Realm Database
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Realm Database instances...\n")
fmt.Printf(string(colorReset))
var countRealmDB = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_realm, err := exec.Command("grep", "-nr", "-e", "RealmConfiguration", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Firebase Database instances have not been observed")
}
cmd_and_pkg_realm_output := string(cmd_and_pkg_realm[:])
if (strings.Contains(cmd_and_pkg_realm_output,"RealmConfiguration")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_realm_output)
countRealmDB++
}
}
}
if (int(countRealmDB) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that Realm database instances should not be misconfigured, if observed. Please note that, the database and its contents have been encrypted with a key stored in the configuration file.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-200: Exposure of Sensitive Information to an Unauthorized Actor")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-2 - Internal Storage
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Internal Storage related instances...\n")
fmt.Printf(string(colorReset))
var countIntStorage = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_internalStorage, err := exec.Command("grep", "-nr", "-e", "openFileOutput", "-e", "MODE_WORLD_READABLE", "-e", "MODE_WORLD_WRITEABLE", "-e", "FileInputStream", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Internal Storage has not been observed")
}
cmd_and_pkg_internalStorage_output := string(cmd_and_pkg_internalStorage[:])
if (strings.Contains(cmd_and_pkg_internalStorage_output,"MODE_WORLD_READABLE")) || (strings.Contains(cmd_and_pkg_internalStorage_output,"MODE_WORLD_WRITEABLE")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
if (strings.Contains(cmd_and_pkg_internalStorage_output,"openFileOutput")) || (strings.Contains(cmd_and_pkg_internalStorage_output,"FileInputStream")) || (strings.Contains(cmd_and_pkg_internalStorage_output,"MODE_WORLD_READABLE")) || (strings.Contains(cmd_and_pkg_internalStorage_output,"MODE_WORLD_WRITEABLE")) {
log.Println(cmd_and_pkg_internalStorage_output)
countIntStorage++
}
}
}
}
if (int(countIntStorage) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that sensitive files saved to the internal storage should not be accessed by other application, if observed. Please note that, Modes such as MODE_WORLD_READABLE and MODE_WORLD_WRITEABLE may pose a security risk.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-922: Insecure Storage of Sensitive Information")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-2 - External Storage
fmt.Printf(string(colorPurple))
log.Println("\n==>> The External Storage related instances...\n")
fmt.Printf(string(colorReset))
var countExtStorage = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_externalStorage, err := exec.Command("grep", "-nr", "-e", "getExternalFilesDir", "-e", "getExternalFilesDirs", "-e", "getExternalCacheDir", "-e", "getExternalCacheDirs", "-e", "getCacheDir", "-e", "getExternalStorageState", "-e", "getExternalStorageDirectory", "-e", "getExternalStoragePublicDirectory", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- External Storage has not been observed")
}
cmd_and_pkg_externalStorage_output := string(cmd_and_pkg_externalStorage[:])
if (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalFilesDirs(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalFilesDirs(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalCacheDir(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalFilesDirs(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getCacheDir(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalStorageState(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalStorageDirectory(")) || (strings.Contains(cmd_and_pkg_externalStorage_output,"getExternalStoragePublicDirectory(")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_externalStorage_output)
countExtStorage++
}
}
}
if (int(countExtStorage) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that any sensitive data should not be stored in the external storage, if observed. Please note that, Files saved to external storage are world-readable and it can be used by an attacker to allow for arbitrary control of the application in some scenarios.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-922: Insecure Storage of Sensitive Information")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-2 - Temporary File Creation
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Temporary File Creation instances...\n")
fmt.Printf(string(colorReset))
var countTempFile = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_tempFile, err := exec.Command("grep", "-nr", "-F", ".createTempFile(", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Temporary File Creation instances have not been observed")
}
cmd_and_pkg_tempFile_output := string(cmd_and_pkg_tempFile[:])
if (strings.Contains(cmd_and_pkg_tempFile_output,".createTempFile(")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_tempFile_output)
countTempFile++
}
}
}
if (int(countTempFile) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that the temporary files should be securely deleted upon their usage, if observed. Please note that, Creating and using insecure temporary files can leave application and system data vulnerable to attack.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-2 | CWE-277: Insecure Inherited Permissions")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-PLATFORM-2 - Local Storage - Input Validation
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Local Storage - Input Validation...\n")
fmt.Printf(string(colorReset))
var countSharedPrefEd = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_sharedPreferencesEditor, err := exec.Command("grep", "-nr", "-F", "SharedPreferences.Editor", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Local Storage - Input Validation has not been observed")
}
cmd_and_pkg_sharedPreferencesEditor_output := string(cmd_and_pkg_sharedPreferencesEditor[:])
if (strings.Contains(cmd_and_pkg_sharedPreferencesEditor_output,"SharedPreferences.Editor")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_sharedPreferencesEditor_output)
countSharedPrefEd++
}
}
}
if (int(countSharedPrefEd) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that input validation needs to be applied on the sensitive data the moment it is read back again, if observed. Please note that, Any process can override the data for any publicly accessible data storage.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-PLATFORM-2 | CWE-922: Insecure Storage of Sensitive Information")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x11-v6-interaction_with_the_environment")
}
// MASVS V2 - MSTG-STORAGE-3 - Logs for Sensitive Data
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Information Leaks via Logs...\n")
fmt.Printf(string(colorReset))
var countLogs = 0
var countLogs2 = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_logs, err := exec.Command("grep", "-nr", "-e", "Log.v(", "-e", "Log.d(", "-e", "Log.i(", "-e", "Log.w(", "-e", "Log.e(", "-e", "logger.log(", "-e", "logger.logp(", "-e", "log.info", "-e", "System.out.print", "-e", "System.err.print", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Logs have not been observed")
}
cmd_and_pkg_logs_output := string(cmd_and_pkg_logs[:])
if (strings.Contains(cmd_and_pkg_logs_output,"Log.v(")) || (strings.Contains(cmd_and_pkg_logs_output,"Log.d(")) || (strings.Contains(cmd_and_pkg_logs_output,"Log.i(")) ||(strings.Contains(cmd_and_pkg_logs_output,"Log.w(")) || (strings.Contains(cmd_and_pkg_logs_output,"Log.e(")) || (strings.Contains(cmd_and_pkg_logs_output,"logger.log(")) || (strings.Contains(cmd_and_pkg_logs_output,"logger.logp(")) || (strings.Contains(cmd_and_pkg_logs_output,"log.info")) || (strings.Contains(cmd_and_pkg_logs_output,"System.out.print")) || (strings.Contains(cmd_and_pkg_logs_output,"System.err.print")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_logs_output)
countLogs++
countLogs2 = countLogs2 + strings.Count(cmd_and_pkg_logs_output,"\n")
}
}
}
if (int(countLogs) > 0) {
log.Println("[+] Total file sources are:", countLogs, "& its total instances are:", countLogs2,"\n")
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that any sensitive data should not be part of the log's output or revealed into Stacktraces, if observed.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-3 | CWE-532: Insertion of Sensitive Information into Log File")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-4 - NotificationManager
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Push Notification instances...\n")
fmt.Printf(string(colorReset))
var countNotiManag = 0
for _, sources_file := range files {
if filepath.Ext(sources_file) == ".java" {
cmd_and_pkg_notificationManager, err := exec.Command("grep", "-nr", "-e", "NotificationManager", "-e", `\.setContentTitle(`, "-e", `\.setContentText(`, sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- NotificationManager has not been observed")
}
cmd_and_pkg_notificationManager_output := string(cmd_and_pkg_notificationManager[:])
if (strings.Contains(cmd_and_pkg_notificationManager_output,"setContentTitle")) || (strings.Contains(cmd_and_pkg_notificationManager_output,"setContentText")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
if (strings.Contains(cmd_and_pkg_notificationManager_output,"NotificationManager")) || (strings.Contains(cmd_and_pkg_notificationManager_output,"setContentTitle")) || (strings.Contains(cmd_and_pkg_notificationManager_output,"setContentText")) {
//fmt.Println(sources_file,"\n",cmd_and_pkg_notificationManager_output)
log.Println(cmd_and_pkg_notificationManager_output)
countNotiManag++
}
}
}
}
if (int(countNotiManag) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended that any sensitive data should not be notified via the push notifications, if observed. Please note that, It would be necessary to understand how the application is generating the notifications and which data ends up being shown.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-4 | CWE-829: Inclusion of Functionality from Untrusted Control Sphere")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-5 - Keyboard Cache
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Keyboard Cache instances...\n")
fmt.Printf(string(colorReset))
var countKeyCache = 0
for _, sources_file := range files_res {
if filepath.Ext(sources_file) == ".xml" {
cmd_and_pkg_keyboardCache, err := exec.Command("grep", "-nr", "-e", ":inputType=", sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Keyboard Cache has not been observed")
}
cmd_and_pkg_keyboardCache_output := string(cmd_and_pkg_keyboardCache[:])
if (strings.Contains(cmd_and_pkg_keyboardCache_output,"textAutoComplete")) || (strings.Contains(cmd_and_pkg_keyboardCache_output,"textAutoCorrect")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_keyboardCache_output)
countKeyCache++
}
}
}
if (int(countKeyCache) > 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(" - It is recommended to set the android input type as textNoSuggestions for any sensitive data, if observed.")
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-5 | CWE-524: Use of Cache Containing Sensitive Information")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
// MASVS V2 - MSTG-STORAGE-7 - Sensitive Data Disclosure Through the User Interface
fmt.Printf(string(colorPurple))
log.Println("\n==>> The Sensitive Data Disclosure through the User Interface...\n")
fmt.Printf(string(colorReset))
var countInputType = 0
for _, sources_file := range files_res {
if filepath.Ext(sources_file) == ".xml" {
cmd_and_pkg_inputType, err := exec.Command("grep", "-nri", "-e", `:inputType="textPassword"`, sources_file).CombinedOutput()
if err != nil {
//fmt.Println("- Sensitive Data Disclosure Through the User Interface has not been observed")
}
cmd_and_pkg_inputType_output := string(cmd_and_pkg_inputType[:])
if (strings.Contains(cmd_and_pkg_inputType_output,":inputType=")) {
fmt.Printf(string(colorBrown))
log.Println(sources_file)
fmt.Printf(string(colorReset))
log.Println(cmd_and_pkg_inputType_output)
countInputType++
}
}
}
if (int(countInputType) == 0) {
fmt.Printf(string(colorCyan))
log.Printf("[!] QuickNote:")
fmt.Printf(string(colorReset))
log.Printf(` - It is recommended not to disclose any sensitive data such as password, card details, etc. in the clear-text format via User Interface. Make sure that the application is masking sensitive user input by using the inputType="textPassword" attribute. It is useful to mitigate risks such as shoulder surfing.`)
fmt.Printf(string(colorCyan))
log.Printf("\n[*] Reference:")
fmt.Printf(string(colorReset))
log.Printf(" - OWASP MASVS: MSTG-STORAGE-7 | CWE-359: Exposure of Private Personal Information to an Unauthorized Actor")
log.Printf(" - https://mobile-security.gitbook.io/masvs/security-requirements/0x07-v2-data_storage_and_privacy_requirements")
}
if (int(countInputType) > 0) {