forked from wpressly/Hardening-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCIS-CentOS_Linux7.sh
2152 lines (1931 loc) · 105 KB
/
CIS-CentOS_Linux7.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
: '
#SYNOPSIS
Quick win script for remediation of CentOS Linux 7 baseline misconfigurations.
.DESCRIPTION
This script will remediation all possible OS baseline misconfigurations from CIS for CentOS Linux 7 based Virtual machines.
.NOTES
Copyright (c) Cloudneeti. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Version: 1.0
# PREREQUISITE
.EXAMPLE
Ensure that you are logged in as root user. Use su command for the same.
Command to execute : bash CIS_CentOS_Linux7_Benchmark_v2_2_0_Remediation.sh
.INPUTS
.OUTPUTS
None
'
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;35m'
NC='\033[0m'
success=0
fail=0
yum update -y && yum install wget -y
###########################################################################################################################
##Category 1.1 Initial Setup - Filesystem Configuration
echo
echo -e "${BLUE}1.1 Initial Setup - Filesystem Configuration${NC}"
#Ensure mounting of cramfs filesystems is disabled
echo
echo -e "${RED}1.1.1.1${NC} Ensure mounting of cramfs filesystems is disabled"
modprobe -n -v cramfs | grep "^install /bin/true$" || echo "install cramfs /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^cramfs\s" && rmmod cramfs
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of cramfs filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of cramfs filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of freevxfs filesystems is disabled
echo
echo -e "${RED}1.1.1.2${NC} Ensure mounting of freevxfs filesystems is disabled"
modprobe -n -v freevxfs | grep "^install /bin/true$" || echo "install freevxfs /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^freevxfs\s" && rmmod freevxfs
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of freevxfs filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of freevxfs filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of jffs2 filesystems is disabled
echo
echo -e "${RED}1.1.1.3${NC} Ensure mounting of jffs2 filesystems is disabled"
modprobe -n -v jffs2 | grep "^install /bin/true$" || echo "install jffs2 /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^jffs2\s" && rmmod jffs2
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of jffs2 filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of jffs2 filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of hfs filesystems is disabled
echo
echo -e "${RED}1.1.1.4${NC} Ensure mounting of hfs filesystems is disabled"
modprobe -n -v hfs | grep "^install /bin/true$" || echo "install hfs /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^hfs\s" && rmmod hfs
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of hfs filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of hfs filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of hfsplus filesystems is disabled
echo
echo -e "${RED}1.1.1.5${NC} Ensure mounting of hfsplus filesystems is disabled"
modprobe -n -v hfsplus | grep "^install /bin/true$" || echo "install hfsplus /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^hfsplus\s" && rmmod hfsplus
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of hfsplus filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of hfsplus filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of squashfs filesystems is disabled
echo
echo -e "${RED}1.1.1.6${NC} Ensure mounting of squashfs filesystems is disabled"
modprobe -n -v squashfs | grep "^install /bin/true$" || echo "install squashfs /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^squashfs\s" && rmmod squashfs
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of squashfs filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of squashfs filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of udf filesystems is disabled
echo
echo -e "${RED}1.1.1.7${NC} Ensure mounting of udf filesystems is disabled"
modprobe -n -v udf | grep "^install /bin/true$" || echo "install udf /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^udf\s" && rmmod udf
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of udf filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of udf filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure mounting of FAT filesystems is disabled
echo
echo -e "${RED}1.1.1.8${NC} Ensure mounting of FAT filesystems is disabled"
modprobe -n -v vfat | grep "^install /bin/true$" || echo "install vfat /bin/true" >> /etc/modprobe.d/CIS.conf
policystatus=$?
lsmod | egrep "^vfat\s" && rmmod vfat
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure mounting of FAT filesystems is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure mounting of FAT filesystems is disabled"
fail=$((fail + 1))
fi
#Ensure sticky bit is set on all world-writable directories
echo
echo -e "${RED}1.1.21${NC} Ensure sticky bit is set on all world-writable directories"
df --local -P | awk {'if (NR!=1) print $6'} | xargs -I '{}' find '{}' -xdev -type d -perm -0002 2>/dev/null | xargs chmod a+t
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure sticky bit is set on all world-writable directories"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure sticky bit is set on all world-writable directories"
fail=$((fail + 1))
fi
#Disable Automounting
echo
echo -e "${RED}1.1.22${NC} Disable Automounting"
systemctl disable autofs.service
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Disable Automounting"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Disable Automounting"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 1.2 Initial Setup - Configure Software Updates
echo
echo -e "${BLUE}1.2 Initial Setup - Configure Software Updates${NC}"
#Ensure gpgcheck is globally activated
echo
echo -e "${RED}1.2.3${NC} Ensure gpgcheck is globally activated"
egrep -q "^(\s*)gpgcheck\s*=\s*\S+(\s*#.*)?\s*$" /etc/yum.conf && sed -ri "s/^(\s*)gpgcheck\s*=\s*\S+(\s*#.*)?\s*$/\1gpgcheck=1\2/" /etc/yum.conf || echo "gpgcheck=1" >> /etc/yum.conf
for file in /etc/yum.repos.d/*; do
egrep -q "^(\s*)gpgcheck\s*=\s*\S+(\s*#.*)?\s*$" $file && sed -ri "s/^(\s*)gpgcheck\s*=\s*\S+(\s*#.*)?\s*$/\1gpgcheck=1\2/" $file || echo "gpgcheck=1" >> $file
done
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure gpgcheck is globally activated"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure gpgcheck is globally activated"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 1.3 Initial Setup - Filesystem Integrity Checking
echo
echo -e "${BLUE}1.3 Initial Setup - Filesystem Integrity Checking${NC}"
#Ensure AIDE is installed
echo
echo -e "${RED}1.3.1${NC} Ensure AIDE is installed"
yum -y install aide && aide --init && mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure AIDE is installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure AIDE is installed"
fail=$((fail + 1))
fi
#Ensure filesystem integrity is regularly checked
echo
echo -e "${RED}1.3.2${NC} Ensure filesystem integrity is regularly checked"
(crontab -u root -l; crontab -u root -l | egrep -q "^0 5 \* \* \* /usr/sbin/aide --check$" || echo "0 5 * * * /usr/sbin/aide --check" ) | crontab -u root -
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure filesystem integrity is regularly checked"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure filesystem integrity is regularly checked"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 1.4 Initial Setup - Secure Boot Settings
echo
echo -e "${BLUE}1.4 Initial Setup - Secure Boot Settings${NC}"
#Ensure permissions on bootloader config are configured
echo
echo -e "${RED}1.4.1${NC} Ensure permissions on bootloader config are configured"
chown root:root /boot/grub2/grub.cfg && chmod og-rwx /boot/grub2/grub.cfg && chown root:root /boot/grub2/user.cfg && chmod og-rwx /boot/grub2/user.cfg
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure permissions on bootloader config are configured"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure permissions on bootloader config are configured"
fail=$((fail + 1))
fi
#Ensure authentication required for single user mode
echo
echo -e "${RED}1.4.3${NC} Ensure authentication required for single user mode"
egrep -q "^\s*ExecStart" /usr/lib/systemd/system/rescue.service && sed -ri "s/(^[[:space:]]*ExecStart[[:space:]]*=[[:space:]]*).*$/\1-\/bin\/sh -c \"\/sbin\/sulogin; \/usr\/bin\/systemctl --fail --no-block default\"/" /usr/lib/systemd/system/rescue.service || echo "ExecStart=-/bin/sh -c \"/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" >> /usr/lib/systemd/system/rescue.service
egrep -q "^\s*ExecStart" /usr/lib/systemd/system/emergency.service && sed -ri "s/(^[[:space:]]*ExecStart[[:space:]]*=[[:space:]]*).*$/\1-\/bin\/sh -c \"\/sbin\/sulogin; \/usr\/bin\/systemctl --fail --no-block default\"/" /usr/lib/systemd/system/emergency.service || echo "ExecStart=-/bin/sh -c \"/sbin/sulogin; /usr/bin/systemctl --fail --no-block default\"" >> /usr/lib/systemd/system/emergency.service
echo -e "${GREEN}Remediated:${NC} Ensure authentication required for single user mode"
success=$((success + 1))
############################################################################################################################
##Category 1.5 Initial Setup - Additional Process Hardening
echo
echo -e "${BLUE}1.5 Initial Setup - Additional Process Hardening${NC}"
#Ensure core dumps are restricted
echo
echo -e "${RED}1.5.1${NC} Ensure core dumps are restricted"
egrep -q "^(\s*)\*\s+hard\s+core\s+\S+(\s*#.*)?\s*$" /etc/security/limits.conf && sed -ri "s/^(\s*)\*\s+hard\s+core\s+\S+(\s*#.*)?\s*$/\1* hard core 0\2/" /etc/security/limits.conf || echo "* hard core 0" >> /etc/security/limits.conf
egrep -q "^(\s*)fs.suid_dumpable\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)fs.suid_dumpable\s*=\s*\S+(\s*#.*)?\s*$/\1fs.suid_dumpable = 0\2/" /etc/sysctl.conf || echo "fs.suid_dumpable = 0" >> /etc/sysctl.conf
echo -e "${GREEN}Remediated:${NC} Ensure core dumps are restricted"
success=$((success + 1))
#Ensure address space layout randomization (ASLR) is enabled
echo
echo -e "${RED}1.5.3${NC} Ensure address space layout randomization (ASLR) is enabled"
egrep -q "^(\s*)kernel.randomize_va_space\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)kernel.randomize_va_space\s*=\s*\S+(\s*#.*)?\s*$/\1kernel.randomize_va_space = 2\2/" /etc/sysctl.conf || echo "kernel.randomize_va_space = 2" >> /etc/sysctl.conf
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure address space layout randomization (ASLR) is enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure address space layout randomization (ASLR) is enabled"
fail=$((fail + 1))
fi
#Ensure prelink is disabled
echo
echo -e "${RED}1.5.4${NC} Ensure prelink is disabled"
prelink -ua && yum remove prelink
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure prelink is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure prelink is disabled"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 1.6 Initial Setup - Mandatory Access Control
echo
echo -e "${BLUE}1.6 Initial Setup - Mandatory Access Control${NC}"
#Ensure SELinux is not disabled in bootloader configuration
echo
echo -e "${RED}1.6.1.1${NC} Ensure SELinux is not disabled in bootloader configuration"
sed -ri "s/^(\s*)GRUB_CMDLINE_LINUX=\"selinux=0\"\s*=\s*\S+(\s*#.*)?\s*$/\1GRUB_CMDLINE_LINUX=\"\"\2/" /etc/default/grub
sed -ri "s/^(\s*)GRUB_CMDLINE_LINUX=\"enforcing=0\"\s*=\s*\S+(\s*#.*)?\s*$/\1GRUB_CMDLINE_LINUX=\"\"\2/" /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
echo -e "${GREEN}Remediated:${NC} Ensure SELinux is not disabled in bootloader configuration"
success=$((success + 1))
#Ensure the SELinux state is enforcing
echo
echo -e "${RED}1.6.1.2${NC} Ensure the SELinux state is enforcing"
egrep -q "^(\s*)SELINUX\s*=\s*\S+(\s*#.*)?\s*$" /etc/selinux/config && sed -ri "s/^(\s*)SELINUX\s*=\s*\S+(\s*#.*)?\s*$/\1SELINUX=enforcing\2/" /etc/selinux/config || echo "SELINUX=enforcing" >> /etc/selinux/config
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure the SELinux state is enforcing"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure the SELinux state is enforcing"
fail=$((fail + 1))
fi
#Ensure SELinux policy is configured
echo
echo -e "${RED}1.6.1.3${NC} Ensure SELinux policy is configured"
egrep -q "^(\s*)SELINUXTYPE\s*=\s*\S+(\s*#.*)?\s*$" /etc/selinux/config && sed -ri "s/^(\s*)SELINUXTYPE\s*=\s*\S+(\s*#.*)?\s*$/\1SELINUXTYPE=targeted\2/" /etc/selinux/config || echo "SELINUXTYPE=targeted" >> /etc/selinux/config
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure SELinux policy is configured"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure SELinux policy is configured"
fail=$((fail + 1))
fi
#Ensure SETroubleshoot is not installed
echo
echo -e "${RED}1.6.1.4${NC} Ensure SETroubleshoot is not installed"
yum remove setroubleshoot
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure SETroubleshoot is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure SETroubleshoot is not installed"
fail=$((fail + 1))
fi
#Ensure the MCS Translation Service (mcstrans) is not installed
echo
echo -e "${RED}1.6.1.5${NC} Ensure the MCS Translation Service (mcstrans) is not installed"
yum remove mcstrans
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure the MCS Translation Service (mcstrans) is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure the MCS Translation Service (mcstrans) is not installed"
fail=$((fail + 1))
fi
#Ensure SELinux is installed
echo
echo -e "${RED}1.6.2${NC} Ensure SELinux is installed"
rpm -q libselinux || yum -y install libselinux
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure SELinux is installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure SELinux is installed"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 1.7 Initial Setup - Warning Banners
echo
echo -e "${BLUE}1.7 Initial Setup - Warning Banners${NC}"
#Ensure message of the day is configured properly
echo
echo -e "${RED}1.7.1.1${NC} Ensure message of the day is configured properly"
sed -ri 's/(\\v|\\r|\\m|\\s)//g' /etc/motd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure message of the day is configured properly"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure message of the day is configured properly"
fail=$((fail + 1))
fi
#Ensure local login warning banner is configured properly
echo
echo -e "${RED}1.7.1.2${NC} Ensure local login warning banner is configured properly"
echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure local login warning banner is configured properly"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure local login warning banner is configured properly"
fail=$((fail + 1))
fi
#Ensure remote login warning banner is configured properly
echo
echo -e "${RED}1.7.1.3${NC} Ensure remote login warning banner is configured properly"
echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure remote login warning banner is configured properly"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure remote login warning banner is configured properly"
fail=$((fail + 1))
fi
#Ensure permissions on /etc/motd are configured
echo
echo -e "${RED}1.7.1.4${NC} Ensure permissions on /etc/motd are configured"
chown root:root /etc/motd && chmod 644 /etc/motd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure permissions on /etc/motd are configured"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure permissions on /etc/motd are configured"
fail=$((fail + 1))
fi
#Ensure permissions on /etc/issue are configured
echo
echo -e "${RED}1.7.1.5${NC} Ensure permissions on /etc/issue are configured"
chown root:root /etc/issue && chmod 644 /etc/issue
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure permissions on /etc/issue are configured"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure permissions on /etc/issue are configured"
fail=$((fail + 1))
fi
#Ensure permissions on /etc/issue.net are configured
echo
echo -e "${RED}1.7.1.6${NC} Ensure permissions on /etc/issue.net are configured"
chown root:root /etc/issue.net && chmod 644 /etc/issue.net
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure permissions on /etc/issue.net are configured"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure permissions on /etc/issue.net are configured"
fail=$((fail + 1))
fi
#Ensure updates, patches, and additional security software are installed
echo
echo -e "${RED}1.8${NC} Ensure updates, patches, and additional security software are installed"
yum update --security
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure updates, patches, and additional security software are installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure updates, patches, and additional security software are installed"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 2.1 Services - inetd Services
echo
echo -e "${BLUE}2.1 Services - inetd Services${NC}"
#Ensure chargen services are not enabled
echo
echo -e "${RED}2.1.1${NC} Ensure chargen services are not enabled"
chkconfig chargen-dgram off && chkconfig chargen-stream off
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure chargen services are not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure chargen services are not enabled"
fail=$((fail + 1))
fi
#Ensure daytime services are not enabled
echo
echo -e "${RED}2.1.2${NC} Ensure daytime services are not enabled"
chkconfig daytime-dgram off && chkconfig daytime-stream off
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure daytime services are not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure daytime services are not enabled"
fail=$((fail + 1))
fi
#Ensure discard services are not enabled
echo
echo -e "${RED}2.1.3${NC} Ensure discard services are not enabled"
chkconfig discard-dgram off && chkconfig discard-stream off
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure discard services are not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure discard services are not enabled"
fail=$((fail + 1))
fi
#Ensure echo services are not enabled
echo
echo -e "${RED}2.1.4${NC} Ensure echo services are not enabled"
chkconfig echo-dgram off && chkconfig echo-stream off
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure echo services are not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure echo services are not enabled"
fail=$((fail + 1))
fi
#Ensure time services are not enabled
echo
echo -e "${RED}2.1.5${NC} Ensure time services are not enabled"
chkconfig time-dgram off && chkconfig time-stream off
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure time services are not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure time services are not enabled"
fail=$((fail + 1))
fi
#Ensure tftp server is not enabled
echo
echo -e "${RED}2.1.6${NC} Ensure tftp server is not enabled"
chkconfig tftp off
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure tftp server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure tftp server is not enabled"
fail=$((fail + 1))
fi
#Ensure xinetd is not enabled
echo
echo -e "${RED}2.1.7${NC} Ensure xinetd is not enabled"
systemctl disable xinetd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure xinetd is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure xinetd is not enabled"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 2.2 Services - Special Purpose Services
echo
echo -e "${BLUE}2.2 Services - Special Purpose Services${NC}"
#Ensure time synchronization is in use
echo
echo -e "${RED}2.2.1.1${NC} Ensure time synchronization is in use"
rpm -q ntp || rpm -q chrony || yum -y install chrony
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure time synchronization is in use"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure time synchronization is in use"
fail=$((fail + 1))
fi
#Ensure ntp is configured
echo
echo -e "${RED}2.2.1.2${NC} Ensure ntp is configured"
if rpm -q ntp >/dev/null; then
egrep -q "^\s*restrict(\s+-4)?\s+default(\s+\S+)*(\s*#.*)?\s*$" /etc/ntp.conf && sed -ri "s/^(\s*)restrict(\s+-4)?\s+default(\s+[^[:space:]#]+)*(\s+#.*)?\s*$/\1restrict\2 default kod nomodify notrap nopeer noquery\4/" /etc/ntp.conf || echo "restrict default kod nomodify notrap nopeer noquery" >> /etc/ntp.conf
egrep -q "^\s*restrict\s+-6\s+default(\s+\S+)*(\s*#.*)?\s*$" /etc/ntp.conf && sed -ri "s/^(\s*)restrict\s+-6\s+default(\s+[^[:space:]#]+)*(\s+#.*)?\s*$/\1restrict -6 default kod nomodify notrap nopeer noquery\3/" /etc/ntp.conf || echo "restrict -6 default kod nomodify notrap nopeer noquery" >> /etc/ntp.conf
egrep -q "^(\s*)OPTIONS\s*=\s*\"(([^\"]+)?-u\s[^[:space:]\"]+([^\"]+)?|([^\"]+))\"(\s*#.*)?\s*$" /etc/sysconfig/ntpd && sed -ri '/^(\s*)OPTIONS\s*=\s*\"([^\"]*)\"(\s*#.*)?\s*$/ {/^(\s*)OPTIONS\s*=\s*\"[^\"]*-u\s+\S+[^\"]*\"(\s*#.*)?\s*$/! s/^(\s*)OPTIONS\s*=\s*\"([^\"]*)\"(\s*#.*)?\s*$/\1OPTIONS=\"\2 -u ntp:ntp\"\3/ }' /etc/sysconfig/ntpd && sed -ri "s/^(\s*)OPTIONS\s*=\s*\"([^\"]+\s+)?-u\s[^[:space:]\"]+(\s+[^\"]+)?\"(\s*#.*)?\s*$/\1OPTIONS=\"\2\-u ntp:ntp\3\"\4/" /etc/sysconfig/ntpd || echo "OPTIONS=\"-u ntp:ntp\"" >> /etc/sysconfig/ntpd
fi
echo -e "${GREEN}Remediated:${NC} Ensure ntp is configured"
success=$((success + 1))
#Ensure chrony is configured
echo
echo -e "${RED}2.2.1.3${NC} Ensure chrony is configured"
if rpm -q chrony >/dev/null; then
egrep -q "^(\s*)OPTIONS\s*=\s*\"(([^\"]+)?-u\s[^[:space:]\"]+([^\"]+)?|([^\"]+))\"(\s*#.*)?\s*$" /etc/sysconfig/chronyd && sed -ri '/^(\s*)OPTIONS\s*=\s*\"([^\"]*)\"(\s*#.*)?\s*$/ {/^(\s*)OPTIONS\s*=\s*\"[^\"]*-u\s+\S+[^\"]*\"(\s*#.*)?\s*$/! s/^(\s*)OPTIONS\s*=\s*\"([^\"]*)\"(\s*#.*)?\s*$/\1OPTIONS=\"\2 -u chrony\"\3/ }' /etc/sysconfig/chronyd && sed -ri "s/^(\s*)OPTIONS\s*=\s*\"([^\"]+\s+)?-u\s[^[:space:]\"]+(\s+[^\"]+)?\"(\s*#.*)?\s*$/\1OPTIONS=\"\2\-u chrony\3\"\4/" /etc/sysconfig/chronyd || echo "OPTIONS=\"-u chrony\"" >> /etc/sysconfig/chronyd
fi
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure chrony is configured"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure chrony is configured"
fail=$((fail + 1))
fi
#Ensure X Window System is not installed
echo
echo -e "${RED}2.2.2${NC} Ensure X Window System is not installed"
yum remove xorg-x11*
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure X Window System is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure X Window System is not installed"
fail=$((fail + 1))
fi
#Ensure Avahi Server is not enabled
echo
echo -e "${RED}2.2.3${NC} Ensure Avahi Server is not enabled"
systemctl disable avahi-daemon
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure Avahi Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure Avahi Server is not enabled"
fail=$((fail + 1))
fi
#Ensure CUPS is not enabled
echo
echo -e "${RED}2.2.4${NC} Ensure CUPS is not enabled"
systemctl disable cups
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure CUPS is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure CUPS is not enabled"
fail=$((fail + 1))
fi
#Ensure DHCP Server is not enabled
echo
echo -e "${RED}2.2.5${NC} Ensure DHCP Server is not enabled"
systemctl disable dhcpd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure DHCP Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure DHCP Server is not enabled"
fail=$((fail + 1))
fi
#Ensure LDAP server is not enabled
echo
echo -e "${RED}2.2.6${NC} Ensure LDAP server is not enabled"
systemctl disable slapd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure LDAP server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure LDAP server is not enabled"
fail=$((fail + 1))
fi
#Ensure NFS and RPC are not enabled
echo
echo -e "${RED}2.2.7${NC} Ensure NFS and RPC are not enabled"
systemctl disable nfs && systemctl disable nfs-server && systemctl disable rpcbind
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure NFS and RPC are not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure NFS and RPC are not enabled"
fail=$((fail + 1))
fi
#Ensure DNS Server is not enabled
echo
echo -e "${RED}2.2.8${NC} Ensure DNS Server is not enabled"
systemctl disable named
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure DNS Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure DNS Server is not enabled"
fail=$((fail + 1))
fi
#Ensure FTP Server is not enabled
echo
echo -e "${RED}2.2.9${NC} Ensure FTP Server is not enabled"
systemctl disable vsftpd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure FTP Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure FTP Server is not enabled"
fail=$((fail + 1))
fi
#Ensure HTTP server is not enabled
echo
echo -e "${RED}2.2.10${NC} Ensure HTTP server is not enabled"
systemctl disable httpd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure HTTP server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure HTTP server is not enabled"
fail=$((fail + 1))
fi
#Ensure IMAP and POP3 server is not enabled
echo
echo -e "${RED}2.2.11${NC} Ensure IMAP and POP3 server is not enabled"
systemctl disable dovecot
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure IMAP and POP3 server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure IMAP and POP3 server is not enabled"
fail=$((fail + 1))
fi
#Ensure Samba is not enabled
echo
echo -e "${RED}2.2.12${NC} Ensure Samba is not enabled"
systemctl disable smb
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure Samba is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure Samba is not enabled"
fail=$((fail + 1))
fi
#Ensure HTTP Proxy Server is not enabled
echo
echo -e "${RED}2.2.13${NC} Ensure HTTP Proxy Server is not enabled"
systemctl disable squid
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure HTTP Proxy Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure HTTP Proxy Server is not enabled"
fail=$((fail + 1))
fi
#Ensure SNMP Server is not enabled
echo
echo -e "${RED}2.2.14${NC} Ensure SNMP Server is not enabled"
systemctl disable snmpd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure SNMP Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure SNMP Server is not enabled"
fail=$((fail + 1))
fi
#Ensure mail transfer agent is configured for local-only mode
echo
echo -e "${RED}2.2.15${NC} Ensure mail transfer agent is configured for local-only mode"
egrep -q "^(\s*)inet_interfaces\s*=\s*\S+(\s*#.*)?\s*$" /etc/postfix/main.cf && sed -ri "s/^(\s*)inet_interfaces\s*=\s*\S+(\s*#.*)?\s*$/\1inet_interfaces = loopback-only\2/" /etc/postfix/main.cf || echo "inet_interfaces = loopback-only" >> /etc/postfix/main.cf
systemctl restart postfix
echo -e "${GREEN}Remediated:${NC} Ensure mail transfer agent is configured for local-only mode"
success=$((success + 1))
#Ensure NIS Server is not enabled
echo
echo -e "${RED}2.2.16${NC} Ensure NIS Server is not enabled"
systemctl disable ypserv
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure NIS Server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure NIS Server is not enabled"
fail=$((fail + 1))
fi
#Ensure rsh server is not enabled
echo
echo -e "${RED}2.2.17${NC} Ensure rsh server is not enabled"
systemctl disable rsh.socket.service && systemctl disable rlogin.socket.service && systemctl disable rexec.socket.service
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure rsh server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure rsh server is not enabled"
fail=$((fail + 1))
fi
#Ensure telnet server is not enabled
echo
echo -e "${RED}2.2.18${NC} Ensure telnet server is not enabled"
systemctl disable telnet.socket.service
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure telnet server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure telnet server is not enabled"
fail=$((fail + 1))
fi
#Ensure tftp server is not enabled
echo
echo -e "${RED}2.2.19${NC} Ensure tftp server is not enabled"
systemctl disable tftp.socket
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure tftp server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure tftp server is not enabled"
fail=$((fail + 1))
fi
#Ensure rsync service is not enabled
echo
echo -e "${RED}2.2.20${NC} Ensure rsync service is not enabled"
systemctl disable rsyncd
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure rsync service is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure rsync service is not enabled"
fail=$((fail + 1))
fi
#Ensure talk server is not enabled
echo
echo -e "${RED}2.2.21${NC} Ensure talk server is not enabled"
systemctl disable ntalk
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure talk server is not enabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure talk server is not enabled"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 2.3 Services - Service Clients
echo
echo -e "${BLUE}2.3 Services - Service Clients${NC}"
#Ensure NIS Client is not installed
echo
echo -e "${RED}2.3.1${NC} Ensure NIS Client is not installed"
yum remove ypbind
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure NIS Client is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure NIS Client is not installed"
fail=$((fail + 1))
fi
#Ensure rsh client is not installed
echo
echo -e "${RED}2.3.2${NC} Ensure rsh client is not installed"
yum remove rsh
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure rsh client is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure rsh client is not installed"
fail=$((fail + 1))
fi
#Ensure talk client is not installed
echo
echo -e "${RED}2.3.3${NC} Ensure talk client is not installed"
yum remove talk
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure talk client is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure talk client is not installed"
fail=$((fail + 1))
fi
#Ensure telnet client is not installed
echo
echo -e "${RED}2.3.4${NC} Ensure telnet client is not installed"
yum -y remove telnet
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure telnet client is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure telnet client is not installed"
fail=$((fail + 1))
fi
#Ensure LDAP client is not installed
echo
echo -e "${RED}2.3.5${NC} Ensure LDAP client is not installed"
yum remove openldap-clients
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure LDAP client is not installed"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure LDAP client is not installed"
fail=$((fail + 1))
fi
############################################################################################################################
##Category 3.1 Network Configuration - Network Parameters (Host Only)
echo
echo -e "${BLUE}3.1 Network Configuration - Network Parameters (Host Only)${NC}"
#Ensure IP forwarding is disabled
echo
echo -e "${RED}3.1.1${NC} Ensure IP forwarding is disabled"
egrep -q "^(\s*)net.ipv4.ip_forward\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.ip_forward\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.ip_forward = 0\2/" /etc/sysctl.conf || echo "net.ipv4.ip_forward = 0" >> /etc/sysctl.conf
policystatus=$?
if [[ "$policystatus" -eq 0 ]]; then
echo -e "${GREEN}Remediated:${NC} Ensure IP forwarding is disabled"
success=$((success + 1))
else
echo -e "${RED}UnableToRemediate:${NC} Ensure IP forwarding is disabled"
fail=$((fail + 1))
fi
#Ensure packet redirect sending is disabled
echo
echo -e "${RED}3.1.2${NC} Ensure packet redirect sending is disabled"
egrep -q "^(\s*)net.ipv4.conf.all.send_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.all.send_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.send_redirects = 0\2/" /etc/sysctl.conf || echo "net.ipv4.conf.all.send_redirects = 0" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.default.send_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.default.send_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.send_redirects = 0\2/" /etc/sysctl.conf || echo "net.ipv4.conf.default.send_redirects = 0" >> /etc/sysctl.conf
sysctl -w net.ipv4.conf.all.send_redirects=0
sysctl -w net.ipv4.conf.default.send_redirects=0
sysctl -w net.ipv4.route.flush=1
echo -e "${GREEN}Remediated:${NC} Ensure packet redirect sending is disabled"
success=$((success + 1))
############################################################################################################################
##Category 3.2 Network Configuration - Network Parameters (Host and Router)
echo
echo -e "${BLUE}3.2 Network Configuration - Network Parameters (Host and Router)${NC}"
#Ensure source routed packets are not accepted
echo
echo -e "${RED}3.2.1${NC} Ensure source routed packets are not accepted"
egrep -q "^(\s*)net.ipv4.conf.all.accept_source_route\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.all.accept_source_route\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.accept_source_route = 0\2/" /etc/sysctl.conf || echo "net.ipv4.conf.all.accept_source_route = 0" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.default.accept_source_route\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.default.accept_source_route\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.accept_source_route = 0\2/" /etc/sysctl.conf || echo "net.ipv4.conf.default.accept_source_route = 0" >> /etc/sysctl.conf
echo -e "${GREEN}Remediated:${NC} Ensure source routed packets are not accepted"
success=$((success + 1))
#Ensure ICMP redirects are not accepted
echo
echo -e "${RED}3.2.2${NC} Ensure ICMP redirects are not accepted"
egrep -q "^(\s*)net.ipv4.conf.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.accept_redirects = 0\2/" /etc/sysctl.conf || echo "net.ipv4.conf.all.accept_redirects = 0" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.default.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.default.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.accept_redirects = 0\2/" /etc/sysctl.conf || echo "net.ipv4.conf.default.accept_redirects = 0" >> /etc/sysctl.conf
sysctl -w net.ipv4.conf.all.accept_redirects=0
sysctl -w net.ipv4.conf.default.accept_redirects=0
sysctl -w net.ipv4.route.flush=1