-
Notifications
You must be signed in to change notification settings - Fork 1
/
harden_06_rhel5_cis-v1.1.1.sh
311 lines (214 loc) · 8.82 KB
/
harden_06_rhel5_cis-v1.1.1.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/bin/sh
#
# harden_06_rhel5_cis-v1.1.1.sh
##########################################################################
# AUTHOR: Jack Maynard #
# Created: May 10, 2010 - version 1.0 #
# #
# RHEL5 Hardening Script Section 6.0 - Logging #
# Scripted to Center for Internet Security (CIS) RHEL5 Benchmark v1.1.1 #
# www.cisecurity.org #
##########################################################################
# Variable Declarations
# Redirect stdout and stderr to /dev/null, this helps reduce screen noise.
# Change /dev/null to a real file for debugging purposes.
STDOUT_STDERR="/dev/null"
exec &>${STDOUT_STDERR}
##########################################################################
# #
# RHEL5 Benchmark Section 6.0 #
# Logging #
# #
##########################################################################
##########################################################################
# 6.1 - Capture Messages Sent To Syslog AUTHPRIV Facility #
##########################################################################
log_authpriv(){
if [ `grep -v '^#' /etc/syslog.conf | grep -v authpriv\.none | grep -c \
'authpriv'` -eq 0 ]; then
echo -e "authpriv.*\t\t\t\t/var/log/secure" >> /etc/syslog.conf
fi
# Add record for 'auth.*', too, placing it after the authpriv record
if [ `grep -v '^#' /etc/syslog.conf | grep -c 'auth.\*'` -eq 0 ]; then
ed /etc/syslog.conf > /dev/null <<END_SCRIPT
1
/^authpriv
a
auth.* /var/log/messages
.
w
q
END_SCRIPT
fi
chown root:root /etc/syslog.conf
# Original/default permissions are 0644.
chmod 0600 /etc/syslog.conf
# Create the log file if it doesn't already exist.
touch /var/log/secure
chown root:root /var/log/secure
chmod 0600 /var/log/secure
# Restart syslog service to immediately implement the latest configuration.
service syslog stop > /dev/null
service syslog start > /dev/null
}
##########################################################################
# 6.2 - Turn On Additional Logging For FTP Daemon #
##########################################################################
log_ftp(){
FILE=""
if [ -f /etc/vsftpd.conf ]; then
FILE="/etc/vsftpd.conf"
else
FILE="/etc/vsftpd/vsftpd.conf"
fi
if [ -f $FILE ]; then
cp -p ${FILE} ${FILE}.tmp
awk '/^#?xferlog_std_format/ \
{ print "xferlog_std_format=NO"; next };
/^#?log_ftp_protocol/ \
{ print "log_ftp_protocol=YES"; next };
{ print }' ${FILE}.tmp > ${FILE}
rm ${FILE}.tmp
if [ `egrep -c log_ftp_protocol ${FILE}` == 0 ]; then
echo "log_ftp_protocol=YES" >> ${FILE}
fi
chown root:root $FILE
chmod 0600 $FILE
fi
}
##########################################################################
# 6.3 - Confirm Permissions On System Log Files #
##########################################################################
confirm_syslog_perms(){
cd /var/log
# Ensure the btmp log file for 'lastb' is in place,
# and with proper permissions.
touch /var/log/btmp
chown root:root /var/log/btmp
chmod 0600 /var/log/btmp
# Utilizing recursiveness. Harmless when applied to a single file.
# Log Perms - Part 1
for LOG in boot.log* cron* dmesg ksyms* httpd/* maillog* messages* news/* pgsql rpmpkgs* samba/* sa/* scrollkeeper.log secure* spooler* squid/* vbox/* wtmp; do
if [ -e $LOG ]; then
chmod -R o-rwx ${LOG}
fi
done
# Log Perms - Part 2
for LOG in boot.log* cron* maillog* messages* pgsql secure* spooler* squid/* sa/*; do
if [ -e $LOG ]; then
chmod -R o-rx ${LOG}
fi
done
# Log Perms - Part 3
for LOG in boot.log* cron* dmesg httpd/* ksyms* maillog* messages* pgsql rpmpkgs* samba/* sa/* scrollkeeper.log secure* spooler*; do
if [ -e $LOG ]; then
chmod -R g-w ${LOG}
fi
done
# Log Perms - Part 4
for LOG in boot.log* cron* maillog* messages* pgsql secure* spooler*; do
if [ -e $LOG ]; then
chmod -R g-rx ${LOG}
fi
done
# Log Perms - Part 5
for LOG in gdm/ httpd/ news/ samba/ squid/ sa/ vbox/; do
if [ -e $LOG ]; then
chmod -R o-w ${LOG}
fi
done
# Log Perms - Part 6
for LOG in httpd/ samba/ squid/ sa/; do
if [ -e $LOG ]; then
chmod -R o-rx ${LOG}
fi
done
# Log Perms - Part 7
for LOG in gdm/ httpd/ news/ samba/ squid/ sa/ vbox/; do
if [ -e $LOG ]; then
chmod -R g-w ${LOG}
fi
done
# Log Perms - Part 8
for LOG in httpd/ samba/ sa/; do
if [ -e $LOG ]; then
chmod -R g-rx ${LOG}
fi
done
# Log Perms - Part 9
for LOG in kernel syslog loginlog; do
if [ -e $LOG ]; then
chmod -R u-x ${LOG}
fi
done
# Log Perms - Part 10
# Removing group write permissions to btmp and wtmp
chgrp utmp btmp
chmod g-w btmp
chgrp utmp wtmp
chmod g-w wtmp
# Fixing "/etc/rc.d/rc.sysinit", as it unsecures permissions for wtmp.
FILE="/etc/rc.d/rc.sysinit"
if [ -f $FILE ]; then
cp -p ${FILE} ${FILE}.tmp
awk '( $1 == "chmod" && $2 == "0664" && $3 == "/var/run/utmp" && $4 == "/var/log/wtmp" ) {
print "chmod 0600 /var/run/utmp /var/log/wtmp"; next };
( $1 == "chmod" && $2 == "0664" && $3 == "/var/run/utmpx" && $4 == "/var/log/wtmpx" ) {
print " chmod 0600 /var/run/utmpx /var/log/wtmpx"; next };
{ print }' ${FILE}.tmp > ${FILE}
rm ${FILE}.tmp
chown root:root ${FILE}
chmod 0700 ${FILE}
fi
# Log Perms - Part 11
[ -e news ] && chown -R news:news news
[ -e pgsql ] && chown postgres:postgres pgsql
[ -e squid ] && chown -R squid:squid squid
[ -e lastlog ] && chmod 0600 lastlog
[ -e wtmp ] && chgrp utmp wtmp
# Set /var/log ownership and permission
chown root:root .
}
##########################################################################
# 6.4 Configure syslogd to Send Logs to a Remote LogHost #
##########################################################################
remote_syslog(){
LOGHOST="localhost"
printf "# Following 6 lines added per CIS RHEL Benchmark\n\
kern.warning;*.err;authpriv.none\t@$LOGHOST\n\
*.info;mail.none;authpriv.none;cron.none\t@$LOGHOST\n\
*.emerg\t\t@$LOGHOST\n\
auth.*\t\t@$LOGHOST\n\
authpriv.*\t@$LOGHOST\n\
local7.*\t@$LOGHOST\n" >> /etc/syslog.conf
chown root:root /etc/syslog.conf
chmod 0600 /etc/syslog.conf
}
#---------- BEGIN CONFIGURATION ----------#
# TO CHANGE SCRIPT BEHAVIOR ONLY EDIT THE SECTIONS BELOW THIS LINE !!!
##########################################################################
# #
# CONFIGURATION #
# Section 6.0 - Logging #
# #
##########################################################################
##########################################################################
# 6.1 Capture Messages Sent To Syslog AUTHPRIV Facility #
##########################################################################
log_authpriv
##########################################################################
# 6.2 Turn On Additional Logging For FTP Daemon #
##########################################################################
log_ftp
##########################################################################
# 6.3 Confirm Permission On System Log Files #
##########################################################################
confirm_syslog_perms
##########################################################################
# 6.4 Configure syslogd to Send Logs to a Remote LogHost #
##########################################################################
# You MUST configure remote syslog host variable $LOGHOST in function 6.4
remote_syslog
#---------- END CONFIGURATION ----------#
#---------- END SECTION 6 ----------#
#END