-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcentos7_cis_benchmark-2.1.1.sh
executable file
·2174 lines (1982 loc) · 79.2 KB
/
centos7_cis_benchmark-2.1.1.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
###############################
# CIS Benchmark CentOS 7 v2.1.1
###############################
CIS_LEVEL=1
INCLUDE_UNSCORED=0
WIDTH=79
if [ $CIS_LEVEL -gt 1 ];then
RESULT_FIELD=10
else
RESULT_FIELD=6
fi
MSG_FIELD=$(($WIDTH - $RESULT_FIELD))
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
NC=$(tput sgr0)
PASSED_CHECKS=0
FAILED_CHECKS=0
function header() {
local HEADING=$1
local TEXT=$((${#HEADING}+2))
local LBAR=5
local RBAR=$(($WIDTH - $TEXT - $LBAR))
echo ""
for (( x=0; x < $LBAR; x++));do
printf %s '#'
done
echo -n " $HEADING "
for (( x=0; x < $RBAR; x++));do
printf %s '#'
done
echo ""
}
function msg() {
printf "%-${MSG_FIELD}s" " - ${1}"
}
function success_result() {
PASSED_CHECKS=$((PASSED_CHECKS+1))
local RESULT="$GREEN${1:-PASSED}$NC"
printf "%-${RESULT_FIELD}s\n" $RESULT
}
function failed_result() {
FAILED_CHECKS=$((FAILED_CHECKS+1))
local RESULT="$RED${1:-FAILED}$NC"
printf "%-${RESULT_FIELD}s\n" $RESULT
}
function warning_result() {
local RESULT="$YELLOW${1:-NOT CHECKED}$NC"
printf "%-${RESULT_FIELD}s\n" $RESULT
}
function check_retval_eq_0() {
RETVAL=$1
if [ $RETVAL -eq 0 ]; then
success_result
else
failed_result
fi
}
function check_retval_ne_0() {
RETVAL=$1
if [ $RETVAL -ne 0 ]; then
success_result
else
failed_result
fi
}
#################
# 1 Initial Setup
#################
##############################
# 1.1 Filesystem Configuration
##############################
##################################
# 1.1.1 Disable Unused Filesystems
##################################
let i=0
for module in cramfs freevxfs jffs2 hfs hfsplus squashfs udf vfat;do
i=$((i+1))
header "1.1.1.${i} $module disabled"
MODPROBE_COMMAND="modprobe -n -v $module"
LSMOD_COMMAND="lsmod | grep $module"
msg " $MODPROBE_COMMAND"
if [[ $(eval $MODPROBE_COMMAND 2>&1) =~ install.*/bin/true ]];then
LEVEL1_PASSED=$(($LEVEL1_PASSED + 1))
success_result
else
LEVEL1_FAILED=$(($LEVEL1_FAILED + 1))
failed_result
fi
msg " $LSMOD_COMMAND"
if [[ $(eval $LSMOD_COMMAND 2>&1) =~ ^$ ]];then
success_result
else
failed_result
fi
done
##################################
# 1.1.2 - 1.1.5 /tmp setup
##################################
if [ $CIS_LEVEL -gt 1 ];then
FURTHER_TMP_CHECKS=1
header "1.1.2 /tmp on own partition"
msg " mount | grep /tmp"
mount | grep ^/tmp 2>&1 > /dev/null
check_retval_eq_0 $?
if [ $FURTHER_TMP_CHECKS -gt 0 ];then
let tmp=2
for option in nodev nosuid noexec;do
tmp=$((tmp+1))
header "1.1.${tmp} Ensure $option mount option set on /tmp"
msg " mount | grep /tmp | grep $option"
mount | grep ^/tmp | grep $option 2>&1 > /dev/null
check_retval_eq_0 $?
done
fi
fi
##################################
# 1.1.6 /var setup
##################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.1.6 /var on own partition"
msg " mount | grep /var"
mount | grep ^/var 2>&1 > /dev/null
check_retval_eq_0 $?
fi
##################################
# 1.1.7 /var/tmp setup
##################################
if [ $CIS_LEVEL -gt 1 ];then
FURTHER_VAR_TMP_CHECKS=1
header "1.1.7 /var/tmp on own partition"
msg " mount | grep /var/tmp"
mount | grep ^/var/tmp 2>&1 > /dev/null
if [ $? -eq 0 ];then
success_result
else
FURTHER_VAR_TMP_CHECKS=0
failed_result
fi
if [ $FURTHER_VAR_TMP_CHECKS -gt 0 ];then
let tmp=7
for option in nodev nosuid noexec;do
tmp=$((tmp+1))
header "1.1.${tmp} Ensure $option mount option set on /var/tmp"
msg " mount | grep /var/tmp | grep $option"
mount | grep ^/var/tmp | grep $option 2>&1 > /dev/null
check_retval_eq_0 $?
done
fi
fi
##################################
# 1.1.11 /var/log setup
##################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.1.11 /var/log on own partition"
msg " mount | grep /var/log"
mount | grep ^/var/log 2>&1 > /dev/null
check_retval_eq_0 $?
fi
##################################
# 1.1.12 /var/log/audit setup
##################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.1.12 /var/log/audit on own partition"
msg " mount | grep /var/log/audit"
mount | grep ^/var/log/audit 2>&1 > /dev/null
check_retval_eq_0 $?
fi
##################################
# 1.1.13 /home setup
##################################
if [ $CIS_LEVEL -gt 1 ];then
FURTHER_HOME_CHECKS=1
header "1.1.13 /home on own partition"
msg " mount | grep /home"
mount | grep -w /home 2>&1 > /dev/null
check_retval_eq_0 $?
if [ $FURTHER_HOME_CHECKS -gt 0 ];then
let tmp=13
for option in nodev;do
tmp=$((tmp+1))
header "1.1.${tmp} Ensure $option mount option set on /home"
msg " mount | grep /home | grep $option"
mount | grep ^/home | grep $option 2>&1 > /dev/null
check_retval_eq_0 $?
done
fi
fi
##################################
# 1.1.15 /dev/shm setup
##################################
let tmp=14
for option in nodev nosuid noexec;do
tmp=$((tmp+1))
header "1.1.${tmp} Ensure $option mount option set on /dev/shm"
msg " mount | grep /dev/shm | grep $option"
mount | grep -w /dev/shm | grep $option 2>&1 > /dev/null
check_retval_eq_0 $?
done
##################################
# 1.1.18 - 1.1.20 removable media
##################################
if [ $INCLUDE_UNSCORED -gt 0 ];then
header "1.1.18 - 1.1.20 removable media setup"
printf "%50s"
warning_result
fi
##################################
# 1.1.21 Sticky Bit Set
##################################
header "1.1.21 Sticky bit on world-writable dirs"
msg
df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null
check_retval_eq_0 $?
##################################
# 1.1.22 autofs Disabled
##################################
header "1.1.22 Ensure autofs is disabled"
msg " systemctl is-enabled autofs"
if ! [[ $(systemctl is-enabled autofs 2>&1) =~ ^enabled$ ]];then
success_result
else
failed_result
fi
################################
# 1.2 Configure Software Updates
################################
#######################################
# 1.2.1 Ensure yum repos are configured
#######################################
if [ $INCLUDE_UNSCORED -gt 0 ];then
header "1.2.1 Ensure yum repos are configured"
msg " yum repolist"
warning_result
fi
#######################################
# 1.2.2 Ensure GPG Keys are configured
#######################################
if [ $INCLUDE_UNSCORED -gt 0 ];then
header "1.2.1 Ensure gpg keys are configured"
msg " rpm -q gpg-pubkey"
warning_result
fi
########################################
# 1.2.3 Ensure gpgcheck enabled globally
########################################
header "1.2.3 Ensure gpgcheck enabled"
msg " grep ^gpgcheck /etc/yum.conf"
if [[ $(grep ^gpgcheck /etc/yum.conf) =~ gpgcheck=1 ]];then
success_result
else
failed_result
fi
msg " grep ^gpgcheck /etc/yum.repos.d/*"
if [ $(grep ^gpgcheck /etc/yum.repos.d/* | grep -v gpgcheck=1 | wc -l) -eq 0 ];then
success_result
else
failed_result
fi
################################
# 1.3 Filesystem Integrity Check
################################
#######################################
# 1.3.1 Ensure aide installed
#######################################
header "1.3.1 aide installed"
msg " rpm -q aide"
rpm -q aide 2>&1 > /dev/null
check_retval_eq_0 $?
#######################################
# 1.3.2 Ensure aide cron exists
#######################################
header "1.3.2 aide cron installed"
msg
grep -r aide /etc/cron.* /etc/crontab 2>&1 > /dev/null
check_retval_eq_0 $?
################################
# 1.4 Secure Boot Settings
################################
##############################################################
# 1.4.1 Ensure permissions on bootloader config are configured
##############################################################
header "1.4.1 Check bootlader filesystem permissions"
msg " Ensure bootloader permissions are 0600 root:root"
if [[ $(stat /boot/grub2/grub.cfg) =~ Access:.*(0600/-rw-------).*Uid:.*(.*0/.*root).*Gid:.*(.*0/.*root) ]];then
success_result
else
failed_result
fi
#########################################
# 1.4.2 Ensure bootloader password is set
#########################################
header "1.4.2 Ensure bootloader password is set"
msg ' grep "^set superusers" /boot/grub2/grub.cfg'
grep "^set superusers" /boot/grub2/grub.cfg 2>&1 > /dev/null
check_retval_eq_0 $?
msg ' grep "^password" /boot/grub2/grub.cfg'
grep "^password" /boot/grub2/grub.cfg 2>&1 > /dev/null
check_retval_eq_0 $?
#################################################
# 1.4.3 Ensure auth required for single user mode
#################################################
if [ $INCLUDE_UNSCORED -gt 0 ];then
header "1.4.3 Ensure auth required for single user mode"
msg
warning_result
fi
##################################
# 1.5 Additional Process Hardening
##################################
########################################
# 1.5.1 Ensure core dumps are restricted
########################################
header "1.5.1 Ensure core dumps are restricted"
msg 'grep "hard core" /etc/security/limits.conf'
grep "hard core" /etc/security/limits.conf /etc/security/limits.d/* 2>&1 > /dev/null
check_retval_eq_0 $?
msg ' sysctl fs.suid_dumpable'
if [[ "$(sysctl fs.suid_dumpable)" == "fs.suid_dumpable = 0" ]];then
success_result
else
failed_result
fi
#######################################
# 1.5.2 Ensure XD/NX support is enabled
#######################################
header "1.5.2 Ensure XD/NX support is enabled"
msg 'cat /proc/cpuinfo | grep ^flags | grep -Ewi "nx|xd"'
cat /proc/cpuinfo | grep ^flags | grep -Ewi "nx|xd" 2>&1 > /dev/null
check_retval_eq_0 $?
###################################################################
# 1.5.3 Ensure address space layout randomization (ASLR) is enabled
###################################################################
header "1.5.3 Ensure ASLR is enabled"
msg 'sysctl kernel.randomize_va_space'
if [[ "$(sysctl kernel.randomize_va_space)" == "kernel.randomize_va_space = 2" ]];then
success_result
else
failed_result
fi
##################################
# 1.5.4 Ensure prelink is disabled
##################################
header "1.5.4 Ensure prelink is disabled"
msg 'rpm -q prelink'
if [[ "$(rpm -q prelink)" == "package prelink is not installed" ]];then
success_result
else
failed_result
fi
##############################
# 1.6 Mandatory Access Control
##############################
#########################
# 1.6.1 Configure SELinux
#########################
######################################################
# 1.6.1.1 Ensure SELinux is not disabled by bootloader
######################################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.1.1 Ensure SELinux is not disabled by bootloader"
msg ' grep "^\s*linux" /boot/grub2/grub.cfg'
grep "^\s*linux" /boot/grub2/grub.cfg | grep -E "selinux=0|enforcing=0" 2>&1 > /dev/null
check_retval_ne_0 $?
fi
###############################################
# 1.6.1.2 Ensure the SELinux state is enforcing
###############################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.1.2 Ensure the SELinux state is enforcing"
msg ' grep SELINUX=enforcing /etc/selinux/config'
grep SELINUX=enforcing /etc/selinux/config 2>&1 > /dev/null
check_retval_eq_0 $?
fi
###############################################
# 1.6.1.3 Ensure SELinux policy is configured
###############################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.1.3 Ensure SELinux policy is configured"
msg ' grep SELINUXTYPE=targeted /etc/selinux/config'
grep SELINUXTYPE=targeted /etc/selinux/config 2>&1 > /dev/null
check_retval_eq_0 $?
fi
################################################
# 1.6.1.4 Ensure SETroubleshoot is not installed
################################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.1.4 Ensure SETroubleshoot is not installed"
msg ' rpm -q setroubleshoot'
if [[ "$(rpm -q setroubleshoot)" == "package setroubleshoot is not installed" ]];then
success_result
else
failed_result
fi
fi
##########################################
# 1.6.1.5 Ensure mcstrans is not installed
##########################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.1.5 Ensure mcstrans is not installed"
msg ' rpm -q mcstrans'
if [[ "$(rpm -q mcstrans)" == "package mcstrans is not installed" ]];then
success_result
else
failed_result
fi
fi
############################################
# 1.6.1.6 Ensure no unconfiged daemons exist
############################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.1.6 Ensure no unconfined daemons exist"
msg ' Check for no unconfigured daemons'
if [[ $(ps -eZ | egrep "initrc" | egrep -vw "tr|ps|egrep|bash|awk" | tr ':' ' ' | awk '{ print $NF }') =~ ^$ ]];then
success_result
else
failed_result
fi
fi
###################################
# 1.6.2 Ensure SELinux is Installed
###################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.6.2 Ensure SELinux is Installed"
msg ' rpm -q libselinux'
rpm -q libselinux 2>&1 > /dev/null
check_retval_eq_0 $?
fi
#####################
# 1.7 Warning Banners
#####################
####################################
# 1.7.1 Command Line Warning Banners
####################################
##########################################################
# 1.7.1.1 Ensure message of the day is configured properly
##########################################################
header "1.7.1.1 Ensure /etc/motd is configured"
msg " egrep '(\\v|\\r|\\m|\\s)' /etc/motd"
egrep '(\\v|\\r|\\m|\\s)' /etc/motd 2>&1 > /dev/null
check_retval_ne_0 $?
##########################################################
# 1.7.1.2 Ensure local login warning banner is configured
##########################################################
header "1.7.1.2 Ensure local login warning banner conf"
msg " egrep '(\\v|\\r|\\m|\\s)' /etc/issue"
egrep '(\\v|\\r|\\m|\\s)' /etc/issue 2>&1 > /dev/null
check_retval_ne_0 $?
##########################################################
# 1.7.1.3 Ensure remote login warning banner is configured
##########################################################
header "1.7.1.3 Ensure remote login warning banner conf"
msg " egrep '(\\v|\\r|\\m|\\s)' /etc/issue.net"
egrep '(\\v|\\r|\\m|\\s)' /etc/issue.net 2>&1 > /dev/null
check_retval_ne_0 $?
##########################################################
# 1.7.1.4 Ensure permissions on /etc/motd are configured
##########################################################
header "1.7.1.4 Ensure permissions on /etc/motd"
msg " Ensure /etc/motd permissions are 0644 root:root"
if [[ $(stat /etc/motd) =~ Access:.*(0644/-rw-r--r--).*Uid:.*(.*0/.*root).*Gid:.*(.*0/.*root) ]];then
success_result
else
failed_result
fi
##########################################################
# 1.7.1.5 Ensure permissions on /etc/issue are configured
##########################################################
header "1.7.1.5 Ensure permissions on /etc/issue"
msg " Ensure /etc/issue permissions are 0644 root:root"
if [[ $(stat /etc/issue) =~ Access:.*(0644/-rw-r--r--).*Uid:.*(.*0/.*root).*Gid:.*(.*0/.*root) ]];then
success_result
else
failed_result
fi
#############################################################
# 1.7.1.6 Ensure permissions on /etc/issue.net are configured
#############################################################
if [ $CIS_LEVEL -gt 1 ];then
header "1.7.1.6 Ensure permissions on /etc/issue.net"
msg " Ensure /etc/issue.net permissions are 0644 root:root"
if [[ $(stat /etc/issue.net) =~ Access:.*(0644/-rw-r--r--).*Uid:.*(.*0/.*root).*Gid:.*(.*0/.*root) ]];then
success_result
else
failed_result
fi
fi
#############################################
# 1.7.2 Ensure GDM login banner is configured
#############################################
header "1.7.2 Ensure GDM login banner is configured"
rpm -q gdm 2>&1 > /dev/null
if [ $? -ne 0 ];then
msg ' gdm not even installed'
success_result
else
msg ' Checking GDM conf'
[[ $(grep "user-db:user" /etc/dconf/profile/gdm) ]] && \
[[ $(grep "system-db:gdm" /etc/dconf/profile/gdm) ]] && \
[[ $(grep "file-db:/usr/share/gdm/greeter-dconf-defaults" /etc/dconf/profile/gdm) ]] && \
success_result || \
failed_result
fi
#############################################################################
# 1.8 Ensure updates, patches, and additional security software are installed
#############################################################################
header "1.8 Ensure all updates are installed"
msg "yum check-update"
yum check-update --exclude=epel-release 2>&1 > /dev/null
check_retval_eq_0 $?
############
# 2 Services
############
#####################
# 2.1 Inetd services
#####################
ENABLED_SERVICES=$(systemctl list-unit-files | awk '($2 == "enabled") {print $0}')
header "2.1.1 - 2.1.7 Ensure inetd services diabled"
for service in chargen-dgram chargen-stream daytime-dgram daytime-stream discard-dgram discard-stream echo-dgram echo-stream time-dgram time-stream tftp xinetd;do
msg "$service"
echo $ENABLED_SERVICES | grep $service 2>&1 > /dev/null
check_retval_ne_0 $?
done
##############################
# 2.2 Special Purpose Services
##############################
#################################
# 2.2.1.1 Ensure time sync in use
#################################
header "2.2.1.1 Ensure time sync enabled and configured"
msg "Check if ntpd/chrony installed"
rpm -qa | grep -Ew "ntp|chrony" 2>&1 > /dev/null
check_retval_eq_0 $?
if [ "$(rpm -q ntp)" != "package ntp is not installed" ];then
header "2.2.1.2 Ensure ntp is configured"
msg 'grep "^restrict" /etc/ntp.conf'
grep "^restrict" /etc/ntp.conf 2>&1 > /dev/null
check_retval_eq_0 $?
msg "grep "^server" /etc/ntp.conf"
grep "^server" /etc/ntp.conf 2>&1 > /dev/null
check_retval_eq_0 $?
msg 'grep "^OPTIONS" /etc/sysconfig/ntpd'
grep "^OPTIONS" /etc/sysconfig/ntpd | grep "\-u ntp:ntp" 2>&1 > /dev/null
check_retval_eq_0 $?
else
header "2.2.1.3 Ensure chrony is configured"
msg 'grep "^server" /etc/chrony.conf'
check_retval_eq_0 $?
msg 'grep ^OPTIONS /etc/sysconfig/chronyd'
grep ^OPTIONS /etc/sysconfig/chronyd | grep "\-u chrony" 2>&1 > /dev/null
check_retval_eq_0 $?
fi
###############################################
# 2.2.2 Ensure X Window System is not installed
###############################################
header "2.2.2 Ensure X Window System is not installed"
msg "rpm -qa xorg-x11*"
if [ $(rpm -qa xorg-x11* | wc -l) -eq 0 ];then
success_result
else
failed_result
fi
####################################################
# 2.2.3 - 2.2.14 Ensure Unneeded Servers not enabled
####################################################
header "2.2.3 - 2.2.21 Ensure Following services are not enabled"
for service in avahi-daemoncups dhcpd slapd nfs rpcbind named vsftpd httpd dovecot smb squid snmpd ypserv rsh.socket rlogin.socket rexec.socket telnet.socket tftp.socket rsyncd ntalk;do
msg "$service"
check_output="$(systemctl is-enabled $service 2>&1)"
if [ "$check_output" == "disabled" -o "$check_output" == "indirect" ];then
success_result
else
if [[ $check_output =~ Failed.*to.*get.*unit.*file.*state.*for.* ]];then
success_result
else
failed_result
fi
fi
done
###################################################
# 2.2.15 Ensure MTA Configured for local-only mode
###################################################
header "2.2.15 Ensure MTA Configured for local-only mode"
msg 'netstat -an | grep LISTEN | grep ":25[[:space:]]"'
netstat -an | grep LISTEN | grep ":25[[:space:]]" | grep -vE "127.0.0.1|::1" 2>&1 > /dev/null
check_retval_ne_0 $?
#####################
# 2.3 Service Clients
#####################
#############################################
# 2.3.1 - 2.3.5 Ensure clients not installed
#############################################
header "2.3.1 - 2.3.5 Ensure following clients not installed"
for client in ypbind rsh talk telnet openldap-clients;do
msg "$client"
rpm -q $client 2>&1 > /dev/null
check_retval_ne_0 $?
done
#########################
# 3 Network Configuration
#########################
####################################
# 3.1 Network Parameters (Host Only)
####################################
#####################################
# 3.1.1 Esnure IP Forwarding disabled
#####################################
header "3.1.1 Ensure IP forwarding disabled"
msg "sysctl net.ipv4.ip_forward"
sysctl net.ipv4.ip_forward 2>&1 > /dev/null
if [[ "$(sysctl net.ipv4.ip_forward)" == "net.ipv4.ip_forward = 0" ]];then
success_result
else
failed_result
fi
##################################################
# 3.1.2 Ensure packet redirect sending is disabled
##################################################
header "3.1.2 Ensure packet redirect sending is disabled"
msg "sysctl net.ipv4.conf.all.send_redirects"
sysctl net.ipv4.conf.all.send_redirects 2>&1 > /dev/null
if [[ "$(sysctl net.ipv4.conf.all.send_redirects)" == "net.ipv4.conf.all.send_redirects = 0" ]];then
success_result
else
failed_result
fi
msg "sysctl net.ipv4.conf.default.send_redirects"
sysctl net.ipv4.conf.default.send_redirects 2>&1 > /dev/null
if [[ "$(sysctl net.ipv4.conf.default.send_redirects)" == "net.ipv4.conf.default.send_redirects = 0" ]];then
success_result
else
failed_result
fi
##########################################
# 3.2 Network Parameters (Host and Router)
##########################################
####################################################
# 3.2.1 Ensure source routed packets aren't accepted
####################################################
header "3.2.1 Ensure source routed packets aren't accepted"
msg "sysctl net.ipv4.conf.all.accept_source_route"
if [[ "$(sysctl net.ipv4.conf.all.accept_source_route)" == "net.ipv4.conf.all.accept_source_route = 0" ]];then
success_result
else
failed_result
fi
msg "sysctl net.ipv4.conf.default.accept_source_route"
if [[ "$(sysctl net.ipv4.conf.default.accept_source_route)" == "net.ipv4.conf.default.accept_source_route = 0" ]];then
success_result
else
failed_result
fi
##############################################
# 3.2.2 Ensure ICMP redirects are not accepted
##############################################
header "3.2.2 Ensure ICMP redirects are not accepted"
msg "sysctl net.ipv4.conf.all.accept_redirects"
if [[ "$(sysctl net.ipv4.conf.all.accept_redirects)" == "net.ipv4.conf.all.accept_redirects = 0" ]];then
success_result
else
failed_result
fi
msg "sysctl net.ipv4.conf.default.accept_redirects"
if [[ "$(sysctl net.ipv4.conf.default.accept_redirects)" == "net.ipv4.conf.default.accept_redirects = 0" ]];then
success_result
else
failed_result
fi
#####################################################
# 3.2.3 Ensure secure ICMP redirects are not accepted
#####################################################
header "3.2.3 Ensure secure ICMP redirects are not accepted"
msg "sysctl net.ipv4.conf.all.secure_redirects"
if [[ "$(sysctl net.ipv4.conf.all.secure_redirects)" == "net.ipv4.conf.all.secure_redirects = 0" ]];then
success_result
else
failed_result
fi
############################################
# 3.2.4 Ensure suspicious packets are logged
############################################
header "3.2.4 Ensure suspicious packets are logged"
msg "sysctl net.ipv4.conf.all.log_martians"
if [[ "$(sysctl net.ipv4.conf.all.log_martians)" == "net.ipv4.conf.all.log_martians = 1" ]];then
success_result
else
failed_result
fi
##################################################
# 3.2.5 Ensure broadcast ICMP requests are ignored
##################################################
header "3.2.5 Ensure broadcast ICMP requests are ignored"
msg "sysctl net.ipv4.icmp_echo_ignore_broadcasts"
if [[ "$(sysctl net.ipv4.icmp_echo_ignore_broadcasts)" == "net.ipv4.icmp_echo_ignore_broadcasts = 1" ]];then
success_result
else
failed_result
fi
###############################################
# 3.2.6 Ensure bogus ICMP responses are ignored
###############################################
header "3.2.6 Ensure bogus ICMP responses are ignored"
msg "sysctl net.ipv4.icmp_ignore_bogus_error_responses"
if [[ "$(sysctl net.ipv4.icmp_ignore_bogus_error_responses)" == "net.ipv4.icmp_ignore_bogus_error_responses = 1" ]];then
success_result
else
failed_result
fi
################################################
# 3.2.7 Ensure Reverse Path Filtering is enabled
################################################
header "3.2.7 Ensure Reverse Path Filtering is enabled"
msg "sysctl net.ipv4.conf.all.rp_filter"
if [[ "$(sysctl net.ipv4.conf.all.rp_filter)" == "net.ipv4.conf.all.rp_filter = 1" ]];then
success_result
else
failed_result
fi
msg "sysctl net.ipv4.conf.default.rp_filter"
if [[ "$(sysctl net.ipv4.conf.default.rp_filter)" == "net.ipv4.conf.default.rp_filter = 1" ]];then
success_result
else
failed_result
fi
#########################################
# 3.2.8 Ensure TCP SYN Cookies is enabled
#########################################
header "3.2.8 Ensure TCP SYN Cookies is enabled"
msg "sysctl net.ipv4.tcp_syncookies"
if [[ "$(sysctl net.ipv4.tcp_syncookies)" == "net.ipv4.tcp_syncookies = 1" ]];then
success_result
else
failed_result
fi
##########
# 3.3 IPv6
##########
##########################################################
# 3.3.1 Ensure IPv6 router advertisements are not accepted
##########################################################
header "3.3.1 Ensure IPv6 router advertisements are not accepted"
msg "sysctl net.ipv6.conf.all.accept_ra"
if [[ "$(sysctl net.ipv6.conf.all.accept_ra)" == "net.ipv6.conf.all.accept_ra = 0" ]];then
success_result
else
failed_result
fi
msg "sysctl net.ipv6.conf.default.accept_ra"
if [[ "$(sysctl net.ipv6.conf.default.accept_ra)" == "net.ipv6.conf.default.accept_ra = 0" ]];then
success_result
else
failed_result
fi
##############################################
# 3.3.2 Ensure IPv6 redirects are not accepted
##############################################
header "3.3.2 Ensure IPv6 redirects are not accepted"
msg "sysctl net.ipv6.conf.all.accept_redirects"
if [[ "$(sysctl net.ipv6.conf.all.accept_redirects)" == "net.ipv6.conf.all.accept_redirects = 0" ]];then
success_result
else
failed_result
fi
msg "sysctl net.ipv6.conf.default.accept_redirects"
if [[ "$(sysctl net.ipv6.conf.default.accept_redirects)" == "net.ipv6.conf.default.accept_redirects = 0" ]];then
success_result
else
failed_result
fi
###############################
# 3.3.3 Ensure IPv6 is disabled
###############################
if [ $INCLUDE_UNSCORED -eq 1 ];then
header "3.3.3 Ensure IPv6 is disabled"
msg "modprobe -c | grep ipv6"
modprobe -c | grep ipv6 | grep "options ipv6 disable=1" 2>&1 > /dev/null
check_retval_eq_0 $?
fi
##################
# 3.4 TCP Wrappers
##################
########################################
# 3.4.1 Ensure TCP Wrappers is installed
########################################
header "3.4.1 Ensure TCP Wrappers is installed"
msg "rpm -q tcp_wrappers"
rpm -q tcp_wrappers 2>&1 > /dev/null
check_retval_eq_0 $?
msg "rpm -q tcp_wrappers-libs"
rpm -q tcp_wrappers-libs 2>&1 > /dev/null
check_retval_eq_0 $?
#############################################
# 3.4.2 Ensure /etc/hosts.allow is configured
#############################################
header "3.4.2 Ensure /etc/hosts.allow is configured"
msg "cat /etc/hosts.allow"
grep "ALL:" /etc/hosts.allow 2>&1 > /dev/null
check_retval_eq_0 $?
#############################################
# 3.4.3 Ensure /etc/hosts.deny is configured
#############################################
header "3.4.3 Ensure /etc/hosts.deny is configured"
msg "cat /etc/hosts.deny"
grep "ALL: ALL" /etc/hosts.deny 2>&1 > /dev/null
check_retval_eq_0 $?
#############################################################
# 3.4.4 Ensure permissions on /etc/hosts.allow are configured
#############################################################
header "3.4.4 Ensure permissions on /etc/hosts.allow are configured"
msg "Ensure /etc/hosts.allow permissions are 0644 root:root"
if [[ $(stat /etc/hosts.allow) =~ Access:.*(0644/-rw-r--r--).*Uid:.*(.*0/.*root).*Gid:.*(.*0/.*root) ]];then
success_result
else
failed_result
fi
#############################################################
# 3.4.5 Ensure permissions on /etc/hosts.deny are configured
#############################################################
header "3.4.5 Ensure permissions on /etc/hosts.deny are configured"
msg "Ensure /etc/hosts.deny permissions are 0644 root:root"
if [[ $(stat /etc/hosts.deny) =~ Access:.*(0644/-rw-r--r--).*Uid:.*(.*0/.*root).*Gid:.*(.*0/.*root) ]];then
success_result
else
failed_result
fi
################################
# 3.5 Uncommon Network Protocols
################################
###############################
# 3.5.1 Ensure DCCP is disabled
###############################
if [ $INCLUDE_UNSCORED -eq 1 ];then
header "3.5.1 - 3.5.4 Ensure unneeded modules disabled"
for module in dccp sctp rds tipc;do
msg "modprobe -n -v $module"
modprobe -n -v $module | grep "install /bin/true" 2>&1 > /dev/null
check_retval_eq_0 $?
msg "lsmod | grep $module"
lsmod | grep "$module" 2>&1 > /dev/null
check_retval_ne_0 $?
done
fi
############################
# 3.6 Firewall Configuration
############################
####################################
# 3.6.1 Ensure IPTables is installed
####################################
header "3.6.1 Ensure IPTables is installed"
msg "rpm -q iptables"
rpm -q iptables 2>&1 > /dev/null
check_retval_eq_0 $?
###########################################
# 3.6.2 Ensure default deny firewall policy
###########################################
header "3.6.2 Ensure default deny firewall policy"
msg 'iptables -L | grep "INPUT" | grep "policy DROP"'
iptables -L | grep "INPUT" | grep "policy DROP" 2>&1 > /dev/null
check_retval_eq_0 $?
msg 'iptables -L | grep "FORWARD" | grep "policy DROP"'
iptables -L | grep "FORWARD" | grep "policy DROP" 2>&1 > /dev/null
check_retval_eq_0 $?
msg 'iptables -L | grep "OUTPUT" | grep "policy DROP"'
iptables -L | grep "OUTPUT" | grep "policy DROP" 2>&1 > /dev/null
check_retval_eq_0 $?
#############################################
# 3.6.3 Ensure loopback traffic is configured
#############################################
header "3.6.3 Ensure loopback traffic is configured"
msg "iptables -L INPUT -v -n =~ .*ACCEPT.*all.*--.*lo.*0.0.0.0/0.*0.0.0.0/0"
if [[ $(iptables -L INPUT -v -n) =~ .*ACCEPT.*all.*--.*lo.*0.0.0.0/0.*0.0.0.0/0 ]];then
success_result
else
failed_result
fi
msg "iptables -L INPUT -v -n =~ .*DROP.*all.*--.*127.0.0.0/8.*0.0.0.0/0'"
if [[ $(iptables -L INPUT -v -n) =~ .*DROP.*all.*--.*127.0.0.0/8.*0.0.0.0/0 ]];then
success_result
else
failed_result
fi
##################################################################
# 3.6.4 Ensure outbound and established connections are configured
##################################################################
if [ $INCLUDE_UNSCORED -eq 1 ];then
header "3.6.4 Ensure outbound and established connections are configured"
msg "See page 179, section 3.6.4"
/bin/true
check_retval_eq_0 $?
fi
######################################################
# 3.6.5 Ensure firewall rules exist for all open ports
######################################################
header "3.6.5 Ensure firewall rules exist for all open ports"
msg "See section 3.6.5, pg 183 for method"
/bin/true
check_retval_eq_0 $?
#############################################
# 3.7 Ensure wireless interfaces are disabled
#############################################
if [ $INCLUDE_UNSCORED -eq 1 ];then
header "3.7 Ensure wireless interfaces are disabled"
msg "See section 3.7, page 179"
/bin/true
check_retval_eq_0 $?
fi