-
Notifications
You must be signed in to change notification settings - Fork 99
/
zeus.sh
2494 lines (1872 loc) · 56.6 KB
/
zeus.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"
}
acc1="Avoid the use of the root account."
acc2="Ensure MFA is enabled for all IAM users that have a console password."
acc3="Ensure credentials unused for 90 days or greater are disabled."
acc4="Ensure access keys are rotated every 90 days or less."
acc5="Ensure IAM password policy requires at least one uppercase letter."
acc6="Ensure IAM password policy requires at least one lowercase letter."
acc7="Ensure IAM password policy requires at least one symbol."
acc8="Ensure IAM password policy requires at least one number."
acc9="Ensure IAM password policy requires minimum length of 14 or greater."
acc12="Ensure no root account access key exist."
acc13="Ensure MFA is enabled for the root account."
acc15="Ensure security questions are registered in the AWS account."
acc16="Ensure IAM policies are attached only to groups or roles"
acc20="Ensure a support role has been created to manage incidents with AWS Support."
log1="Ensure CloudTrail is enabled in all regions:"
log2="Ensure CloudTrail log file validation is enabled:"
log3="Ensure the S3 bucket CloudTrail logs to is not publicly accessible:"
log4="Ensure CloudTrail trails are integrated with CloudWatch logs:"
log5="Ensure AWS Config is enabled in all regions:"
log6="Ensure S3 bucket access logging is enabled on the CloudTrail S3 bucket:"
log7="Ensure CloudTrail logs are encrypted at rest using KMS CMKs:"
log8="Ensure rotation for customer created CMKs is enabled:"
mon1="Ensure a log metric filter and alarm exist for unauthorized API calls."
mon2="Ensure a log metric filter and alarm exist for Management Console sign-in without MFA."
mon3="Ensure a log metric filter and alarm exist for usage of "root" account."
mon4="Ensure a log metric filter and alarm exist for IAM policy changes."
mon5="Ensure a log metric filter and alarm exist for CloudTrail configuration changes."
mon6="Ensure a log metric filter and alarm exist for AWS Management Console authentication failures."
mon7="Ensure a log metric filter and alarm exist for disabling or scheduled deletion of customer created CMKs."
mon8="Ensure a log metric filter and alarm exist for S3 bucket policy changes."
mon9="Ensure a log metric filter and alarm exist for AWS Config configuration changes."
mon10="Ensure a log metric filter and alarm exist for security group changes."
mon11="Ensure a log metric filter and alarm exist for changes to NetworkAccess Control Lists (NACL)."
mon12="Ensure a log metric filter and alarm exist for changes to network gateways."
mon13="Ensure a log metric filter and alarm exist for route table changes."
mon14="Ensure a log metric filter and alarm exist for VPC changes."
net1="Ensure no security groups allow ingress from 0.0.0.0/0 to port 22"
net2="Ensure no security groups allow ingress from 0.0.0.0/0 to port 3389"
net3="Ensure VPC flow logging is enabled in all VPCs."
hp="$(basename "$0") [-h] [-n 1] -- Zeus is a friend of DevOps/SysAdmins.
options:
-h help menu
-n 1 no ask for fixing to WARNING reports."
while getopts ':hn:' option; do
case "$option" in
h) echo "$hp"
exit
;;
n)
gr='\033[1;32m'
re='\033[1;31m'
xx='\033[0m'
yw='\033[1;33m'
bl='\033[0;34m'
show(){
printf "${!1}\n"
}
#echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
echo " ______ ______ __ __ ______"
echo " /\___ \ /\ ___\ /\ \/\ \ /\ ___\ "
echo " \/_/ /__ \ \ __\ \ \ \_\ \ \ \___ \ "
echo " /\_____\ \ \_____\ \ \_____\ \/\_____\ "
echo " \/_____/ \/_____/ \/_____/ \/_____/ "
echo -en '\n'
#echo "+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+"
echo -en '\n'
echo -e "____________________________________________"
echo -en '\n'
echo -e "${bl}AWS Auditing & Hardening Tool v1.0 ~${xx}"
echo -en '\n'
echo -e "${re}[email protected]${xx}"
echo -e "${re}twitter.com/_denizparlak${xx}"
echo -en '\n'
echo -e "Zeus starting at.." `date`
#echo -en '\n'
echo -e "____________________________________________"
echo -en '\n'
check_aws(){
type "$1" &> /dev/null
}
check_pip(){
type "$1" &> /dev/null
}
check_os(){
if [[ $OSTYPE == darwin* ]]
then
echo -e "${yw}INFO${xx}: Operating System: MacOS" | tee -a reports/reports.1
if check_pip pip ; then
echo -e "${yw}INFO{$xx}:." | tee -a reports/reports.1
else
curl -O https://bootstrap.pypa.io/get-pip.py &> /dev/null
python3 get-pip.py --user &> /dev/null
fi
if check_aws aws ; then
echo -e "${yw}INFO${xx}: AWS-CLI is installed on the system." | tee -a reports/reports.1
else
pip3 install --user --upgrade awscli &> /dev/null
fi
echo ""
elif [[ "$OSTYPE" == linux* ]]
then
echo -e "${yw}INFO${xx}: Operating System: Linux" | tee -a reports/reports.1
if check_pip pip; then
echo -e "${yw}INFO${xx}: pip is installed on the system." | tee -a reports/reports.1
else
apt install -y python-pip
fi
if check_aws aws ; then
echo -e "${yw}INFO${xx}: AWS-CLI is installed on the system." | tee -a reports/reports.1
echo -e "____________________________________________"
echo -en '\n'
else
apt install -y python-pip
fi
echo ""
fi
}
check_os
avoid_root(){
cre_rep=$(aws iam generate-credential-report)
aws iam get-credential-report --query 'Content' --output text | base64 -d | cut -d, -f1,5,11,16 > credential_reports.txt
echo -en "IAM credential report file created as 'credential_reports.txt'" | tee -a reports/reports.1
echo ""
}
show acc1
echo "Result:"
echo ""
avoid_root
echo ""
echo -e "____________________________________________"
echo -en '\n'
mfa_iam(){
aws iam get-credential-report --query 'Content' --output text | base64 -d | cut -d, -f1,4,8 > mfa_reports.txt
echo -en "MFA credential report file created as 'mfa_reports.txt'" | tee -a reports/reports.1
echo ""
}
show acc2
echo "Result:"
echo ""
mfa_iam
echo ""
echo -e "____________________________________________"
echo -en '\n'
days_90(){
rep_days=$(aws iam get-credential-report --query 'Content' --output text | base64 -d | cut -d, -f1,4,5,9,10,11,14,15,16 | awk -F "," '{print $2}' | sed -n '2p')
if [ "$rep_days" == "not_supported" ]
then
echo -e "${re}WARNING${xx}"
echo -e "Password not supported!"
else
echo -e "${gr}OK${xx}"
echo -e "Password enabled for each user!"
fi
}
show acc3
echo "Result:"
echo ""
days_90
echo ""
echo -e "____________________________________________"
echo -en '\n'
rotated_90(){
aws iam get-credential-report --query 'Content' --output text | base64 -d > access_key.log
echo -en "Access keys rotate log file created as access_key.log" | tee -a reports/reports.1
echo ""
}
show acc4
echo "Result:"
echo ""
rotated_90
echo ""
echo -e "____________________________________________"
echo -en '\n'
uppercase_iam(){
up_c=$(aws iam get-account-password-policy | grep RequireUpper | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//')
if aws iam get-account-password-policy | grep "NoSuch" || [ "$up_c" == "false" ]
then
echo -en "${re}WARNING${xx}"
echo ""
echo -en "Uppercase letter force was not setted for IAM password policy!" | tee -a reports/reports.1
else
echo -en "${gr}OK${xx}"
echo ""
echo -en "Uppercase letter force active!" | tee -a reports/reports.1
fi
}
show acc5
echo "Result:"
echo ""
uppercase_iam
echo ""
echo -e "____________________________________________"
echo -en '\n'
lowercase_iam(){
low_c=$(aws iam get-account-password-policy | grep RequireLower | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//')
if aws iam get-account-password-policy | grep "NoSuch" || [ "$low_c" == "false" ]
then
echo -en "${re}WARNING${xx}"
echo ""
echo -en "Lowercase letter force was not setted for IAM password policy!" | tee -a reports/reports.1
echo ""
else
echo -en "${gr}OK${xx}"
echo ""
echo -en "Lowercase letter force active!"
fi
}
show acc6
echo "Result:"
echo ""
lowercase_iam
echo ""
echo -e "____________________________________________"
echo -en '\n'
sym_c=$(aws iam get-account-password-policy | grep RequireSym | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e 's/^\s*//')
symbols_req(){
if aws iam get-account-password-policy | grep "NoSuch" || [ "$sym_c" == "false" ]
then
echo -en "${re}WARNING${xx}"
echo ""
echo -en "At least one symbol force was not setted for IAM password policy!" | tee -a reports/reports.1
echo ""
else
echo -en "${gr}OK${xx}"
echo ""
echo -en "At least one symbol force active!"
fi
}
show acc7
echo "Result:"
echo ""
symbols_req
echo ""
echo -e "____________________________________________"
echo -en '\n'
require_num(){
num_c=$(aws iam get-account-password-policy | grep RequireNumber | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//')
if aws iam get-account-password-policy | grep "NoSuch" || [ "$num_c" == "false" ]
then
echo -en "${re}WARNING${xx}"
echo ""
echo -en "Number force was not setted for IAM password policy!" | tee -a reports/reports.1
echo ""
else
echo -en "${gr}OK${xx}"
echo ""
echo -en "Number force active!"
fi
}
show acc8
echo "Result:"
echo ""
require_num
echo ""
echo -e "____________________________________________"
echo -en '\n'
min_len(){
min_n=$(aws iam get-account-password-policy | grep Minimum | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//')
if aws iam get-account-password-policy | grep "NoSuch" || [ "$min_n" == "6" ]
then
echo -en "${re}WARNING${xx}"
echo ""
echo -en "Required minimum length = 14"
echo ""
else
echo -en "${gr}OK${xx}"
echo ""
echo -en "Minimum number length is $min_n now."
fi
}
show acc9
echo "Result:"
echo ""
min_len
echo ""
echo -e "____________________________________________"
echo -en '\n'
###
root_access_key(){
aws iam generate-credential-report
aws iam get-credential-report --query 'Content' --output text | base64 -d | cut -d, -f1,9,14 | grep -B1 root > root_access_key.log
echo -en "Root access key log file created as root_access_key.log" | tee -a reports/reports.1
}
show acc12
echo "Result:"
echo ""
root_access_key
echo ""
echo -e "____________________________________________"
echo -en '\n'
mfa_root(){
mfa_en=$(aws iam get-account-summary | grep "AccountMFA" | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//')
if [ "$mfa_en" == "1" ]
then
echo -en "${gr}OK${xx}"
echo ""
echo -en "MFA is enabled for the root account." | tee -a reports/reports.1
else
echo -en "${re}WARNING${xx}"
echo ""
echo "MFA is disabled for the root account." | tee -a reports/reports.1
fi
}
show acc13
echo "Result:"
echo ""
mfa_root
echo ""
echo -e "____________________________________________"
echo -en '\n'
sec_ques(){
echo -en "No any command availability for check to security questions. You should visit https://console.aws.amazon.com/billing/home?#/account and check Configure Security Challenge Questions section." | tee -a reports/reports.1
}
show acc15
echo "Result:"
echo ""
sec_ques
echo ""
echo -e "____________________________________________"
echo -en '\n'
iam_policies(){
iam_users_check=$(aws iam list-users | grep Users | awk -F ":" '{print $2}' | sed -e 's/^.//')
iam_users=$(aws iam list-users | grep UserName | awk -F ":" '{print $2}' | sed 's/"//g' | sed -e 's/,//' | xargs)
attc_pol=$(aws iam list-attached-user-policies --user-name $iam_users)
pol_name=$(aws iam list-user-policies --user-name $iam_users)
if [ "$iam_users" == "[]" ]
then
echo -en "${yw}INFORMATION${xx}"
echo ""
echo -e "IAM user not found!" | tee -a reports/reports.1
else
echo -e "IAM user: $iam_users"
echo ""
if [ "$attc_pol" == "[]" ] || [ "$pol_name" == "[]" ]
then
echo -en "${gr}OK${xx}"
echo ""
echo -e "No any policy attached to IAM users." | tee -a reports/reports.1
else
echo -en "${re}WARNING${xx}"
echo ""
fi
fi
}
show acc16
echo "Result:"
echo ""
iam_policies
echo ""
echo -e "____________________________________________"
echo -en '\n'
aws_support(){
chckarn=$(aws iam list-policies --query "Policies[?PolicyName == 'AWSSupportAccess']" | grep Arn | awk -F " " '{print $2}' | sed 's/"//g' | sed 's/,//g')
chcksup=$(aws iam list-entities-for-policy --policy-arn $chckarn | grep Group | awk -F ":" {'print $2'} | sed 's/,//g' | xargs)
if [[ $chcksup == "[]" ]]
then
echo -en "${re}WARNING${xx}"
else
echo -en "${gr}OK${xx}"
echo ""
fi
}
show acc20
echo "Result:"
echo ""
aws_support
echo ""
echo -e "____________________________________________"
echo -en '\n'
detail_billing(){
echo -en "There is currently no AWS CLI support for this operation, so it is necessary to use the Management Console." | tee -a reports/reports.1
}
show acc17
echo "Result:"
echo ""
detail_billing
echo ""
echo -e "____________________________________________"
echo -en '\n'
contact_dets(){
echo -en "There is currently no AWS CLI support for this operation, so it is necessary to use the Management Console." | tee -a reports/reports.1
}
show acc19
echo "Result:"
echo ""
contact_dets
echo ""
echo -e "____________________________________________"
echo -en '\n'
contact_infs(){
echo -en "There is currently no AWS CLI support for this operation, so it is necessary to use the Management Console." | tee -a reports/reports.1
}
show acc20
echo "Result:"
echo ""
contact_infs
echo ""
echo -e "____________________________________________"
echo -en '\n'
res_acc(){
echo -en "There is currently no AWS CLI support for this operation, so it is necessary to use the Management Console." | tee -a reports/reports.1
}
show acc21
echo "Result:"
echo ""
res_acc
echo ""
echo -e "____________________________________________"
echo -en '\n'
trail_control(){
list=$(aws cloudtrail describe-trails | grep trailList | awk -F ":" '{print $2}')
e_list=" []"
trail_n=$(aws cloudtrail describe-trails | grep Name | grep -v S3 | awk -F ":" '{print $2}' | sed -e 's/^\s*//' -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//')
region_trail=$(aws cloudtrail describe-trails | egrep '*IsM*' | tr -s [:space:] | awk -F ":" '{print $2}')
f_trail=" true,"
#echo $list
#echo $e_list
fix_trail(){
aws cloudtrail update-trail --name $trail_n --is-multi-region-trail
echo -e "${gr}OK${xx}"
}
if [ "$list" == "$e_list" ]
then
echo -e "${yw}INFORMATION${xx}"
echo -e "Trail not found!" | tee -a reports/reports.1
elif [ "$region_trail" == "$f_trail" ]
then
echo -e "${gr}OK${xx}"
echo "Multi region trail is active." | tee -a reports/reports.1
else
echo -e "${re}WARNING${xx}"
echo "Trail found but multi region is not active." | tee -a reports/reports.1
echo ""
fi
}
show log1
echo "Result:"
echo ""
trail_control
echo ""
echo -e "____________________________________________"
echo -en '\n'
#fix_trail(){
trail_log_control(){
log_e=$(aws cloudtrail describe-trails | egrep '*LogFile*' | tr -s [:space:] | awk -F ":" '{print $2}' | tr -s \\n)
t_log=" true,"
f_log=" false,"
fix_log_control(){
aws cloudtrail update-trail --name $trail_n --enable-log-file-validation
}
if [ "$log_e" == "$t_log" ]
then
echo -e "${gr}OK${xx}"
echo "Log file validation is enabled." | tee -a reports/reports.1
elif [ "$log_e" == "$f_log" ]
then
echo -e "${yw}INFORMATION${xx}"
echo "Log file validation is disabled." | tee -a reports/reports.1
else
echo -e "${re}WARNING${xx}"
echo "Trail not found."
fi
}
#fix_trail_log(){
show log2
echo "Result:"
echo ""
trail_log_control
echo ""
echo -e "____________________________________________"
echo -en '\n'
s3_bucket_log(){
ct_bucket=$(aws cloudtrail describe-trails --query 'trailList[*].S3BucketName' | grep [0-9A-Z] | sed -e 's/^\s*//' -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//')
echo -en "S3 Bucket: $ct_bucket"
echo -e ""
s3_all_users=$(aws s3api get-bucket-acl --bucket $ct_bucket --query 'Grants[?Grantee.URI==`http://acs.amazonaws.com/groups/global/AllUsers`]')
if [ "$s3_all_users" == "[]" ]
then
echo -e "${gr}OK${xx}"
echo -e "No permission for everyone!"
else
echo -e "${re}WARNING${xx}"
echo -e "All users are granted!"
fi
ct_bucket_aut=$(aws s3api get-bucket-acl --bucket $ct_bucket --query 'Grants[?Grantee.URI==`http://acs.amazonaws.com/groups/global/AuthenticatedUsers`]')
if [ "$ct_bucket_aut" == "[]" ]
then
echo -e "${gr}OK${xx}"
echo -e "Authentication policy true!" | tee -a reports/reports.1
else
echo -e "${re}WARNING${xx}"
echo -e "Authenticated users are granted!" | tee -a reports/reports.1
fi
s3_bucket_policy=$(aws s3api get-bucket-policy --bucket $ct_bucket)
if [ "$s3_bucket_policy" == "[]" ]
then
echo -e "${gr}OK${xx}"
echo -e "Bucket policy is fine!" | tee -a reports/reports.1
else
echo -e "${re}WARNING${xx}"
echo -e "Bucket policy should be fix!" | tee -a reports/reports.1
fi
}
show log3
echo "Result:"
echo ""
s3_bucket_log
echo ""
echo -e "____________________________________________"
echo -en '\n'
cloudwatch(){
cdw=$(aws cloudtrail describe-trails | grep Cloud | sed -e 's/^\s*//' -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//' | sed -e 's/.$//')
if [ "$cdw" == "[]" ]
then
echo -e "${re}WARNING${xx}"
echo -e "CloudWatch is not enable!" | tee -a reports/reports.1
else
echo -e "${gr}OK${xx}"
echo -e "CloudWatch is enable!" | tee -a reports/reports.1
fi
}
show log4
echo "Result:"
echo ""
cloudwatch
echo ""
echo -e "____________________________________________"
echo -en '\n'
s3_access_log(){
bucket_log=$(aws s3api get-bucket-logging --bucket $ct_bucket)
if [ "$bucket_log" == "" ]
then
echo -e "${re}WARNING${xx}"
echo -e "S3 Bucket logging is disabled." | tee -a reports/reports.1
else
echo -e "${gr}OK${xx}"
echo -e "S3 Bucket logging is enabled." | tee -a reports/reports.1
fi
}
show log6
echo "Result:"
echo ""
s3_access_log
echo ""
echo -e "____________________________________________"
echo -en '\n'
cmk_kms(){
kms_e=$(aws cloudtrail describe-trails | grep Kms)
if [ "$kms_e" == "" ]
then
echo -e "${re}WARNING${xx}"
echo "SSE KMS is disabled!" | tee -a reports/reports.1
else
echo -e "${gr}OK${xx}"
echo "SSE KMS is enabled!" | tee -a reports/reports.1
fi
}
show log7
echo "Result:"
echo ""
cmk_kms
echo ""
echo -e "____________________________________________"
echo -en '\n'
cmk(){
key_id=$(aws kms list-keys | egrep KeyId | awk -F ":" '{print $2}' | sed -e 's/^\s*//' -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//')
kms_l=$(aws kms list-keys)
keys_e=" []"
fix_key_rotation(){
aws kms enable-key-rotation --key-id $key_id
}
if [ "$kms_l" == "$keys_e" ]
then
echo -e "${re}WARNING${xx}"
echo "Master Key not found!"
rotation_e=$(aws kms get-key-rotation-status --key-id $key_id | egrep KeyRot | awk -F ":" '{print $2}' | sed -e 's/^\s*//' -e '/^$/d')
elif [ "$rotation_s" == "false" ]
then
echo -e "${yw}INFORMATION${xx}"
echo "Key Rotation is disabled!"
else
echo -e "${gr}OK${xx}"
echo "Key rotation is enabled!"
fi
}
show log8
echo "Result:"
echo ""
cmk
echo ""
echo -e "____________________________________________"
echo -en '\n'
###
port_22(){
bl=$(aws ec2 describe-security-groups --filters Name=ip-permission.to-port,Values=22 | grep GroupName | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//')
bl_num=$(aws ec2 describe-security-groups --filters Name=ip-permission.to-port,Values=22 | grep GroupName | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//' | cat -n | awk -F " " '{print $1}' | tail -n 1 )
bl_file=$(aws ec2 describe-security-groups --filters Name=ip-permission.to-port,Values=22 | grep GroupName | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//' > allows.log)
if [[ $bl = "" ]]
then
echo -en "${gr}OK${xx}"
echo ""
echo -en "No security group has allow to port 22."
else
echo -en "${re}WARNING${xx}"
echo ""
echo -en "$bl_num security group has allow to port 22!"
echo ""
echo -en "Security groups listed on allows.log file!"
fi
}
show net1
echo "Result:"
echo ""
port_22
echo ""
echo -e "____________________________________________"
echo -en '\n'
port_3389(){
bl=$(aws ec2 describe-security-groups --filters Name=ip-permission.to-port,Values=3389 | grep GroupName | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//')
bl_num=$(aws ec2 describe-security-groups --filters Name=ip-permission.to-port,Values=3389 | grep GroupName | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//' | cat -n | awk -F " " '{print $1}' | tail -n 1 )
bl_file=$(aws ec2 describe-security-groups --filters Name=ip-permission.to-port,Values=3389 | grep GroupName | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e 's/.$//' > allows.log)
if [[ $bl = "" ]]
then
echo -en "${gr}OK${xx}"
echo ""
echo -en "No security group has allow to port 3389."
else
echo -en "${re}WARNING${xx}"
echo ""
echo -en "$bl_num security group has allow to port 3389!"
echo ""
echo -en "Security groups listed on allows.log file!"
fi
}
show net2
echo "Result:"
echo ""
port_3389
echo ""
echo -e "____________________________________________"
echo -en '\n'
flow_logs(){
log_c=$(aws ec2 describe-flow-logs | grep FlowLogId | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e '/^$/d' | sed -e 's/.$//')
aws ec2 describe-flow-logs | grep FlowLogId | awk -F ":" '{print $2}' | sed -e 's/.$//' | sed -e 's/^\s*//' | sed -e '/^$/d' | sed -e 's/^"//' | sed -e '/^$/d' | sed -e 's/.$//' > flow_log.log
if [ "$log_c" == "[]" ]
then
echo -en "${re}WARNING${xx}"
echo ""
echo -e "Flow log is not active!"
else
echo -en "${gr}OK${xx}"
echo ""
echo -e "Flow log is active."
echo -en "Flow log file is created as flow_log.log"
fi
}
show net3
echo "Result:"
echo ""
flow_logs
echo ""
echo -e "____________________________________________"
echo -en '\n'
defsecvpcfunc(){
defsecvpc=$(aws ec2 describe-security-groups --filters Name=group-name,Values='default' --query 'SecurityGroups[*].{IpPermissions:IpPermissions,IpPermissionsEgress:IpPermissionsEgress,GroupId:GroupId}')
if [ "$defsecvpc" == "[]" ]
then
echo -en "${gr}OK${xx}"
echo ""
echo -e "No any Default Security Groups open to 0.0.0.0"
else
echo -en "${re}WARNING${xx}"
echo ""
echo -e "Default Security Groups found that allow 0.0.0.0 bidirectional traffic!"
fi
}
show net4
echo "Result:"
echo ""
defsecvpcfunc
echo ""
echo -e "____________________________________________"
echo -en '\n'
unauthapi(){
ctrail_gr_name=$(aws cloudtrail describe-trails | egrep "*GroupArn" | awk -F ":" '{print $8}')
metfiln=$(aws logs describe-metric-filters --log-group-name CloudTrail/DefaultLogGroup | grep -w UnauthorizedOperation | awk -F ":*" '{print $2}' | awk -F "=" '{print $2}' | awk -F "\\" '{print $2}' | uniq | head -n 1 | sed -e 's/^"//' | sed -e 's/^*//')
if [ "$metfiln" == "UnauthorizedOperation" ]
then
echo -e "${gr}OK${xx}"
echo -e "Unauthorized authentication metric filter is enabled!"
else
echo -e "${re}WARNING${xx}"
echo -e "Unauthorized authentication metric filter is disabled!"
fi
}
show mon1
echo "Result:"
echo ""
unauthapi
echo ""
echo -e "____________________________________________"
echo -en '\n'
mfametric(){
ctrail_gr_name=$(aws cloudtrail describe-trails | egrep "*GroupArn" | awk -F ":" '{print $8}')
if aws logs describe-metric-filters --log-group-name $ctrail_gr_name | grep MFAUsed
then
echo -e "${gr}OK${xx}"
echo -e "Management Console sign-in metric filter is enabled!"
else
echo -e "${re}WARNING${xx}"
echo -e "Management Console sign-in metric filter is disabled!"
fi
}
show mon2
echo "Result:"
echo ""
mfametric
echo ""
echo -e "____________________________________________"
echo -en '\n'
rootmetrfilt(){
ctrail_gr_name=$(aws cloudtrail describe-trails | egrep "*GroupArn" | awk -F ":" '{print $8}')
if aws logs describe-metric-filters --log-group-name $ctrail_gr_name | grep userIdentity.invokedBy
then
echo -e "${gr}OK${xx}"
echo -e "A metric filter for usage of root account is enabled!"
else
echo -e "${re}WARNING${xx}"
echo -e "A metric filter for usage of root account is disabled!"
fi
}
show mon3
echo "Result:"
echo ""
rootmetrfilt
echo ""
echo -e "____________________________________________"
echo -en '\n'
iammetrfilt(){