-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecureRH7.sh
1078 lines (889 loc) · 68.5 KB
/
secureRH7.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 -xv
# Ensure mounting of cramfs filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^cramfs\s" && rmmod cramfs
# Ensure mounting of freevxfs filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^freevxfs\s" && rmmod freevxfs
# Ensure mounting of jffs2 filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^jffs2\s" && rmmod jffs2
# Ensure mounting of hfs filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^hfs\s" && rmmod hfs
# Ensure mounting of hfsplus filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^hfsplus\s" && rmmod hfsplus
# Ensure mounting of squashfs filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^squashfs\s" && rmmod squashfs
# Ensure mounting of udf filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^udf\s" && rmmod udf
# Ensure mounting of FAT filesystems is disabled
echo
echo \*\*\*\* 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
lsmod | egrep "^vfat\s" && rmmod vfat
# Ensure nodev option set on /tmp partition
echo
echo \*\*\*\* Ensure\ nodev\ option\ set\ on\ /tmp\ partition
echo Ensure\ nodev\ option\ set\ on\ /tmp\ partition not configured
# Ensure nosuid option set on /tmp partition
echo
echo \*\*\*\* Ensure\ nosuid\ option\ set\ on\ /tmp\ partition
echo Ensure\ nosuid\ option\ set\ on\ /tmp\ partition not configured
# Ensure noexec option set on /tmp partition
echo
echo \*\*\*\* Ensure\ noexec\ option\ set\ on\ /tmp\ partition
echo Ensure\ noexec\ option\ set\ on\ /tmp\ partition not configured
# Ensure nodev option set on /var/tmp partition
echo
echo \*\*\*\* Ensure\ nodev\ option\ set\ on\ /var/tmp\ partition
echo Ensure\ nodev\ option\ set\ on\ /var/tmp\ partition not configured
# Ensure nosuid option set on /var/tmp partition
echo
echo \*\*\*\* Ensure\ nosuid\ option\ set\ on\ /var/tmp\ partition
echo Ensure\ nosuid\ option\ set\ on\ /var/tmp\ partition not configured
# Ensure noexec option set on /var/tmp partition
echo
echo \*\*\*\* Ensure\ noexec\ option\ set\ on\ /var/tmp\ partition
echo Ensure\ noexec\ option\ set\ on\ /var/tmp\ partition not configured
# Ensure nodev option set on /home partition
echo
echo \*\*\*\* Ensure\ nodev\ option\ set\ on\ /home\ partition
echo Ensure\ nodev\ option\ set\ on\ /home\ partition not configured
# Ensure nodev option set on /dev/shm partition
echo
echo \*\*\*\* Ensure\ nodev\ option\ set\ on\ /dev/shm\ partition
echo Ensure\ nodev\ option\ set\ on\ /dev/shm\ partition not configured
# Ensure nosuid option set on /dev/shm partition
echo
echo \*\*\*\* Ensure\ nosuid\ option\ set\ on\ /dev/shm\ partition
echo Ensure\ nosuid\ option\ set\ on\ /dev/shm\ partition not configured
# Ensure noexec option set on /dev/shm partition
echo
echo \*\*\*\* Ensure\ noexec\ option\ set\ on\ /dev/shm\ partition
echo Ensure\ noexec\ option\ set\ on\ /dev/shm\ partition not configured
# Ensure sticky bit is set on all world-writable directories
echo
echo \*\*\*\* 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
# Disable Automounting
echo
echo \*\*\*\* Disable\ Automounting
systemctl disable autofs.service
# Ensure gpgcheck is globally activated
echo
echo \*\*\*\* 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
ficheros=`ls /etc/yum.repos.d/`
for file in $ficheros; 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
# Ensure AIDE is installed
echo
echo \*\*\*\* Ensure\ AIDE\ is\ installed
rpm -q aide || yum -y install aide
# Ensure filesystem integrity is regularly checked
echo
echo \*\*\*\* 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 -
# Ensure permissions on bootloader config are configured
echo
echo \*\*\*\* 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
# Ensure bootloader password is set
echo
echo \*\*\*\* Ensure\ bootloader\ password\ is\ set
echo Ensure\ bootloader\ password\ is\ set not configured.
# Ensure authentication required for single user mode
echo
echo \*\*\*\* 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
# Ensure core dumps are restricted
echo
echo \*\*\*\* 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*)\*\s+hard\s+core\s+\S+(\s*#.*)?\s*$" /etc/security/limits.d/* && sed -ri "s/^(\s*)\*\s+hard\s+core\s+\S+(\s*#.*)?\s*$/\1* hard core 0\2/" /etc/security/limits.d/* || for i in /etc/security/limits.d/*; do echo "* hard core 0" >> $i; done
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
egrep -q "^(\s*)fs.suid_dumpable\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)fs.suid_dumpable\s*=\s*\S+(\s*#.*)?\s*$/\1fs.suid_dumpable = 0\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/* ; do echo "fs.suid_dumpable = 0" >> $i; done
# Ensure XD/NX support is enabled
echo
echo \*\*\*\* Ensure\ XD/NX\ support\ is\ enabled
echo Ensure\ XD/NX\ support\ is\ enabled not configured.
# Ensure address space layout randomization (ASLR) is enabled
echo
echo \*\*\*\* 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
egrep -q "^(\s*)kernel.randomize_va_space\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)kernel.randomize_va_space\s*=\s*\S+(\s*#.*)?\s*$/\1kernel.randomize_va_space = 2\2/" /etc/sysctl.d/*|| for i in /etc/sysctl.d/*; do echo "kernel.randomize_va_space = 2" >> $i; done
# Ensure prelink is disabled
echo
echo \*\*\*\* Ensure\ prelink\ is\ disabled
rpm -q prelink && yum -y remove prelink
# Ensure SELinux is not disabled in bootloader configuration
echo
echo \*\*\*\* Ensure\ SELinux\ is\ not\ disabled\ in\ bootloader\ configuration
echo Ensure\ SELinux\ is\ not\ disabled\ in\ bootloader\ configuration not configured.
# Ensure the SELinux state is enforcing
echo
echo \*\*\*\* Ensure\ the\ SELinux\ state\ is\ enforcing
echo Ensure\ the\ SELinux\ state\ is\ enforcing not configured.
# Ensure SELinux policy is configured
echo
echo \*\*\*\* Ensure\ SELinux\ policy\ is\ configured
echo Ensure\ SELinux\ policy\ is\ configured not configured.
# Ensure SETroubleshoot is not installed
echo
echo \*\*\*\* Ensure\ SETroubleshoot\ is\ not\ installed
rpm -q setroubleshoot && yum -y remove setroubleshoot
# Ensure the MCS Translation Service (mcstrans) is not installed
echo
echo \*\*\*\* Ensure\ the\ MCS\ Translation\ Service\ \(mcstrans\)\ is\ not\ installed
rpm -q mcstrans && yum -y remove mcstrans
# Ensure no unconfined daemons exist
echo
echo \*\*\*\* Ensure\ no\ unconfined\ daemons\ exist
echo Ensure\ no\ unconfined\ daemons\ exist Linux custom object not configured.
# Ensure SELinux is installed
echo
echo \*\*\*\* Ensure\ SELinux\ is\ installed
rpm -q libselinux || yum -y install libselinux
# Ensure message of the day is configured properly
echo
echo \*\*\*\* Ensure\ message\ of\ the\ day\ is\ configured\ properly
sed -ri 's/(\\v|\\r|\\m|\\s)//g' /etc/motd
# Ensure local login warning banner is configured properly
echo
echo \*\*\*\* Ensure\ local\ login\ warning\ banner\ is\ configured\ properly
echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue
# Ensure remote login warning banner is configured properly
echo
echo \*\*\*\* Ensure\ remote\ login\ warning\ banner\ is\ configured\ properly
echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue.net
# Ensure permissions on /etc/motd are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/motd\ are\ configured
chmod -t,u+r+w-x-s,g+r-w-x-s,o+r-w-x /etc/motd
# Ensure permissions on /etc/issue are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/issue\ are\ configured
chmod -t,u+r+w-x-s,g+r-w-x-s,o+r-w-x /etc/issue
# Ensure permissions on /etc/issue.net are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/issue.net\ are\ configured
chmod -t,u+r+w-x-s,g+r-w-x-s,o+r-w-x /etc/issue.net
# Ensure GDM login banner is configured
echo
echo \*\*\*\* Ensure\ GDM\ login\ banner\ is\ configured
echo Ensure\ GDM\ login\ banner\ is\ configured not configured.
# Ensure chargen services are not enabled
echo
echo \*\*\*\* Ensure\ chargen\ services\ are\ not\ enabled
chkconfig chargen off
echo /etc/inetd.conf and /etc/inetd.d/* unmodified
chkconfig chargen-dgram off
chkconfig chargen-stream off
# Ensure daytime services are not enabled
echo
echo \*\*\*\* Ensure\ daytime\ services\ are\ not\ enabled
chkconfig daytime off
echo /etc/inetd.conf and /etc/inetd.d/* unmodified
# Ensure discard services are not enabled
echo
echo \*\*\*\* Ensure\ discard\ services\ are\ not\ enabled
chkconfig discard off
echo /etc/inetd.conf and /etc/inetd.d/* unmodified
# Ensure echo services are not enabled
echo
echo \*\*\*\* Ensure\ echo\ services\ are\ not\ enabled
chkconfig echo off
echo /etc/inetd.conf and /etc/inetd.d/* unmodified
# Ensure time services are not enabled
echo
echo \*\*\*\* Ensure\ time\ services\ are\ not\ enabled
chkconfig time off
echo /etc/inetd.conf and /etc/inetd.d/* unmodified
# Ensure tftp server is not enabled
echo
echo \*\*\*\* Ensure\ tftp\ server\ is\ not\ enabled
chkconfig tftp off
echo /etc/inetd.conf and /etc/inetd.d/* unmodified
systemctl disable tftp.socket.service
# Ensure xinetd is not enabled
echo
echo \*\*\*\* Ensure\ xinetd\ is\ not\ enabled
systemctl disable xinetd.service
# Ensure time synchronization is in use
echo
echo \*\*\*\* Ensure\ time\ synchronization\ is\ in\ use
rpm -q ntp || rpm -q chrony || yum -y install chrony
# Ensure ntp is configured
echo
echo \*\*\*\* 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 -4 default kod nomodify notrap nopeer noquery\3/" /etc/ntp.conf || echo "restrict -4 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
# egrep -q "^(server|pool)" /etc/ntp.conf && sed -ri "s/^(server|pool).*/#/" /etc/ntp.conf && echo -e "server ntp-server1.om.dsn.inet\nserver ntp-server2.om.dsn.inet" >> /etc/ntp.conf
systemctl restart ntpd
fi
# Ensure chrony is configured
echo
echo \*\*\*\* 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
# egrep -q "^server" /etc/chrony.conf && sed -ri "s/^server.*/#/" /etc/chrony.conf && echo -e "server ntp-server1.om.dsn.inet iburst\nserver ntp-server2.om.dsn.inet iburst" >> /etc/chrony.conf
systemctl restart chronyd
echo Ensure chrony is configured - server not configured.
fi
# Ensure X Window System is not installed
echo
echo \*\*\*\* Ensure\ X\ Window\ System\ is\ not\ installed
yum -y remove xorg-x11*
# Ensure Avahi Server is not enabled
echo
echo \*\*\*\* Ensure\ Avahi\ Server\ is\ not\ enabled
systemctl disable avahi-daemon.service
# Ensure CUPS is not enabled
echo
echo \*\*\*\* Ensure\ CUPS\ is\ not\ enabled
systemctl disable cups.service
# Ensure DHCP Server is not enabled
echo
echo \*\*\*\* Ensure\ DHCP\ Server\ is\ not\ enabled
systemctl disable dhcpd.service
# Ensure LDAP server is not enabled
# echo
# echo \*\*\*\* Ensure\ LDAP\ server\ is\ not\ enabled
# systemctl disable slapd.service
# Ensure NFS and RPC are not enabled
echo
echo \*\*\*\* Ensure\ NFS\ and\ RPC\ are\ not\ enabled
systemctl disable nfs.service
systemctl disable nfs-server
systemctl disable rpcbind.service
# Ensure DNS Server is not enabled
echo
echo \*\*\*\* Ensure\ DNS\ Server\ is\ not\ enabled
systemctl disable named.service
# Ensure FTP Server is not enabled
echo
echo \*\*\*\* Ensure\ FTP\ Server\ is\ not\ enabled
systemctl disable vsftpd.service
# Ensure HTTP server is not enabled
echo
echo \*\*\*\* Ensure\ HTTP\ server\ is\ not\ enabled
systemctl disable htttpd.service
# Ensure IMAP and POP3 server is not enabled
echo
echo \*\*\*\* Ensure\ IMAP\ and\ POP3\ server\ is\ not\ enabled
systemctl disable dovecot.service
# Ensure Samba is not enabled
echo
echo \*\*\*\* Ensure\ Samba\ is\ not\ enabled
systemctl disable smb.service
# Ensure HTTP Proxy Server is not enabled
echo
echo \*\*\*\* Ensure\ HTTP\ Proxy\ Server\ is\ not\ enabled
systemctl disable squid.service
# Ensure SNMP Server is not enabled
echo
echo \*\*\*\* Ensure\ SNMP\ Server\ is\ not\ enabled
systemctl disable snmpd.service
# Ensure mail transfer agent is configured for local-only mode
echo
echo \*\*\*\* Ensure\ mail\ transfer\ agent\ is\ configured\ for\ local-only\ mode
echo Ensure\ mail\ transfer\ agent\ is\ configured\ for\ local-only\ mode Linux custom object not configured.
sed -i "s/^inet_interfaces.\+/inet_interfaces = loopback-only/g" /etc/postfix/main.cf
service postfix restart
# Ensure NIS Server is not enabled
echo
echo \*\*\*\* Ensure\ NIS\ Server\ is\ not\ enabled
systemctl disable ypserv.service
# Ensure rsh server is not enabled
echo
echo \*\*\*\* Ensure\ rsh\ server\ is\ not\ enabled
systemctl disable rsh.socket.service
systemctl disable rlogin.socket.service
systemctl disable rexec.socket.service
# Ensure talk server is not enabled
echo
echo \*\*\*\* Ensure\ talk\ server\ is\ not\ enabled
systemctl disable ntalk.service
# Ensure telnet server is not enabled
echo
echo \*\*\*\* Ensure\ telnet\ server\ is\ not\ enabled
systemctl disable telnet.socket.service
# Ensure rsync service is not enabled
echo
echo \*\*\*\* Ensure\ rsync\ service\ is\ not\ enabled
systemctl disable rsyncd
# Ensure NIS Client is not installed
echo
echo \*\*\*\* Ensure\ NIS\ Client\ is\ not\ installed
rpm -q ypbind && yum -y remove ypbind
# Ensure rsh client is not installed
echo
echo \*\*\*\* Ensure\ rsh\ client\ is\ not\ installed
rpm -q rsh && yum -y remove rsh
# Ensure talk client is not installed
echo
echo \*\*\*\* Ensure\ talk\ client\ is\ not\ installed
rpm -q talk && yum -y remove talk
# Ensure telnet client is not installed
echo
echo \*\*\*\* Ensure\ telnet\ client\ is\ not\ installed
rpm -q telnet && yum -y remove telnet
# Ensure LDAP client is not installed
# echo
# echo \*\*\*\* Ensure\ LDAP\ client\ is\ not\ installed
# rpm -q openldap-clients && yum -y remove openldap-clients
# Ensure IP forwarding is disabled
echo
echo \*\*\*\* 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
egrep -q "^(\s*)net.ipv4.ip_forward\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.ip_forward\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.ip_forward = 0\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.ip_forward = 0" >> $i; done
# Ensure packet redirect sending is disabled
echo
echo \*\*\*\* 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.all.send_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && 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.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.send_redirects = 0" >> $i; done
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
egrep -q "^(\s*)net.ipv4.conf.default.send_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && 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.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.default.send_redirects = 0" >> $i; done
# Ensure source routed packets are not accepted
echo
echo \*\*\*\* 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.all.accept_source_route\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && 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.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.accept_source_route = 0" >> $i; done
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
egrep -q "^(\s*)net.ipv4.conf.default.accept_source_route\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && 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.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.default.accept_source_route = 0" >> $i; done
# Ensure ICMP redirects are not accepted
echo
echo \*\*\*\* 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.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && 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.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.accept_redirects = 0" >> $i; done
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.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && 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.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.accept_redirects = 0" >> $i; done
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
# Ensure secure ICMP redirects are not accepted
echo
echo \*\*\*\* Ensure\ secure\ ICMP\ redirects\ are\ not\ accepted
egrep -q "^(\s*)net.ipv4.conf.all.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.all.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.secure_redirects = 1\2/" /etc/sysctl.conf || echo "net.ipv4.conf.all.secure_redirects = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.all.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.conf.all.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.secure_redirects = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.secure_redirects = 1" >> $i; done
egrep -q "^(\s*)net.ipv4.conf.default.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.default.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.secure_redirects = 1\2/" /etc/sysctl.conf || echo "net.ipv4.conf.default.secure_redirects = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.default.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.conf.default.secure_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.secure_redirects = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.default.secure_redirects = 1" >> $i; done
sysctl -w net.ipv4.conf.all.secure_redirects=0
sysctl -w net.ipv4.conf.default.secure_redirects=0
sysctl -w net.ipv4.route.flush=1
# Ensure suspicious packets are logged
echo
echo \*\*\*\* Ensure\ suspicious\ packets\ are\ logged
egrep -q "^(\s*)net.ipv4.conf.all.log_martians\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.all.log_martians\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.log_martians = 1\2/" /etc/sysctl.conf || echo "net.ipv4.conf.all.log_martians = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.all.log_martians\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.conf.all.log_martians\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.log_martians = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.log_martians = 1" >> $i; done
egrep -q "^(\s*)net.ipv4.conf.default.log_martians\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.default.log_martians\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.log_martians = 1\2/" /etc/sysctl.conf || echo "net.ipv4.conf.default.log_martians = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.default.log_martians\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.conf.default.log_martians\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.log_martians = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.default.log_martians = 1" >> $i; done
sysctl -w net.ipv4.conf.all.log_martians=1
sysctl -w net.ipv4.conf.default.log_martians=1
sysctl -w net.ipv4.route.flush=1
# Ensure broadcast ICMP requests are ignored
echo
echo \*\*\*\* Ensure\ broadcast\ ICMP\ requests\ are\ ignored
egrep -q "^(\s*)net.ipv4.icmp_echo_ignore_broadcasts\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.icmp_echo_ignore_broadcasts\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.icmp_echo_ignore_broadcasts = 1\2/" /etc/sysctl.conf || echo "net.ipv4.icmp_echo_ignore_broadcasts = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.icmp_echo_ignore_broadcasts\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.icmp_echo_ignore_broadcasts\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.icmp_echo_ignore_broadcasts = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.icmp_echo_ignore_broadcasts = 1" >> $i; done
sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
sysctl -w net.ipv4.route.flush=1
# Ensure bogus ICMP responses are ignored
echo
echo \*\*\*\* Ensure\ bogus\ ICMP\ responses\ are\ ignored
egrep -q "^(\s*)net.ipv4.icmp_ignore_bogus_error_responses\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.icmp_ignore_bogus_error_responses\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.icmp_ignore_bogus_error_responses = 1\2/" /etc/sysctl.conf || echo "net.ipv4.icmp_ignore_bogus_error_responses = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.icmp_ignore_bogus_error_responses\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.icmp_ignore_bogus_error_responses\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.icmp_ignore_bogus_error_responses = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.icmp_ignore_bogus_error_responses = 1" >> $i; done
sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1
sysctl -w net.ipv4.route.flush=1
# Ensure Reverse Path Filtering is enabled
echo
echo \*\*\*\* Ensure\ Reverse\ Path\ Filtering\ is\ enabled
egrep -q "^(\s*)net.ipv4.conf.all.rp_filter\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.all.rp_filter\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.rp_filter = 1\2/" /etc/sysctl.conf || echo "net.ipv4.conf.all.rp_filter = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.all.rp_filter\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.conf.all.rp_filter\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.all.rp_filter = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.all.rp_filter = 1" >> /etc/sysctl.d/*; done
egrep -q "^(\s*)net.ipv4.conf.default.rp_filter\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.conf.default.rp_filter\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.rp_filter = 1\2/" /etc/sysctl.conf || echo "net.ipv4.conf.default.rp_filter = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.conf.default.rp_filter\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.conf.default.rp_filter\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.conf.default.rp_filter = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.conf.default.rp_filter = 1" >> $i; done
sysctl -w net.ipv4.conf.all.rp_filter=1
sysctl -w net.ipv4.conf.default.rp_filter=1
sysctl -w net.ipv4.route.flush=1
# Ensure TCP SYN Cookies is enabled
echo
echo \*\*\*\* Ensure\ TCP\ SYN\ Cookies\ is\ enabled
egrep -q "^(\s*)net.ipv4.tcp_syncookies\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv4.tcp_syncookies\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.tcp_syncookies = 1\2/" /etc/sysctl.conf || echo "net.ipv4.tcp_syncookies = 1" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv4.tcp_syncookies\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv4.tcp_syncookies\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv4.tcp_syncookies = 1\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv4.tcp_syncookies = 1" >> $i; done
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.ipv4.route.flush=1
# Ensure IPv6 router advertisements are not accepted
echo
echo \*\*\*\* Ensure\ IPv6\ router\ advertisements\ are\ not\ accepted
egrep -q "^(\s*)net.ipv6.conf.all.accept_ra\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv6.conf.all.accept_ra\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.all.accept_ra = 0\2/" /etc/sysctl.conf || echo "net.ipv6.conf.all.accept_ra = 0" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv6.conf.all.accept_ra\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv6.conf.all.accept_ra\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.all.accept_ra = 0\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv6.conf.all.accept_ra = 0" >> $i; done
egrep -q "^(\s*)net.ipv6.conf.default.accept_ra\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv6.conf.default.accept_ra\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.default.accept_ra = 0\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv6.conf.default.accept_ra = 0" >> $i; done
sysctl -w net.ipv6.conf.all.accept_ra=0
sysctl -w net.ipv6.conf.default.accept_ra=0
sysctl -w net.ipv6.route.flush=1
# Ensure IPv6 redirects are not accepted
echo
echo \*\*\*\* Ensure\ IPv6\ redirects\ are\ not\ accepted
egrep -q "^(\s*)net.ipv6.conf.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv6.conf.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.all.accept_redirects = 0\2/" /etc/sysctl.conf || echo "net.ipv6.conf.all.accept_redirects = 0" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv6.conf.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv6.conf.all.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.all.accept_redirects = 0\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv6.conf.all.accept_redirects = 0" >> $i; done
egrep -q "^(\s*)net.ipv6.conf.default.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.conf && sed -ri "s/^(\s*)net.ipv6.conf.default.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.default.accept_redirects = 0\2/" /etc/sysctl.conf || echo "net.ipv6.conf.default.accept_redirects = 0" >> /etc/sysctl.conf
egrep -q "^(\s*)net.ipv6.conf.default.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$" /etc/sysctl.d/* && sed -ri "s/^(\s*)net.ipv6.conf.default.accept_redirects\s*=\s*\S+(\s*#.*)?\s*$/\1net.ipv6.conf.default.accept_redirects = 0\2/" /etc/sysctl.d/* || for i in /etc/sysctl.d/*; do echo "net.ipv6.conf.default.accept_redirects = 0" >> $i; done
sysctl -w net.ipv6.conf.all.accept_redirects=0
sysctl -w net.ipv6.conf.default.accept_redirects=0
sysctl -w net.ipv6.route.flush=1
# Ensure IPv6 is disabled
echo
echo \*\*\*\* Ensure\ IPv6\ is\ disabled
echo Ensure\ IPv6\ is\ disabled not configured.
# Ensure TCP Wrappers is installed
echo
echo \*\*\*\* Ensure\ TCP\ Wrappers\ is\ installed
rpm -q tcp_wrappers || yum -y install tcp_wrappers
rpm -q tcp_wrappers-libs || yum -y install tcp_wrappers-libs
# Ensure /etc/hosts.allow is configured
echo
echo \*\*\*\* Ensure\ /etc/hosts.allow\ is\ configured
touch /etc/hosts.allow
# Ensure /etc/hosts.deny is configured
echo
echo \*\*\*\* Ensure\ /etc/hosts.deny\ is\ configured
echo Ensure\ /etc/hosts.deny\ is\ configured not configured.
# Ensure permissions on /etc/hosts.allow are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/hosts.allow\ are\ configured
chmod -t,u+r+w-x-s,g+r-w-x-s,o+r-w-x /etc/hosts.allow
# Ensure permissions on /etc/hosts.deny are 644
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/hosts.deny\ are\ 644
chmod -t,u+r+w-x-s,g+r-w-x-s,o+r-w-x /etc/hosts.deny
# Ensure DCCP is disabled
echo
echo \*\*\*\* Ensure\ DCCP\ is\ disabled
modprobe -n -v dccp | grep "^install /bin/true$" || echo "install dccp /bin/true" >> /etc/modprobe.d/CIS.conf
lsmod | egrep "^dccp\s" && rmmod dccp
# Ensure SCTP is disabled
echo
echo \*\*\*\* Ensure\ SCTP\ is\ disabled
modprobe -n -v sctp | grep "^install /bin/true$" || echo "install sctp /bin/true" >> /etc/modprobe.d/CIS.conf
lsmod | egrep "^sctp\s" && rmmod sctp
# Ensure RDS is disabled
echo
echo \*\*\*\* Ensure\ RDS\ is\ disabled
modprobe -n -v rds | grep "^install /bin/true$" || echo "install rds /bin/true" >> /etc/modprobe.d/CIS.conf
lsmod | egrep "^rds\s" && rmmod rds
# Ensure TIPC is disabled
echo
echo \*\*\*\* Ensure\ TIPC\ is\ disabled
modprobe -n -v tipc | grep "^install /bin/true$" || echo "install tipc /bin/true" >> /etc/modprobe.d/CIS.conf
lsmod | egrep "^tipc\s" && rmmod tipc
# Ensure iptables is installed
echo
echo \*\*\*\* Ensure\ iptables\ is\ installed
rpm -q iptables || yum -y install iptables
# Ensure default deny firewall policy
echo
echo \*\*\*\* Ensure\ default\ deny\ firewall\ policy
echo Ensure\ default\ deny\ firewall\ policy not configured.
# Ensure loopback traffic is configured
echo
echo \*\*\*\* Ensure\ loopback\ traffic\ is\ configured
echo Ensure\ loopback\ traffic\ is\ configured not configured.
# Ensure firewall rules exist for all open ports
echo
echo \*\*\*\* Ensure\ firewall\ rules\ exist\ for\ all\ open\ ports
echo Ensure\ firewall\ rules\ exist\ for\ all\ open\ ports not configured.
# Ensure audit log storage size is configured
echo
echo \*\*\*\* Ensure\ audit\ log\ storage\ size\ is\ configured
echo Ensure\ audit\ log\ storage\ size\ is\ configured not configured.
# Ensure auditd service is enabled
echo
echo \*\*\*\* Ensure\ auditd\ service\ is\ enabled
systemctl enable auditd.service
# Ensure auditing for processes that start prior to auditd is enabled
echo
echo \*\*\*\* Ensure\ auditing\ for\ processes\ that\ start\ prior\ to\ auditd\ is\ enabled
egrep -q "^(\s*)GRUB_CMDLINE_LINUX\s*=\s*\"([^\"]+)?\"(\s*#.*)?\s*$" /etc/default/grub && sed -ri '/^(\s*)GRUB_CMDLINE_LINUX\s*=\s*\"([^\"]*)?\"(\s*#.*)?\s*$/ {/^(\s*)GRUB_CMDLINE_LINUX\s*=\s*\"([^\"]+\s+)?audit=\S+(\s+[^\"]+)?\"(\s*#.*)?\s*$/! s/^(\s*GRUB_CMDLINE_LINUX\s*=\s*\"([^\"]+)?)(\"(\s*#.*)?\s*)$/\1 audit=1\3/ }' /etc/default/grub && sed -ri "s/^((\s*)GRUB_CMDLINE_LINUX\s*=\s*\"([^\"]+\s+)?)audit=\S+((\s+[^\"]+)?\"(\s*#.*)?\s*)$/\1audit=1\4/" /etc/default/grub || echo "GRUB_CMDLINE_LINUX=\"audit=1\"" >> /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
# Ensure events that modify date and time information are collected
echo
echo \*\*\*\* Ensure\ events\ that\ modify\ date\ and\ time\ information\ are\ collected
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+adjtimex\s+-S\s+settimeofday\s+-S\s+stime\s+-k\s+time-change\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change" >> /etc/audit/rules.d/audit.rules
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+clock_settime\s+-k\s+time-change\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S clock_settime -k time-change" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/localtime\s+-p\s+wa\s+-k\s+time-change\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/localtime -p wa -k time-change" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+adjtimex\s+-S\s+settimeofday\s+-k\s+time-change\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+clock_settime\s+-k\s+time-change\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S clock_settime -k time-change" >> /etc/audit/rules.d/audit.rules
# Ensure events that modify user/group information are collected
echo
echo \*\*\*\* Ensure\ events\ that\ modify\ user/group\ information\ are\ collected
egrep "^-w\s+/etc/group\s+-p\s+wa\s+-k\s+identity\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/group -p wa -k identity" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/passwd\s+-p\s+wa\s+-k\s+identity\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/passwd -p wa -k identity" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/gshadow\s+-p\s+wa\s+-k\s+identity\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/gshadow -p wa -k identity" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/shadow\s+-p\s+wa\s+-k\s+identity\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/shadow -p wa -k identity" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/security/opasswd\s+-p\s+wa\s+-k\s+identity\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/security/opasswd -p wa -k identity" >> /etc/audit/rules.d/audit.rules
# Ensure events that modify the system's network environment are collected
echo
echo \*\*\*\* Ensure\ events\ that\ modify\ the\ system\'s\ network\ environment\ are\ collected
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+sethostname\s+-S\s+setdomainname\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S sethostname -S setdomainname -k system-locale" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/issue\s+-p\s+wa\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/issue -p wa -k system-locale" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/issue.net\s+-p\s+wa\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/issue.net -p wa -k system-locale" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/hosts\s+-p\s+wa\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/hosts -p wa -k system-locale" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/sysconfig/network\s+-p\s+wa\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/sysconfig/network -p wa -k system-locale" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/etc/sysconfig/network-scripts\s+-p\s+wa\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/sysconfig/network-scripts/ -p wa -k system-locale" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+sethostname\s+-S\s+setdomainname\s+-k\s+system-locale\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale" >> /etc/audit/rules.d/audit.rules
# Ensure events that modify the system's Mandatory Access Controls are collected
echo
echo \*\*\*\* Ensure\ events\ that\ modify\ the\ system\'s\ Mandatory\ Access\ Controls\ are\ collected
egrep "^-w\s+/etc/selinux/\s+-p\s+wa\s+-k\s+MAC-policy\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/selinux/ -p wa -k MAC-policy" >> /etc/audit/rules.d/audit.rules
echo "-w /usr/share/selinux/ -p wa -k MAC-policy" >> /etc/audit/rules.d/audit.rules
# Ensure login and logout events are collected
echo
echo \*\*\*\* Ensure\ login\ and\ logout\ events\ are\ collected
egrep "^-w\s+/var/run/faillock/\s+-p\s+wa\s+-k\s+logins\s*$" /etc/audit/rules.d/audit.rules || echo "-w /var/run/faillock/ -p wa -k logins" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/var/log/lastlog\s+-p\s+wa\s+-k\s+logins\s*$" /etc/audit/rules.d/audit.rules || echo "-w /var/log/lastlog -p wa -k logins" >> /etc/audit/rules.d/audit.rules
# Ensure session initiation information is collected
echo
echo \*\*\*\* Ensure\ session\ initiation\ information\ is\ collected
egrep "^-w\s+/var/run/utmp\s+-p\s+wa\s+-k\s+session\s*$" /etc/audit/rules.d/audit.rules || echo "-w /var/run/utmp -p wa -k session" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/var/log/wtmp\s+-p\s+wa\s+-k\s+logins\s*$" /etc/audit/rules.d/audit.rules || echo "-w /var/log/wtmp -p wa -k logins" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/var/log/btmp\s+-p\s+wa\s+-k\s+logins\s*$" /etc/audit/rules.d/audit.rules || echo "-w /var/log/btmp -p wa -k logins" >> /etc/audit/rules.d/audit.rules
# Ensure discretionary access control permission modification events are collected
echo
echo \*\*\*\* Ensure\ discretionary\ access\ control\ permission\ modification\ events\ are\ collected
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+chmod\s+-S\s+fchmod\s+-S\s+fchmodat\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+perm_mod\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S chmod -S fchmod -S fchmodat -F auid>=1000 -F auid!=4294967295 -k perm_mod" >> /etc/audit/rules.d/audit.rules
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+chown\s+-S\s+fchown\s+-S\s+fchownat\s+-S\s+lchown\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+perm_mod\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S chown -S fchown -S fchownat -S lchown -F auid>=1000 -F auid!=4294967295 -k perm_mod" >> /etc/audit/rules.d/audit.rules
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+setxattr\s+-S\s+lsetxattr\s+-S\s+fsetxattr\s+-S\s+removexattr\s+-S\s+lremovexattr\s+-S\s+fremovexattr\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+perm_mod\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+chmod\s+-S\s+fchmod\s+-S\s+fchmodat\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+perm_mod\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -F auid>=1000 -F auid!=4294967295 -k perm_mod" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+chown\s+-S\s+fchown\s+-S\s+fchownat\s+-S\s+lchown\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+perm_mod\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -F auid>=1000 -F auid!=4294967295 -k perm_mod" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+setxattr\s+-S\s+lsetxattr\s+-S\s+fsetxattr\s+-S\s+removexattr\s+-S\s+lremovexattr\s+-S\s+fremovexattr\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+perm_mod\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -F auid>=1000 -F auid!=4294967295 -k perm_mod" >> /etc/audit/rules.d/audit.rules
# Ensure unsuccessful unauthorized file access attempts are collected
echo
echo \*\*\*\* Ensure\ unsuccessful\ unauthorized\ file\ access\ attempts\ are\ collected
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+creat\s+-S\s+open\s+-S\s+openat\s+-S\s+truncate\s+-S\s+ftruncate\s+-F\s+exit=-EACCES\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+access\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=4294967295 -k access" >> /etc/audit/rules.d/audit.rules
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+creat\s+-S\s+open\s+-S\s+openat\s+-S\s+truncate\s+-S\s+ftruncate\s+-F\s+exit=-EPERM\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+access\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=4294967295 -k access" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+creat\s+-S\s+open\s+-S\s+openat\s+-S\s+truncate\s+-S\s+ftruncate\s+-F\s+exit=-EACCES\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+access\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=4294967295 -k access" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+creat\s+-S\s+open\s+-S\s+openat\s+-S\s+truncate\s+-S\s+ftruncate\s+-F\s+exit=-EPERM\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+access\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S creat -S open -S openat -S truncate -S ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=4294967295 -k access" >> /etc/audit/rules.d/audit.rules
# Ensure use of privileged commands is collected
echo
echo \*\*\*\* Ensure\ use\ of\ privileged\ commands\ is\ collected
for file in `find / -xdev \( -perm -4000 -o -perm -2000 \) -type f`; do egrep -q "^\s*-a\s+(always,exit|exit,always)\s+-F\s+path=$file\s+-F\s+perm=x\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+privileged\s*(#.*)?$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F path=$file -F perm=x -F auid>=1000 -F auid!=4294967295 -k privileged" >> /etc/audit/rules.d/audit.rules; done
# Ensure successful file system mounts are collected
echo
echo \*\*\*\* Ensure\ successful\ file\ system\ mounts\ are\ collected
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+mount\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+mounts\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S mount -F auid>=1000 -F auid!=4294967295 -k mounts" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+mount\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+mounts\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S mount -F auid>=1000 -F auid!=4294967295 -k mounts" >> /etc/audit/rules.d/audit.rules
# Ensure file deletion events by users are collected
echo
echo \*\*\*\* Ensure\ file\ deletion\ events\ by\ users\ are\ collected
egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b32\s+-S\s+unlink\s+-S\s+unlinkat\s+-S\s+rename\s+-S\s+renameat\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+delete\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+-F\s+arch=b64\s+-S\s+unlink\s+-S\s+unlinkat\s+-S\s+rename\s+-S\s+renameat\s+-F\s+auid>=1000\s+-F\s+auid!=4294967295\s+-k\s+delete\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 -F auid!=4294967295 -k delete" >> /etc/audit/rules.d/audit.rules
# Ensure changes to system administration scope (sudoers) is collected
echo
echo \*\*\*\* Ensure\ changes\ to\ system\ administration\ scope\ \(sudoers\)\ is\ collected
egrep -q "^-w\s+/etc/sudoers\s+-p\s+wa\s+-k\s+scope\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/sudoers -p wa -k scope" >> /etc/audit/rules.d/audit.rules
egrep -q "^-w\s+/etc/sudoers.d\s+-p\s+wa\s+-k\s+scope\s*$" /etc/audit/rules.d/audit.rules || echo "-w /etc/sudoers.d -p wa -k scope" >> /etc/audit/rules.d/audit.rules
# Ensure system administrator actions (sudolog) are collected
echo
echo \*\*\*\* Ensure\ system\ administrator\ actions\ \(sudolog\)\ are\ collected
egrep "^-w\s+/var/log/sudo.log\s+-p\s+wa\s+-k\s+actions\s*$" /etc/audit/rules.d/audit.rules || echo "-w /var/log/sudo.log -p wa -k actions" >> /etc/audit/rules.d/audit.rules
# Ensure kernel module loading and unloading is collected
echo
echo \*\*\*\* Ensure\ kernel\ module\ loading\ and\ unloading\ is\ collected
egrep "^-w\s+/sbin/insmod\s+-p\s+x\s+-k\s+modules\s*$" /etc/audit/rules.d/audit.rules || echo "-w /sbin/insmod -p x -k modules" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/sbin/rmmod\s+-p\s+x\s+-k\s+modules\s*$" /etc/audit/rules.d/audit.rules || echo "-w /sbin/rmmod -p x -k modules" >> /etc/audit/rules.d/audit.rules
egrep "^-w\s+/sbin/modprobe\s+-p\s+x\s+-k\s+modules\s*$" /etc/audit/rules.d/audit.rules || echo "-w /sbin/modprobe -p x -k modules" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' || egrep "^-a\s+(always,exit|exit,always)\s+arch=b32\s+-S\s+init_module\s+-S\s+delete_module\s+-k\s+modules\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit arch=b32 -S init_module -S delete_module -k modules" >> /etc/audit/rules.d/audit.rules
uname -p | grep -q 'x86_64' && egrep "^-a\s+(always,exit|exit,always)\s+arch=b64\s+-S\s+init_module\s+-S\s+delete_module\s+-k\s+modules\s*$" /etc/audit/rules.d/audit.rules || echo "-a always,exit arch=b64 -S init_module -S delete_module -k modules" >> /etc/audit/rules.d/audit.rules
# Ensure the audit configuration is immutable
echo
echo \*\*\*\* Ensure\ the\ audit\ configuration\ is\ immutable
egrep "^-e\s+2\s*$" /etc/audit/rules.d/audit.rules || echo "-e 2" >> /etc/audit/rules.d/audit.rules
# Ensure rsyslog is installed (Scored)
echo
echo Ensure rsyslog is installed \(Scored\)
rpm -q rsyslog || dnf -y install rsyslog
# Ensure rsyslog Service is enabled
echo
echo \*\*\*\* Ensure\ rsyslog\ Service\ is\ enabled
rpm -q rsyslog && systemctl enable rsyslog.service
# Ensure rsyslog default file permissions configured
echo
echo \*\*\*\* Ensure\ rsyslog\ default\ file\ permissions\ configured
echo Ensure\ rsyslog\ default\ file\ permissions\ configured not configured.
grep -q "^\$FileCreateMode" /etc/rsyslog.conf || echo '$FileCreateMode 0640' >> /etc/rsyslog.conf
for i in /etc/rsyslog.d/*.conf
do
grep -q "^\$FileCreateMode" $i || echo '$FileCreateMode 0640' >> $i
done
# Ensure rsyslog is configured to send logs to a remote log host
echo
echo \*\*\*\* Ensure\ rsyslog\ is\ configured\ to\ send\ logs\ to\ a\ remote\ log\ host
echo Ensure\ rsyslog\ is\ configured\ to\ send\ logs\ to\ a\ remote\ log\ host not configured.
# Ensure syslog-ng service is enabled
echo
echo \*\*\*\* Ensure\ syslog-ng\ service\ is\ enabled
rpm -q syslog-ng && systemctl enable syslog-ng.service
# Ensure syslog-ng default file permissions configured
echo
echo \*\*\*\* Ensure\ syslog-ng\ default\ file\ permissions\ configured
echo Ensure\ syslog-ng\ default\ file\ permissions\ configured not configured.
# Ensure rsyslog or syslog-ng is installed
echo
echo \*\*\*\* Ensure\ rsyslog\ or\ syslog-ng\ is\ installed
rpm -q rsyslog || rpm -q syslog-ng || yum -y install rsyslog
# Ensure permissions on all logfiles are configured
# echo
# echo \*\*\*\* Ensure\ permissions\ on\ all\ logfiles\ are\ configured
# chmod -R g-w-x,o-r-w-x /var/log/.*
# Ensure cron daemon is enabled
echo
echo \*\*\*\* Ensure\ cron\ daemon\ is\ enabled
systemctl enable crond.service
# Ensure permissions on /etc/crontab are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/crontab\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/crontab
# Ensure permissions on /etc/cron.hourly are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/cron.hourly\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/cron.hourly
# Ensure permissions on /etc/cron.daily are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/cron.daily\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/cron.daily
# Ensure permissions on /etc/cron.weekly are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/cron.weekly\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/cron.weekly
# Ensure permissions on /etc/cron.monthly are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/cron.monthly\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/cron.monthly
# Ensure permissions on /etc/cron.d are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/cron.d\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/cron.d
# Ensure at/cron is restricted to authorized users
echo
echo \*\*\*\* Ensure\ at \/cron\ is\ restricted\ to\ authorized\ users
rm -f /etc/cron.deny
rm -f /etc/at.deny
touch /etc/cron.allow
touch /etc/at.allow
chmod g-r-w-x,o-r-w-x /etc/cron.allow
chmod g-r-w-x,o-r-w-x /etc/at.allow
# Ensure permissions on /etc/ssh/sshd_config are configured
echo
echo \*\*\*\* Ensure\ permissions\ on\ /etc/ssh/sshd_config\ are\ configured
chmod g-r-w-x,o-r-w-x /etc/ssh/sshd_config
# Ensure SSH Protocol is set to 2
echo
echo \*\*\*\* Ensure\ SSH\ Protocol\ is\ set\ to\ 2
egrep -q "^(\s*)Protocol\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)Protocol\s+\S+(\s*#.*)?\s*$/\1Protocol 2\2/" /etc/ssh/sshd_config || echo "Protocol 2" >> /etc/ssh/sshd_config
# Ensure SSH LogLevel is set to INFO
echo
echo \*\*\*\* Ensure\ SSH\ LogLevel\ is\ set\ to\ INFO
egrep -q "^(\s*)LogLevel\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)LogLevel\s+\S+(\s*#.*)?\s*$/\1LogLevel INFO\2/" /etc/ssh/sshd_config || echo "LogLevel INFO" >> /etc/ssh/sshd_config
# Ensure SSH X11 forwarding is disabled
echo
echo \*\*\*\* Ensure\ SSH\ X11\ forwarding\ is\ disabled
egrep -q "^(\s*)X11Forwarding\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)X11Forwarding\s+\S+(\s*#.*)?\s*$/\1X11Forwarding no\2/" /etc/ssh/sshd_config || echo "X11Forwarding no" >> /etc/ssh/sshd_config
# Ensure SSH MaxAuthTries is set to 4 or less
echo
echo \*\*\*\* Ensure\ SSH\ MaxAuthTries\ is\ set\ to\ 4\ or\ less
egrep -q "^(\s*)MaxAuthTries\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)MaxAuthTries\s+\S+(\s*#.*)?\s*$/\1MaxAuthTries 4\2/" /etc/ssh/sshd_config || echo "MaxAuthTries 4" >> /etc/ssh/sshd_config
# Ensure SSH IgnoreRhosts is enabled
echo
echo \*\*\*\* Ensure\ SSH\ IgnoreRhosts\ is\ enabled
egrep -q "^(\s*)IgnoreRhosts\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)IgnoreRhosts\s+\S+(\s*#.*)?\s*$/\1IgnoreRhosts yes\2/" /etc/ssh/sshd_config || echo "IgnoreRhosts yes" >> /etc/ssh/sshd_config
# Ensure SSH HostbasedAuthentication is disabled
echo
echo \*\*\*\* Ensure\ SSH\ HostbasedAuthentication\ is\ disabled
egrep -q "^(\s*)HostbasedAuthentication\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)HostbasedAuthentication\s+\S+(\s*#.*)?\s*$/\1HostbasedAuthentication no\2/" /etc/ssh/sshd_config || echo "HostbasedAuthentication no" >> /etc/ssh/sshd_config
# Ensure SSH root login is disabled
echo
echo \*\*\*\* Ensure\ SSH\ root\ login\ is\ disabled
egrep -q "^(\s*)PermitRootLogin\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)PermitRootLogin\s+\S+(\s*#.*)?\s*$/\1PermitRootLogin no\2/" /etc/ssh/sshd_config || echo "PermitRootLogin no" >> /etc/ssh/sshd_config
# Ensure SSH PermitEmptyPasswords is disabled
echo
echo \*\*\*\* Ensure\ SSH\ PermitEmptyPasswords\ is\ disabled
egrep -q "^(\s*)PermitEmptyPasswords\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)PermitEmptyPasswords\s+\S+(\s*#.*)?\s*$/\1PermitEmptyPasswords no\2/" /etc/ssh/sshd_config || echo "PermitEmptyPasswords no" >> /etc/ssh/sshd_config
# Ensure SSH PermitUserEnvironment is disabled
echo
echo \*\*\*\* Ensure\ SSH\ PermitUserEnvironment\ is\ disabled
egrep -q "^(\s*)PermitUserEnvironment\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)PermitUserEnvironment\s+\S+(\s*#.*)?\s*$/\1PermitUserEnvironment no\2/" /etc/ssh/sshd_config || echo "PermitUserEnvironment no" >> /etc/ssh/sshd_config
# Ensure only approved ciphers are used
echo
echo \*\*\*\* Ensure\ only\ approved\ ciphers\ are\ used
egrep -q "^(\s*)Ciphers\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)Ciphers\s+\S+(\s*#.*)?\s*$/\Ciphers aes256-ctr,aes192-ctr,aes128-ctr\2/" /etc/ssh/sshd_config || echo "Ciphers aes256-ctr,aes192-ctr,aes128-ctr" >> /etc/ssh/sshd_config
# Ensure only approved MAC algorithms are used
echo
echo \*\*\*\* Ensure\ only\ approved\ MAC\ algorithms\ are\ used
egrep -q "^(\s*)MACs\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)MACs\s+\S+(\s*#.*)?\s*$/\MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected]\2/" /etc/ssh/sshd_config || echo "MACs [email protected],[email protected],[email protected],hmac-sha2-512,hmac-sha2-256,[email protected]" >> /etc/ssh/sshd_config
# Ensure SSH Idle Timeout Interval is configured
echo
echo \*\*\*\* Ensure\ SSH\ Idle\ Timeout\ Interval\ is\ configured
egrep -q "^(\s*)ClientAliveInterval\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)ClientAliveInterval\s+\S+(\s*#.*)?\s*$/\1ClientAliveInterval 300\2/" /etc/ssh/sshd_config || echo "ClientAliveInterval 300" >> /etc/ssh/sshd_config
egrep -q "^(\s*)ClientAliveCountMax\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)ClientAliveCountMax\s+\S+(\s*#.*)?\s*$/\1ClientAliveCountMax 3\2/" /etc/ssh/sshd_config || echo "ClientAliveCountMax 3" >> /etc/ssh/sshd_config
# Ensure SSH LoginGraceTime is set to one minute or less
echo
echo \*\*\*\* Ensure\ SSH\ LoginGraceTime\ is\ set\ to\ one\ minute\ or\ less
egrep -q "^(\s*)LoginGraceTime\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)LoginGraceTime\s+\S+(\s*#.*)?\s*$/\1LoginGraceTime 60\2/" /etc/ssh/sshd_config || echo "LoginGraceTime 60" >> /etc/ssh/sshd_config
# Ensure SSH access is limited
echo
echo \*\*\*\* Ensure\ SSH\ access\ is\ limited
echo Ensure\ SSH\ access\ is\ limited not configured.
# Ensure SSH warning banner is configured
echo
echo \*\*\*\* Ensure\ SSH\ warning\ banner\ is\ configured
egrep -q "^(\s*)Banner\s+\S+(\s*#.*)?\s*$" /etc/ssh/sshd_config && sed -ri "s/^(\s*)Banner\s+\S+(\s*#.*)?\s*$/\1Banner \/etc\/issue.net\2/" /etc/ssh/sshd_config || echo "Banner /etc/issue.net" >> /etc/ssh/sshd_config
# Ensure password creation requirements are configured
echo
echo \*\*\*\* Ensure\ password\ creation\ requirements\ are\ configured
egrep -q "^(\s*)minlen\s*=\s*\S+(\s*#.*)?\s*$" /etc/security/pwquality.conf && sed -ri "s/^(\s*)minlen\s*=\s*\S+(\s*#.*)?\s*$/\minlen=9\2/" /etc/security/pwquality.conf || echo "minlen = 9" >> /etc/security/pwquality.conf
egrep -q "^(\s*)dcredit\s*=\s*\S+(\s*#.*)?\s*$" /etc/security/pwquality.conf && sed -ri "s/^(\s*)dcredit\s*=\s*\S+(\s*#.*)?\s*$/\dcredit=-1\2/" /etc/security/pwquality.conf || echo "dcredit = -1" >> /etc/security/pwquality.conf
egrep -q "^(\s*)ucredit\s*=\s*\S+(\s*#.*)?\s*$" /etc/security/pwquality.conf && sed -ri "s/^(\s*)ucredit\s*=\s*\S+(\s*#.*)?\s*$/\ucredit=-1\2/" /etc/security/pwquality.conf || echo "ucredit = -1" >> /etc/security/pwquality.conf
egrep -q "^(\s*)ocredit\s*=\s*\S+(\s*#.*)?\s*$" /etc/security/pwquality.conf && sed -ri "s/^(\s*)ocredit\s*=\s*\S+(\s*#.*)?\s*$/\ocredit=-1\2/" /etc/security/pwquality.conf || echo "ocredit = -1" >> /etc/security/pwquality.conf
egrep -q "^(\s*)lcredit\s*=\s*\S+(\s*#.*)?\s*$" /etc/security/pwquality.conf && sed -ri "s/^(\s*)lcredit\s*=\s*\S+(\s*#.*)?\s*$/\lcredit=-1\2/" /etc/security/pwquality.conf || echo "lcredit = -1" >> /etc/security/pwquality.conf
egrep -q "^\s*password\s+requisite\s+pam_pwquality.so\s+" /etc/pam.d/system-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+try_first_pass)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1try_first_pass \2/ }' /etc/pam.d/system-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+retry=[0-9]+)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1retry=3 \2/ }' /etc/pam.d/system-auth && sed -ri 's/(^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*\s+)retry=[0-9]+(\s+.*)?$/\1retry=3\3/' /etc/pam.d/system-auth || echo Ensure\ password\ creation\ requirements\ are\ configured - /etc/pam.d/system-auth not configured.
egrep -q "^\s*password\s+requisite\s+pam_pwquality.so\s+" /etc/pam.d/password-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+try_first_pass)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1try_first_pass \2/ }' /etc/pam.d/password-auth && sed -ri '/^\s*password\s+requisite\s+pam_pwquality.so\s+/ { /^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*(\s+retry=[0-9]+)(\s+.*)?$/! s/^(\s*password\s+requisite\s+pam_pwquality.so\s+)(.*)$/\1retry=3 \2/ }' /etc/pam.d/password-auth && sed -ri 's/(^\s*password\s+requisite\s+pam_pwquality.so(\s+\S+)*\s+)retry=[0-9]+(\s+.*)?$/\1retry=3\3/' /etc/pam.d/password-auth || echo Ensure\ password\ creation\ requirements\ are\ configured - /etc/pam.d/password-auth not configured.
# echo "password requisite pam_pwquality.so try_first_pass retry=3" >> /etc/pam.d/system-auth
# echo "password requisite pam_pwquality.so try_first_pass retry=3" >> /etc/pam.d/password-auth
# Ensure password reuse is limited
echo
echo \*\*\*\* Ensure\ password\ reuse\ is\ limited
egrep -q "^\s*password\s+sufficient\s+pam_unix.so(\s+.*)$" /etc/pam.d/system-auth && sed -ri '/^\s*password\s+sufficient\s+pam_unix.so\s+/ { /^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*(\s+remember=[0-9]+)(\s+.*)?$/! s/^(\s*password\s+sufficient\s+pam_unix.so\s+)(.*)$/\1remember=5 \2/ }' /etc/pam.d/system-auth && sed -ri 's/(^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*\s+)remember=[0-9]+(\s+.*)?$/\1remember=5\3/' /etc/pam.d/system-auth || echo Ensure\ password\ reuse\ is\ limited - /etc/pam.d/system-auth not configured.
egrep -q "^\s*password\s+sufficient\s+pam_unix.so(\s+.*)$" /etc/pam.d/password-auth && sed -ri '/^\s*password\s+sufficient\s+pam_unix.so\s+/ { /^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*(\s+remember=[0-9]+)(\s+.*)?$/! s/^(\s*password\s+sufficient\s+pam_unix.so\s+)(.*)$/\1remember=5 \2/ }' /etc/pam.d/password-auth && sed -ri 's/(^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*\s+)remember=[0-9]+(\s+.*)?$/\1remember=5\3/' /etc/pam.d/password-auth || echo Ensure\ password\ reuse\ is\ limited - /etc/pam.d/password-auth not configured.
# echo "password sufficient pam_unix.so remember=5" >>/etc/pam.d/password-auth
# echo "password sufficient pam_unix.so remember=5" >>/etc/pam.d/system-auth
# Ensure password hashing algorithm is SHA-512
echo
echo \*\*\*\* Ensure\ password\ hashing\ algorithm\ is\ SHA-512
egrep -q "^\s*password\s+sufficient\s+pam_unix.so\s+" /etc/pam.d/system-auth && sed -ri '/^\s*password\s+sufficient\s+pam_unix.so\s+/ { /^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*(\s+sha512)(\s+.*)?$/! s/^(\s*password\s+sufficient\s+pam_unix.so\s+)(.*)$/\1sha512 \2/ }' /etc/pam.d/system-auth || echo Ensure\ password\ hashing\ algorithm\ is\ SHA-512 - /etc/pam.d/password-auth not configured.
egrep -q "^\s*password\s+sufficient\s+pam_unix.so\s+" /etc/pam.d/password-auth && sed -ri '/^\s*password\s+sufficient\s+pam_unix.so\s+/ { /^\s*password\s+sufficient\s+pam_unix.so(\s+\S+)*(\s+sha512)(\s+.*)?$/! s/^(\s*password\s+sufficient\s+pam_unix.so\s+)(.*)$/\1sha512 \2/ }' /etc/pam.d/password-auth || echo Ensure\ password\ hashing\ algorithm\ is\ SHA-512 - /etc/pam.d/password-auth not configured.
# Ensure minimum days between password changes is 7 or more
echo
echo \*\*\*\* Ensure\ minimum\ days\ between\ password\ changes\ is\ 7\ or\ more
egrep -q "^(\s*)PASS_MIN_DAYS\s+\S+(\s*#.*)?\s*$" /etc/login.defs && sed -ri "s/^(\s*)PASS_MIN_DAYS\s+\S+(\s*#.*)?\s*$/\PASS_MIN_DAYS 7\2/" /etc/login.defs || echo "PASS_MIN_DAYS 7" >> /etc/login.defs
getent passwd | cut -f1 -d ":" | xargs -n1 chage --mindays 7
# Ensure password expiration warning days is 7 or more
echo
echo \*\*\*\* Ensure\ password\ expiration\ warning\ days\ is\ 7\ or\ more
egrep -q "^(\s*)PASS_WARN_AGE\s+\S+(\s*#.*)?\s*$" /etc/login.defs && sed -ri "s/^(\s*)PASS_WARN_AGE\s+\S+(\s*#.*)?\s*$/\PASS_WARN_AGE 7\2/" /etc/login.defs || echo "PASS_WARN_AGE 7" >> /etc/login.defs
getent passwd | cut -f1 -d ":" | xargs -n1 chage --warndays 7
# Ensure inactive password lock is 30 days or less
# No parece una buena política
# echo
# echo \*\*\*\* Ensure\ inactive\ password\ lock\ is\ 30\ days\ or\ less
# useradd -D -f 30
# getent passwd | cut -f1 -d ":" | xargs -n1 chage --inactive 30
# Ensure system accounts are non-login
echo
echo \*\*\*\* Ensure\ system\ accounts\ are\ non-login
for user in `awk -F: '($3 < 1000) {print $1 }' /etc/passwd`; do
if [ $user != "root" ]
then
/usr/sbin/usermod -L $user
if [ $user != "sync" ] && [ $user != "shutdown" ] && [ $user != "halt" ]
then
/usr/sbin/usermod -s /sbin/nologin $user
fi
fi
done
#Ensure default user umask is 027 or more restrictive
echo
echo \*\*\*\* Ensure\ default\ user\ umask\ is\ 027\ or\ more\ restrictive
egrep -q "^(\s*)umask\s+\S+(\s*#.*)?\s*$" /etc/bashrc && sed -ri "s/^(\s*)umask\s+\S+(\s*#.*)?\s*$/\1umask 027\2/" /etc/bashrc || echo "umask 027" >> /etc/bashrc
egrep -q "^(\s*)umask\s+\S+(\s*#.*)?\s*$" /etc/profile && sed -ri "s/^(\s*)umask\s+\S+(\s*#.*)?\s*$/\1umask 027\2/" /etc/profile || echo "umask 027" >> /etc/profile
for i in /etc/profile.d/*.sh
do
egrep -q "^(\s*)umask\s+\S+(\s*#.*)?\s*$" $i && sed -ri "s/^(\s*)umask\s+\S+(\s*#.*)?\s*$/\1umask 027\2/" $i || echo "umask 027" >> $i