-
Notifications
You must be signed in to change notification settings - Fork 14
/
hayat.sh
executable file
·1625 lines (1193 loc) · 36.7 KB
/
hayat.sh
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
#!/bin/bash
gr='\033[1;32m'
re='\033[1;31m'
xx='\033[0m'
yw='\033[1;33m'
bl='\033[0;34m'
show(){
printf "${!1}\n"
}
check(){
echo -en "${re} - Check: ${xx}"
}
result(){
echo -en "${re} - Result: ${xx}"
}
dash(){
echo "--------------------------------"
}
#project=$project_n
#echo "Enter the project name: "
#read -e project_n
score=0
num=2
echo -en '\n'
iam_scr(){
echo -en "${bl} # Identity and Access Management${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
log_scr(){
echo -en "${bl} # Logging and Monitoring${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
net_scr(){
echo -en "${bl} # Networking${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
vm_scr(){
echo -en "${bl} # Virtual Machines${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
sto_scr(){
echo -en "${bl} # Storage${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
sql_scr(){
echo -en "${bl} # Cloud SQL Database Services${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
k8s_scr(){
echo -en "${bl} # Kubernetes Engine${xx}"
echo -en '\n'
echo -en "--------------------------------"
echo -en '\n'
echo -en '\n'
}
iam1="Ensure that corporate login credentials are used instead of Gmail accounts."
iam3="Ensure that there are only GCP-managed service account keys for each service account."
iam4="Ensure that ServiceAccount has no Admin privileges."
iam5="Ensure that IAM users are not assigned Service Account User role at project level."
iam6="Ensure user-managed/external keys for service accounts are rotated every 90 days or less."
iam7="Ensure that Separation of duties is enforced while assigning service account related roles to users."
log2="Ensure that sinks are configured for all Log entries."
log3="Ensure that object versioning is enabled on log-buckets."
netw1="Ensure the default network does not exist in a project."
netw2="Ensure legacy networks does not exists for a project."
netw3="Ensure that DNSSEC is enabled for Cloud DNS."
netw4="Ensure that RSASHA1 is not used for key-signing key in Cloud DNS DNSSEC."
netw5="Ensure that RSASHA1 is not used for zone-signing key in Cloud DNS DNSSEC."
netw6="Ensure that SSH access is restricted from the Internet."
netw7="Ensure that SSH access is restricted from the Internet."
netw8="Ensure Private Google Access is enabled for all in VPC Network."
netw9="Ensure VPC Flow logs is enabled for every subnet in VPC Network."
vm1="Ensure that instances are not configured to use the default service account with full access to all Cloud API."
vm2="Ensure Block Project-wide SSH keys enabled for VM instances."
vm3="Ensure oslogin is enabled for a project."
vm4="Ensure Enable connecting to serial ports is not enabled for VM Instance."
vm5="Ensure that IP forwarding is not enabled on Instances."
vm6="Ensure VM disks for critical VMs are encrypted with CustomerSupplied Encryption Keys (CSEK)"
stor1="Ensure that Cloud Storage bucket is not anonymously or publicly accessible."
stor3="Ensure that logging is enabled for Cloud storage buckets."
sql1="Ensure that Cloud SQL database instance requires all incoming connections to use SSL."
sql2="Ensure that Cloud SQL database Instances are not open to the world."
sql3="Ensure that MySQL database instance does not allow anyone to connect with administrative privileges."
sql4="Ensure that MySQL Database Instance does not allows root login from any host."
k8s1="Ensure Stackdriver Logging is set to Enabled on Kubernetes Engine Clusters."
k8s2="Ensure Stackdriver Monitoring is set to Enabled on Kubernetes Engine Clusters."
k8s3="Ensure Legacy Authorization is set to Disabled on Kubernetes Engine Clusters."
k8s4="Ensure Master authorized networks is set to Enabled on Kubernetes Engine Clusters."
k8s5="Ensure Kubernetes Clusters are configured with Labels."
k8s6="Ensure Kubernetes web UI / Dashboard is disabled."
k8s7="Ensure Automatic node repair is enabled for Kubernetes Clusters."
k8s8="Ensure Automatic node upgrades is enabled on Kubernetes Engine Clusters nodes."
k8s9="Ensure Container-Optimized OS (cos) is used for Kubernetes Engine Clusters Node image."
k8s10="Ensure Basic Authentication is disabled on Kubernetes Engine Clusters."
k8s11="Ensure Network policy is enabled on Kubernetes Engine Clusters."
k8s12="Ensure Kubernetes Cluster is created with Client Certificate enabled."
k8s13="Ensure Kubernetes Cluster is created with Alias IP ranges enabled."
k8s14="Ensure PodSecurityPolicy controller is enabled on the Kubernetes Engine Clusters."
k8s15="Ensure Kubernetes Cluster is created with Private cluster enabled."
k8s16="Ensure Private Google Access is set on Kubernetes Engine Cluster Subnets."
k8s17="Ensure default Service account is not used for Project access in Kubernetes Clusters"
k8s18="Ensure Kubernetes Clusters created with limited service account Access scopes for Project access."
echo -en " ██░ ██ ▄▄▄ ▓██ ██▓ ▄▄▄ ▄▄▄█████▓ '\n'"
echo -en "▓██░ ██▒▒████▄ ▒██ ██▒▒████▄ ▓ ██▒ ▓▒ '\n'"
echo -en "▒██▀▀██░▒██ ▀█▄ ▒██ ██░▒██ ▀█▄ ▒ ▓██░ ▒░ '\n'"
echo -en "░▓█ ░██ ░██▄▄▄▄██ ░ ▐██▓░░██▄▄▄▄██░ ▓██▓ ░ '\n'"
echo -en "░▓█▒░██▓ ▓█ ▓██▒ ░ ██▒▓░ ▓█ ▓██▒ ▒██▒ ░ '\n'"
echo -en " ▒ ░░▒░▒ ▒▒ ▓▒█░ ██▒▒▒ ▒▒ ▓▒█░ ▒ ░░ '\n'"
echo -en " ▒ ░▒░ ░ ▒ ▒▒ ░▓██ ░▒░ ▒ ▒▒ ░ ░ '\n'"
echo -en " ░ ░░ ░ ░ ▒ ▒ ▒ ░░ ░ ▒ ░ '\n'"
echo -en " ░ ░ ░ ░ ░░ ░ ░ ░ '\n'"
echo -en " ░ ░ '\n'"
echo -en '\n'
echo -e "____________________________________________"
echo -en '\n'
echo -e "${bl}~ Google Cloud Platform - Auditing & Hardening Script ~${xx}"
echo -en '\n'
echo -e "${re}[email protected]${xx}"
echo -e "${re}twitter.com/_denizparlak${xx}"
echo -en '\n'
echo -e "Hayat starting at.." `date`
echo -e "____________________________________________"
echo -en '\n'
#!/bin/bash
sw=/usr/bin/sw_vers
ubuntu=$(lsb_release -a 2> /dev/null | grep Dist | awk -F ":" {'print $2'} | xargs)
rhel=/etc/redhat-release
gcloud=/usr/bin/gcloud
if [ -f $sw ]
then
echo "Operating System: MacOS X"
elif [[ $ubuntu == "Ubuntu" ]]
then
echo "Operating System: Ubuntu"
elif [ -f $rhel ]
then
echo "Operating System: RHEL"
fi
if [ ! -f $gcloud ] && [ -z "command -v gcloud" ]
then
read -p 'gcloud does not found on the system, do you want to install it? y/n' getyn
echo -en '\n'
if [[ $getyn == "y" ]] && [[ $ubuntu == "Ubuntu" ]]
then
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
apt-get install apt-transport-https ca-certificates
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update -y && sudo apt-get install google-cloud-sdk -y
elif [[ $getyn == "y" ]] && [ -f $sw]
then
curl https://sdk.cloud.google.com | bash
exec -l $SHELL
elif [[ $getyn == "y" ]] && [ -f $rhel ]
then
sudo tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-sdk]
name=Google Cloud SDK
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
yum install google-cloud-sdk -y
else
echo 1
fi
fi
cp report_template.html res.html
iam_clus(){
clus_score=0
clus_num=16
read -p 'Project name: ' project
echo -en '\n'
iam_check_gmail(){
check_mail=$(gcloud projects get-iam-policy $project | grep gmail)
mailb=$(gcloud projects get-iam-policy $project | grep gmail | awk -F ":" '{print $2}' | uniq)
if [[ $check_mail == *"gmail"* ]]
then
read ech1 < <(echo -en "Current mail: $mailb" "${re} [ Warning ]${xx}")
echo -en "Current mail: $mailb" "${re} [ Warning ]${xx}"
scoren=0
clus_score=0
else
echo -en "Current mail policy is fine." "${gr} [ OK ]${xx}"
scoren=$(( $score + num ))
clus_scoren=$(( clus_score + clus_num ))
fi
}
t1=$(echo $iam1)
iam_scr
check; show iam1
result; iam_check_gmail
echo -en '\n'
dash
echo -en '\n'
#gsed -i "s/a1/$t1/g" res.html
t2=$(echo $iam_check_gmail | awk -F "om" {'print $1'})
a2=$(echo $ech1 | tr -s ' ' | cut -d ' ' -f1,2,3)
#gsed -i "s/a2/$a2/g" res.html
#echo $iam_check_gmail
: '
if [[ $iam_check_mail == *"OK"* ]]
then
#gsed -i "s/a3/OK/g" res.html
#gsed -i "s/$t2//g" res.html | grep -A5 $t2
else
#gsed -i "s/a3/WARNING/g" res.html
#gsed -i "91s/ok/failure/g" res.html
fi
'
serv_acc_key(){
get_iam_acc=$(gcloud iam service-accounts list | awk '{print $6}' | grep @)
check_iam_acc=$(gcloud iam service-accounts keys list --iam-account=$get_iam_acc --managed-by=user 2>&1)
if [[ $check_iam_acc == *"items"* ]]
then
read ech2 < <(echo -en "Service Account has no any key." "${gr} [ OK ]${xx}")
echo -en "Service Account has no any key." "${gr} [ OK ]${xx}"
scoren2=$(( scoren + num ))
clus_scoren2=$(( clus_score + clus_num ))
else
echo -en "Service Account has a key." "${re} [ Warning ]${xx}"
scoren2=$(( scoren + 0 ))
clus_scoren2=$(( clus_score + 0 ))
fi
}
te2=$(echo $iam3)
t2=$(echo $ech2)
check; show iam3
result; serv_acc_key
echo -en '\n'
dash
echo -en '\n'
#gsed -i "s/c1/$te2/g" res.html
c2=$(echo $ech2 | tr -s ' ' | cut -d ' ' -f1,2,3,4,5,6)
: '
gsed -i "s/c2/$c2/g" res.html
if [[ $ech2 == *"OK"* ]]
then
gsed -i "s/c3/OK/g" res.html
gsed -i "103s/failure/ok/" res.html
else
gsed -i "s/c3/WARNING/g" res.html
gsed -i "103s/ok/failure/g" res.html
fi
'
iam_service_acc(){
editor_serv_accs=$(gcloud projects get-iam-policy $project | grep -A 2 service | sed '$d' | grep -B10 'editor' | grep -v members | awk '/role*/{f=1;next}/\*editor/{f=0} f')
echo $editor_serv_accs > ed.txt
if [ -s ed.txt ]
then
echo -en "These Service Accounts has Editor role.""${re} [ Warning ]${xx}"
read ech3 < <(echo -en "These Service Accounts has Editor role." "${re} [ Warning ]${xx}")
scoren3=$(( scoren2 + 0 ))
clus_scoren3=$(( clus_scoren2 + 0 ))
else
echo -en "There is no any Service Accounts with Editor role." "${gr} Ok${xx}"
scoren3=$(( scoren2 + num ))
clus_scoren3=$(( clus_scoren2 + clus_num ))
rm -f ed.txt
fi
}
t3=$(echo $iam4)
check; show iam4
result; iam_service_acc
echo -en '\n'
dash
echo -en '\n'
#gsed -i "s/d1/$t3/g" res.html
d2=$(echo $ech3 | tr -s ' ' | cut -d ' ' -f1,2,3,4,5,6)
#gsed -i "s/d2/$d2/g" res.html
: '
if [[ $ech3 == *"OK"* ]]
then
#gsed -i "s/d3/OK/g" res.html
#gsed -i "114/failure/ok/" res.html
else
#gsed -i "s/d3/WARNING/g" res.html
#gsed -i "114s/ok/failure/g" res.html
fi
'
iam_serv(){
get_iam_serv=$(gcloud projects get-iam-policy $project | grep roles | grep iam.serviceAcc)
if [[ $get_iam_serv == " " ]]
then
echo -en "IAM users are not assigned Service Account User."
scoren4=$((scoren3 + num))
clus_scoren4=$(( clus_scoren3 + clus_num ))
else
echo -en "IAM users are assigned Service Account User." "${re} [ Warning ]${xx}"
read ech4 < <(echo -en "IAM users are assigned Service Account User.")
scoren4=$((scoren3 + 0))
clus_scoren4=$(( clus_scoren3 + 0 ))
fi
}
t4=$(echo $iam5)
e2=$(echo $ech4)
check; show iam5
result; iam_serv
echo -en '\n'
dash
echo -en '\n'
90days(){
service_mail=$(gcloud iam service-accounts list | grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b")
get_date=$(gcloud iam service-accounts keys list --iam-account $service_mail --format=json | grep validAfterTime | awk -F ":" {'print $2'} | awk -F "T" {'print $1'} | sed 's/"//g' | xargs)
echo -en "Service account created date: $get_date" "${yw} [ INFO ]${xx}"
}
check; show iam6
result; 90days
echo -en '\n'
dash
echo -en '\n'
serviceadmin(){
checkadm=$(gcloud projects get-iam-policy $project | grep Admin)
if [ -z $checkadm ]
then
echo -en "Admin role does not assigned to any user." "${gr} [ OK ]${xx}"
scoren5=$((scoren4 + num))
clus_scoren5=$(( clus_scoren4 + clus_num ))
else
echo -en "${re} [ WARNING ]${xx}"
scoren5=$((scoren4 + 0))
clus_scoren5=$(( clus_scoren4 + 0 ))
fi
}
check; show iam7
result; serviceadmin
echo -en '\n'
dash
echo -en '\n'
if [ "$var" == "a" ]
then
echo "Identity and Access Management score is $clus_scoren5/100"
else
echo 1
fi
#gsed -i "s/e1/$t4/g" res.html
m2=$(echo $ech4 | tr -s ' ' | cut -d ' ' -f1,2,3,4,5,6,7)
#gsed -i "s/e2/$m2/g" res.html
: '
if [[ $ech4 == *"OK"* ]]
then
#gsed -i "s/e3/OK/g" res.html
#gsed -i "125s/failure/ok/" res.html
else
#gsed -i "s/e3/WARNING/g" res.html
#gsed -i "125s/ok/failure/" res.html
fi
'
}
: '
if [[ $1 == "iam_clus" ]]
then
iam_clus
exit 1
elif [[ $1 == "iam" ]]
exit 1
fi
'
log_clus(){
log_sink(){
check_sink=$(gcloud logging sinks list 2>&1)
echo $check_sink
if [[ $check_sink == *"0 items"* ]]
then
echo -en " No any sinks are configured for Log entries." "${re} [ Warning ]${xx}"
scoren6=$((scoren5 + 0))
else
echo -en " Sink is configured for Log entries." "${gr} Ok${xx}"
scoren6=$((scoren5 + num))
fi
}
log_scr
check; show log2
result; log_sink
echo -en '\n'
dash
echo -en '\n'
sink_vers(){
get_sink=$(gcloud logging sinks list | grep -v DES | head -n 1 | sed 's/^.*\///' | awk '{print $1}')
check_vers=$(gsutil versioning get gs://$get_sink | awk '{print $2}')
if [[ $check_vers = "Suspended" ]]
then
echo -en "Object versioning is disabled." "${re} [ Warning ]${xx}"
else
echo -en "Object versioning is enabled." "${gr} [ OK ]${xx}"
fi
}
check; show log3
result; sink_vers
echo -en '\n'
dash
echo -en '\n'
}
net_clus(){
net_default(){
check_def=$(gcloud compute networks list | grep defa | awk {'print $1'})
if [[ $check_def == *"def"* ]]
then
echo -en "The project has "default" network." "${re} [ Warning ]${xx}"
scoren7=$((scoren6 + 0))
else
echo -en "There is no any "default" network for the project." "${gr} Ok${xx}"
scoren7=$((scoren6 + num))
fi
}
net_scr
check; show netw1
result; net_default
echo -en '\n'
dash
echo -en '\n'
net_legacy(){
check_lega=$(gcloud compute networks list | grep lega | awk {'print $1'})
if [[ $check_lega == *"lega"* ]]
then
echo -en "The project has "legacy" network." "${re} Warning${xx}"
scoren8=$((scoren7 + 0))
else
echo -en "There is no any "legacy" network for the project." "${gr} [ OK ]${xx}"
scoren8=$((scoren7 + num))
fi
}
check; show netw2
result; net_legacy
echo -en '\n'
dash
echo -en '\n'
: '
net_dnssec(){
check_dnssec=$(gcloud beta dns managed-zones list | awk '{print $1}' | sed '1d')
check2=$(gcloud beta dns managed-zones describe "$check_dnssec" | grep state | awk '{print $2}')
if [[ $check_dnssec == "Listed 0 items." ]]
then
echo -en "There is no any managed zone!" "${re} [ Warning ]${xx}"
elif [[ $check2 == "on" ]]
then
echo -en "DNSSEC is enabled." "${gr} Ok${xx}"
scoren9=$((scoren8 + num))
else
echo -en "DNSSEC is disabled." "${re} [ Warning ]${xx}"
scoren9=$((scoren8 + 0))
fi
}
check; show netw3
result; net_dnssec
echo -en '\n'
dash
echo -en '\n'
'
: '
keysign_dnssec(){
check_sign=$(gcloud beta dns managed-zones describe test1 | grep -B2 keySign | grep algorithm | awk '{print $3}')
if [[ $check_sign == "rsasha1" ]]
then
echo -en "RSASHA1 is enabled for key-signing." "${re} Warning${xx}"
scoren10=$((scoren9 + 0))
else
echo -en "RSASHA1 is disabled for key-signing." "${gr} [ OK ]${xx}"
scoren10=$((scoren9 + num))
fi
}
check; show netw4
result; keysign_dnssec
echo -en '\n'
dash
echo -en '\n'
zonesign_dnssec(){
check_zsign=$(gcloud beta dns managed-zones describe test1 | grep -B2 zoneSign | grep algorithm | awk '{print $3}')
if [[ $check_zsign == "rsasha1" ]]
then
echo -en "RSASHA1 is enabled for key-signing." "${re} Warning${xx}"
scoren11=$((scoren10 + 0))
else
echo -en "RSASHA1 is disabled for key-signing." "${gr} [ OK ]${xx}"
scoren11=$((scoren10 + num))
fi
}
check; show netw5
result; zonesign_dnssec
echo -en '\n'
dash
echo -en '\n'
'
ssh_rest(){
check_generic=$(gcloud compute firewall-rules list --format=table'(name,direction,sourceRanges,allowed.ports)' | grep ssh | awk '{print $3}' | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep 0. | grep 0.0)
if [[ $check_generic == "0.0.0.0" ]]
then
echo -en "SSH traffic source 0.0.0.0" "${re} [ Warning ]${xx}"
scoren12=$((scoren11 + 0))
else
echo -en "SSH traffic source is $check_generic" "${gr} [ OK ]${xx}"
scoren12=$((scoren11 + num))
fi
}
check; show netw6
result; ssh_rest
echo -en '\n'
dash
echo -en '\n'
rdp_rest(){
check_generic2=$(gcloud compute firewall-rules list --format=table'(name,direction,sourceRanges,allowed.ports)' | grep rdp | awk '{print $3}' | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
if [[ $check_generic2 == "0.0.0.0" ]]
then
echo -en "RDP traffic source 0.0.0.0" "${re} [ Warning ]${xx}"
scoren13=$((scoren12 + 0))
else
echo -en "RDP traffic source is $check_generic2" "${gr} Ok${xx}"
scoren13=$((scoren12 + num))
fi
}
check; show netw7
result; rdp_rest
echo -en '\n'
dash
echo -en '\n'
priv_goac(){
check_goac=$(gcloud compute networks subnets describe default --region us-central1 | grep privateIp | awk '{print $2}')
if [[ $check_goac == "false" ]]
then
echo -en "Private Google Access is disabled." "${re} [ Warning ]${xx}"
scoren14=$((scoren13 + 0))
else
echo -en "Private Google Access is enabled." "${gr} Ok${xx}"
scoren14=$((scoren13 + num))
fi
}
check; show netw8
result; priv_goac
echo -en '\n'
dash
echo -en '\n'
vflow(){
check_flow=$(gcloud compute networks subnets describe default --region us-central1 --format=json | grep enableFlow | awk '{print $2}')
if [[ $check_flow == *"true"* ]]
then
echo -en "VPC Flow logs are enabled." "${gr} [ OK ]${xx}"
scoren15=$((scoren14 + num))
else
echo -en "VPC Flow logs are disabled." "${re} [ Warning ]${xx}"
scoren15=$((scoren14 + 0))
fi
}
check; show netw9
result; vflow
echo -en '\n'
dash
echo -en '\n'
}
: '
if [[ $1 == "iam_clus" ]]
then
iam_clus
exit 1
elif [[ $1 == "net_clus" ]]
then
net_clus
exit 1
else
exit 1
fi
'
vm_clus(){
#vm_check(){
read -p 'This section will check your virtual machine settings, do you want to check or pass? c/p' getcp
echo -en '\n'
if [[ $getcp == "p" ]]
then
return
else
echo 1
fi
read -p 'Instance name: ' instance
echo -en '\n'
cloudapi(){
get_current_zone=$(gcloud compute instances list --filter="name=('instance-1')" --format "value(zone)")
check_fullacc=$(gcloud compute instances describe $instance | grep -A20 scopes | grep https://www.googleapis.com | grep -v zone)
if [[ $check_fullacc == *"cloud-platform"* ]]
then
echo -en "Instance have full access to Cloud API." "${re} Warning${xx}"
scoren16=$((scoren15 + 0))
else
echo -en "Instance does not have full access to Cloud API." "${gr} [ OK ]${xx}"
scoren16=$((scoren15 + num))
fi
}
vm_scr
check; show vm1
result; cloudapi
echo -en '\n'
dash
echo -en '\n'
block_key(){
check_block_key=$(gcloud compute instances describe $instance | grep project-ssh-keys)
if [[ $check_block_key == *"true"* ]]
then
echo -en "Block Project-wide SSH Keys enabled." "${gr} Ok${xx}"
scoren17=$((scoren16 + num))
else
echo -en "Block Project-wide SSH keys disabled." "${re} [ Warning ]${xx}"
scoren17=$((scoren16 + 0))
fi
}
check; show vm2
result; block_key
echo -en '\n'
dash
echo -en '\n'
ologin(){
check_ologin=$(gcloud compute project-info describe | grep enable-oslogin | awk '{print $2}')
if [[ $check_ologin == *"true"* ]]
then
echo -en "oslogin is enabled." "${gr} Ok${xx}"
scoren18=$((scoren17 + num))
else
echo -en "oslogin is disabled." "${re} [ Warning ]${xx}"
scoren18=$((scoren17 + 0))
fi
}
check; show vm3
result; ologin
echo -en '\n'
dash
echo -en '\n'
serial_port(){
check_null=$(gcloud compute instances describe $instance --format="json(metadata.items[].key,metadata.items[].value)")
if [[ $check_null == "null" ]]
then
echo -en "Serial ports are disabled." "${gr} [ OK ]${xx}"
scoren19=$((scoren18 + num))
else
echo -en "Serial ports are enabled." "${re} Warning${xx}"
scoren19=$((scoren18 + 0))
fi
}
check; show vm4
result; serial_port
echo -en '\n'
dash
echo -en '\n'
ip_fw(){
check_ipfw=$(gcloud compute instances list --format='table(name,canIpForward)' | awk '{print $2}' | tail -n 1)
if [[ $check_ipfw == "False" ]]
then
echo -en "IP Forwarding disabled." "${gr} [ OK ]${xx}"
scoren20=$((scoren19 + num))
else
echo -en "IP Forwarding enabled." "${re} [ Warning ]${xx}"
scoren20=$((scoren19 + 0))
fi
}
check; show vm5
result; ip_fw
echo -en '\n'
dash
echo -en '\n'
csek_disk(){
disk1=$(gcloud beta compute disks list | awk -F " " {'print $1'} | grep -v NAME | head -n 1)
disk2=$(gcloud beta compute disks list | awk -F " " {'print $1'} | grep -v NAME | tail -n 1)
disk_zone=$(gcloud beta compute disks list | awk -F " " {'print $2'} | grep -v LOC | head -n 1)
checkc=$(gcloud beta compute disks describe $disk1 --zone $disk_zone --format="json(diskEncryptionKey,name)")
if [[ ! -z $checkc ]]
then
echo -en "$disk1 using CSEK" "${gr} [ OK ]${xx}"
scoren21=$((scoren20 + num))
else
echo -en "${re} [ Warning ]${xx}"
scoren21=$((scoren20 + 0))
fi
}
check; show vm6
result; csek_disk
echo -en '\n'
dash
echo -en '\n'
}
stor_clus(){
read -p 'This section will check your bucket settings, do you want to check or pass? c/p' getcpb
echo -en '\n'
if [[ $getcpb == "p" ]]
then
return
else
echo 1
fi
read -p 'Bucket name: ' bucket
echo -en '\n'
bucket_auth(){
check_bucket=$(gsutil ls)
check_bucket_iam=$(gsutil iam get "$check_bucket")
if [[ $check_bucket_iam == *"allAuthenticated"* ]]
then
echo -en "Bucket is publicly accessible." "${re} [ Warning ]${xx}"
scoren22=$((scoren21 + 0))
else
echo -en "Bucket is not anonymously." "${gr} [ OK ]${xx}"
scoren22=$((scoren21 + num))
fi
}
sto_scr
check; show stor1
result; bucket_auth
echo -en '\n'
dash
echo -en '\n'
bucket_log(){
check_blog=$(gsutil logging get $bucket)
if [[ $check_blog == *"no logging"* ]]
then
echo -en "Bucket logging is disabled." "${re} [ Warning ]${xx}"
scoren23=$((scoren22 + 0))
else
echo -en "Bucket logging is enabled." "${gr} [ OK ]${xx}"
scoren23=$((scoren22 + num))
fi
}
check; show stor3
result; bucket_log
echo -en '\n'
dash