forked from sej7278/virt-installs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
centos7_cis.cfg
425 lines (386 loc) · 13.7 KB
/
centos7_cis.cfg
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
# install
cdrom
text
skipx
firstboot --disable
eula --agreed
poweroff
selinux --enforcing # 1.6.1.2, 1.6.1.3
# geography
keyboard --vckeymap=gb --xlayouts='gb'
lang en_GB.UTF-8
timezone Europe/London --isUtc --ntpservers=0.centos.pool.ntp.org,1.centos.pool.ntp.org,2.centos.pool.ntp.org,3.centos.pool.ntp.org # 2.2.1.2
# network
network --bootproto=static --device=eth0 --gateway=192.168.0.1 --ip=192.168.0.91 --netmask=255.255.255.0 --nameserver=192.168.0.1,8.8.8.8 --noipv6 --activate
network --hostname=localhost.localdomain
# users
auth --enableshadow --passalgo=sha512 # 6.3.1
rootpw password
user --name=simon --groups=wheel --password=password # 5.6
# disk
ignoredisk --only-use=sda
bootloader --location=mbr --boot-drive=sda --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH audit=1 net.ifnames=0 biosdevname=0" --password=password # 1.4.2, 4.1.3
clearpart --all --initlabel --drives=sda
part swap --asprimary --fstype="swap" --size=1024
part /boot --fstype xfs --size=200
part pv.01 --size=1 --grow
volgroup vg_root pv.01
logvol / --fstype xfs --name=root --vgname=vg_root --size=5120
logvol /tmp --vgname vg_root --name tmp --size=500 --fsoptions="nodev,nosuid,noexec" # 1.1.2-1.1.5
logvol /var --vgname vg_root --name var --size=500 # 1.1.6
logvol /var/log --vgname vg_root --name varlog --size=1024 # 1.1.11
logvol /var/log/audit --vgname vg_root --name varlogaudit --size=1024 # 1.1.12
logvol /home --vgname vg_root --name home --size=1024 --grow --fsoptions="nodev" # 1.1.13-1.1.14
# packages
%packages
@core
chrony # 2.2.1.1
-ntp
iptables # 3.6.1
iptables-services
net-tools
aide # 1.3.1
tcp_wrappers # 3.4.1
rsyslog # 4.2.3
-setroubleshoot # 1.6.1.4
-mcstrans # 1.6.1.5
-prelink # 1.5.4
-tftp-server # 2.1.6, 2.2.20
-tftp
-xinetd # 2.1.7
-xorg-x11-server-common # 2.2.2
-avahi-daemon # 2.2.3
-cups # 2.2.4
-dhcp # 2.2.5
-openldap # 2.2.6
-openldap-clients # 2.3.5
-bind # 2.2.8
-vsftpd # 2.2.9
-httpd # 2.2.10
-dovecot # 2.2.11
-samba # 2.2.12
-squid # 2.2.13
-ypserv # 2.2.16
-ypbind # 2.3.1
-rsh-server # 2.2.17
-rsh # 2.3.2
-talk-server # 2.2.18
-talk # 2.3.3
-telnet-server # 2.2.19
-telnet # 2.3.4
-rsync # 2.2.21
-autofs # 1.1.22
-wpa_supplicant # 3.7
-b43-openfwwf
-iwl*firmware
%end
# services
services --enabled=chronyd,auditd,rsyslog,crond,sshd,iptables # 2.2.1.1, 4.1.2, 4.2.1, 5.1.1, 3.6.1
services --disabled=postfix,rhnsd,nfs,nfs-server,rpcbind,firewalld # 1.1.22, 1.2.5, 2.2.7, 2.2.14, 2.2.15
firewall --disabled
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
%post
# enable trim for ssd
systemctl enable fstrim.timer
# 1.1.1, 1.1.18-1.1.20, 3.5.1-3.5.4
cat << EOF > /etc/modprobe.d/cis.conf
install cramfs /bin/true
install freevxfs /bin/true
install jffs2 /bin/true
install hfs /bin/true
install hfsplus /bin/true
install squashfs /bin/true
install udf /bin/true
install dccp /bin/true
install sctp /bin/true
install rds /bin/true
install tipc /bin/true
blacklist sr_mod
install sr_mod /bin/true
blacklist cdrom
install cdrom /bin/true
blacklist usb_storage
install usb-storage /bin/true
EOF
# 1.1.7-1.1.10, 1.1.15-1.1.17
cat << EOF >> /etc/fstab
/tmp /var/tmp none bind 0 0
tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0
EOF
# 1.2.3
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 1.2.2
sed -i 's/gpgcheck=.*$/gpgcheck=1/' /etc/yum.conf
sed -i 's/gpgcheck=.*$/gpgcheck=1/g' /etc/yum.repos.d/*
# 1.4.1
chown root:root /boot/grub2/grub.cfg
chmod 600 /boot/grub2/grub.cfg
chmod 600 /boot/grub2/user.cfg
# 1.5.1
echo '* hard core 0' >> /etc/security/limits.conf
# 1.7.1.1-1.7.1.5-6
echo 'PrintMotd no' >> /etc/ssh/sshd_config
echo 'Banner /etc/issue' >> /etc/ssh/sshd_config
cat /dev/null > /etc/motd
cat /dev/null > /etc/issue.net
echo 'Authorized uses only. All activity may be monitored and reported.' > /etc/issue
chown root:root /etc/motd
chown root:root /etc/issue
chown root:root /etc/issue.net
chmod 644 /etc/motd
chmod 644 /etc/issue
chmod 644 /etc/issue.net
# 1.7.2 - bit pointless on headless server
cat << EOF > /etc/dconf/profile/gdm
user-db:user
system-db:gdm
file-db:/usr/share/gdm/greeter-dconf-defaults
EOF
cat << EOF > /etc/dconf/db/gdm.d/01-banner-message
[org/gnome/login-screen]
banner-message-enable=true
banner-message-text='Authorized uses only. All activity may be monitored and reported.'
EOF
# 2.2.1.3
sed -i 's/OPTIONS=.*$/OPTIONS="-4 -u chrony"/' /etc/sysconfig/chronyd
# 1.5.3, 3.1.1, 3.1.2, 3.2.1-3.3.3
cat << EOF > /etc/sysctl.d/cis.conf
kernel.randomize_va_space = 2
net.ipv4.ip_forward = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.lo.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv6.conf.lo.accept_redirects = 0
net.ipv6.conf.eth0.accept_redirects = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
net.ipv4.conf.eth0.secure_redirects = 0
net.ipv4.conf.lo.secure_redirects = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.default.log_martians = 1
net.ipv4.conf.lo.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.tcp_syncookies = 1
net.ipv6.conf.all.accept_ra = 0
net.ipv6.conf.default.accept_ra = 0
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv4.tcp_timestamps = 0
kernel.sysrq = 0
fs.suid_dumpable = 0
net.ipv4.tcp_max_syn_backlog = 4096
net.ipv4.tcp_max_orphans = 256
net.ipv4.conf.all.proxy_arp = 0
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.lo.proxy_arp = 0
EOF
# 3.4.2-3.4.5
echo "ALL: 192.168.0.0/255.255.255.0" > /etc/hosts.allow
echo "ALL: ALL" > /etc/hosts.deny
chown root:root /etc/hosts.allow
chmod 644 /etc/hosts.allow
chown root:root /etc/hosts.deny
chmod 644 /etc/hosts.deny
# 3.6.2-3.6.5
cat << EOF > /etc/sysconfig/iptables
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -j ACCEPT
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
-A INPUT -s 127.0.0.1 -d 127.0.0.1 -i lo -j ACCEPT
-A INPUT -j DROP
COMMIT
EOF
# 4.1.1.1-4.1.1.3
sed -i 's/^max_log_file .*$/max_log_file 1024/' /etc/audit/auditd.conf
sed -i 's/^space_left_action.*$/space_left_action email/' /etc/audit/auditd.conf
sed -i 's/^action_mail_acct.*$/action_mail_acct root/' /etc/audit/auditd.conf
sed -i 's/^admin_space_left_action.*$/admin_space_left_action halt/' /etc/audit/auditd.conf
sed -i 's/^max_log_file_action.*$/max_log_file_action keep_logs/' /etc/audit/auditd.conf
# 4.1.4-4.1.18
cat << EOF > /etc/audit/rules.d/cis.rules
-a always,exit -F arch=b64 -S adjtimex -S settimeofday -k time-change
-a always,exit -F arch=b32 -S adjtimex -S settimeofday -S stime -k time-change
-a always,exit -F arch=b64 -S clock_settime -k time-change
-a always,exit -F arch=b32 -S clock_settime -k time-change
-w /etc/localtime -p wa -k time-change
-w /etc/group -p wa -k identity
-w /etc/passwd -p wa -k identity
-w /etc/gshadow -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/security/opasswd -p wa -k identity
-a always,exit -F arch=b64 -S sethostname -S setdomainname -k system-locale
-a always,exit -F arch=b32 -S sethostname -S setdomainname -k system-locale
-w /etc/issue -p wa -k system-locale
-w /etc/issue.net -p wa -k system-locale
-w /etc/hosts -p wa -k system-locale
-w /etc/sysconfig/network -p wa -k system-locale
-w /etc/sysconfig/network-scripts/ -p wa -k system-locale
-w /etc/selinux/ -p wa -k MAC-policy
-w /usr/share/selinux/ -p wa -k MAC-policy
-w /var/log/faillog -p wa -k logins
-w /var/log/tallylog -p wa -k logins
-w /var/log/lastlog -p wa -k logins
-w /var/run/faillock/ -p wa -k logins
-w /var/run/utmp -p wa -k session
-w /var/log/wtmp -p wa -k logins
-w /var/log/btmp -p wa -k logins
-a always,exit -F arch=b64 -S chmod -S fchmod -S fchmodat -F auid>=1000 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b32 -S chmod -S fchmod -S fchmodat -F auid>=1000 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -F auid>=1000 -F auid!=4294967295 -k perm_mod
-a always,exit -F arch=b32 -S chown -S fchown -S fchownat -S lchown -F auid>=1000 -F auid!=4294967295 -k perm_mod
-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
-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
-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
-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
-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
-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
-a always,exit -F arch=b64 -S mount -F auid>=1000 -F auid!=4294967295 -k mounts
-a always,exit -F arch=b32 -S mount -F auid>=1000 -F auid!=4294967295 -k mounts
-a always,exit -F arch=b64 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 \ -F auid!=4294967295 -k delete
-a always,exit -F arch=b32 -S unlink -S unlinkat -S rename -S renameat -F auid>=1000 \ -F auid!=4294967295 -k delete
-w /etc/sudoers -p wa -k scope
-w /etc/sudoers.d/ -p wa -k scope
-w /var/log/sudo.log -p wa -k actions
-w /sbin/insmod -p x -k modules
-w /sbin/rmmod -p x -k modules
-w /sbin/modprobe -p x -k modules
-a always,exit -F arch=b64 -S init_module -S delete_module -k modules
-e 2
EOF
# 4.2.1.3, 4.2.4
echo '$FileCreateMode 0640' > /etc/rsyslog.d/cis.conf
chown root:root /etc/rsyslog.conf /etc/rsyslog.d/*.conf
chmod 600 /etc/rsyslog.conf /etc/rsyslog.d/*.conf
# 5.1.2-5.1.8
rm /etc/cron.deny /etc/at.deny
touch /etc/at.allow /etc/cron.allow
chown root:root /etc/*cron* /etc/at.allow
chmod 600 /etc/anacrontab /etc/crontab /etc/cron.allow /etc/at.allow
chmod 700 /etc/cron.hourly /etc/cron.daily /etc/cron.weekly /etc/cron.monthly /etc/cron.d
# 5.2.1-5.2.15
cat <<EOF > /etc/ssh/sshd_config
AddressFamily inet
ListenAddress 192.168.0.91
Protocol 2
AllowUsers simon
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
MACs [email protected],[email protected],hmac-sha2-256,hmac-sha2-512
Ciphers aes256-ctr,[email protected]
KexAlgorithms [email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512
SyslogFacility AUTHPRIV
LogLevel INFO
LoginGraceTime 1m
PermitRootLogin no
StrictModes yes
MaxAuthTries 3
PermitEmptyPasswords no
HostbasedAuthentication no
IgnoreRhosts yes
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials no
UsePAM yes
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
PrintMotd no
PrintLastLog yes
PermitTunnel no
UseDNS no
Banner /etc/issue
PermitUserEnvironment no
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
Subsystem sftp /usr/libexec/openssh/sftp-server
ClientAliveInterval 300
ClientAliveCountMax 0
EOF
chown root:root /etc/ssh/sshd_config
chmod 600 /etc/ssh/sshd_config
# 5.3.1-5.3.4
authconfig --enablefaillock --passminlen=14 --passalgo=sha512 --enablereqlower --enablerequpper --enablereqdigit --enablereqother --faillockargs='unlock_time=900 audit deny=3' --update
sed -i 's/^password.*sufficient.*pam_unix.*$/password sufficient pam_unix.so remember=5/' /etc/pam.d/system-auth
sed -i 's/^password.*sufficient.*pam_unix.*$/password sufficient pam_unix.so remember=5/' /etc/pam.d/password-auth
# 5.4.1.1-5.4.1.3
sed -i 's/^PASS_MAX_DAYS.*$/PASS_MAX_DAYS 90/' /etc/login.defs
sed -i 's/^PASS_MIN_DAYS.*$/PASS_MIN_DAYS 7/' /etc/login.defs
sed -i 's/^PASS_WARN_AGE.*$/PASS_WARN_AGE 7/' /etc/login.defs
# 5.4.3
usermod -g 0 root
# 5.4.4
sed -i 's/umask.*$/umask 027/g' /etc/profile
sed -i 's/umask.*$/umask 027/g' /etc/bashrc
sed -i 's/umask.*$/umask 027/g' /etc/csh.cshrc
# 5.4.5
cat << EOF > /etc/profile.d/cis.sh
test -t 0 && mesg n
umask 027
readonly TMOUT=600
export TMOUT
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
EOF
cat << EOF > /etc/profile.d/cis.csh
mesg n 2>/dev/null
umask 027
set autologout=10
set -r autologout=10
setenv PATH /sbin:/bin:/usr/sbin:/usr/bin
EOF
# 5.5
cat << EOF > /etc/securetty
console
EOF
# 5.6
sed -i 's/^auth.*required.*pam_wheel.so.*$/auth required pam_wheel.so use_uid/' /etc/pam.d/su
# 6.1.2-6.1.9
chmod 644 /etc/passwd
chmod 644 /etc/passwd-
chmod 000 /etc/shadow
chmod 000 /etc/shadow-
chmod 000 /etc/gshadow
chmod 000 /etc/gshadow-
chmod 644 /etc/group
chmod 644 /etc/group-
chown root:root /etc/passwd
chown root:root /etc/passwd-
chown root:root /etc/shadow
chown root:root /etc/shadow-
chown root:root /etc/gshadow
chown root:root /etc/gshadow-
chown root:root /etc/group
chown root:root /etc/group-
# 6.2.6
sed -i 's/^PATH.*$/PATH=\$PATH/' /root/.bash_profile
sed -i 's/^PATH.*$/PATH=\$PATH/' /home/simon/.bash_profile
sed -i 's/^PATH.*$/PATH=\$PATH/' /etc/skel/.bash_profile
# 6.2.8-6.2.14
chmod 700 /home/simon
chown simon:simon /home/simon
rm /home/simon/.forward
rm /home/simon/.netrc
rm /home/simon/.rhosts
# 1.8
yum -y update
# 1.3.2 - do at end of kickstart
echo "0 5 * * * /usr/sbin/aide --check" >> /var/spool/cron/root
/usr/sbin/aide --init -B 'database_out=file:/var/lib/aide/aide.db.gz'
%end