blob: 4761dc270850da0305140e2f36ad1e005a0fe6d4 (
plain)
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
|
#!/bin/bash
#
# Written by Vandoorselaere Yoann
#
if [[ -f /etc/security/msec/security.conf ]]; then
. /etc/security/msec/security.conf
else
echo "/etc/security/msec/security.conf don't exist."
exit 1
fi
if [[ ${CHECK_SECURITY} == no ]]; then
exit 0
fi
SECURITY_LOG="/var/log/security.log"
TMP=`mktemp /tmp/secure.XXXXXX`
### New Suid root files detection
if [[ ${CHECK_SUID_ROOT} == yes ]]; then
if [[ -f ${SUID_ROOT_YESTERDAY} ]]; then
if ! diff -u ${SUID_ROOT_YESTERDAY} ${SUID_ROOT_TODAY} > ${SUID_ROOT_DIFF}; then
printf "\nSecurity Warning: Change in Suid Root files found :\n" >> ${TMP}
grep '^+' ${SUID_ROOT_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly added suid root file : ${file}\n"
done >> ${TMP}
grep '^-' ${SUID_ROOT_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer present suid root file : ${file}\n"
done >> ${TMP}
fi
fi
fi
### New Sgid files detection
if [[ ${CHECK_SGID} == yes ]]; then
if [[ -f ${SGID_YESTERDAY} ]]; then
if ! diff -u ${SGID_YESTERDAY} ${SGID_TODAY} > ${SGID_DIFF}; then
printf "\nSecurity Warning: Changes in Sgid files found :\n" >> ${TMP}
grep '^+' ${SGID_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly added sgid file : ${file}\n"
done >> ${TMP}
grep '^-' ${SGID_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer present sgid file : ${file}\n"
done >> ${TMP}
fi
fi
fi
### Writable files detection
if [[ ${CHECK_WRITABLE} == yes ]]; then
if [[ -f ${WRITABLE_YESTERDAY} ]]; then
diff -u ${WRITABLE_YESTERDAY} ${WRITABLE_TODAY} > ${WRITABLE_DIFF}
if [ -s ${WRITABLE_DIFF} ]; then
printf "\nSecurity Warning: Change in World Writable Files found :\n" >> ${TMP}
grep '^+' ${WRITABLE_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly added writable file : ${file}\n"
done >> ${TMP}
grep '^-' ${WRITABLE_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer present writable file : ${file}\n"
done >> ${TMP}
fi
fi
fi
### Search Non Owned files
if [[ ${CHECK_UNOWNED} == yes ]]; then
if [[ -f ${UNOWNED_USER_YESTERDAY} ]]; then
diff -u ${UNOWNED_USER_YESTERDAY} ${UNOWNED_USER_TODAY} > ${UNOWNED_USER_DIFF}
if [ -s ${UNOWNED_USER_DIFF} ]; then
printf "\nSecurity Warning: the following files aren't owned by an user :\n" >> ${TMP}
grep '^+' ${UNOWNED_USER_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly added un-owned file : ${file}\n"
done >> ${TMP}
grep '^-' ${UNOWNED_USER_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer present un-owned file : ${file}\n"
done >> ${TMP}
fi
fi
if [[ -f ${UNOWNED_GROUP_YESTERDAY} ]]; then
diff -u ${UNOWNED_GROUP_YESTERDAY} ${UNOWNED_GROUP_TODAY} > ${UNOWNED_GROUP_DIFF}
if [ -s ${UNOWNED_GROUP_DIFF} ]; then
printf "\nSecurity Warning: the following files aren't owned by a group :\n" >> ${TMP}
grep '^+' ${UNOWNED_GROUP_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly added un-owned file : ${file}\n"
done >> ${TMP}
grep '^-' ${UNOWNED_GROUP_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer present un-owned file : ${file}\n"
done >> ${TMP}
fi
fi
fi
### Md5 check for SUID root fileg
if [[ ${CHECK_SUID_MD5} == yes ]]; then
ctrl_md5=0;
if [[ -f ${SUID_MD5_YESTERDAY} ]]; then
diff -u ${SUID_MD5_YESTERDAY} ${SUID_MD5_TODAY} > ${SUID_MD5_DIFF}
if [ -s ${SUID_MD5_DIFF} ]; then
grep '^+' ${SUID_MD5_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | awk '{print $2}' | while read file; do
if cat ${SUID_MD5_YESTERDAY} | awk '{print $2}' | grep -qw ${file}; then
if [[ ${ctrl_md5} == 0 ]]; then
printf "\nSecurity Warning: the md5 checksum for one of your SUID files has changed,\n" >> ${TMP}
printf "\tmaybe an intruder modified one of these suid binary in order to put in a backdoor...\n" >> ${TMP}
ctrl_md5=1;
fi
printf "\t\t- Checksum changed file : ${file}\n"
fi
done >> ${TMP}
fi
fi
fi
### Changed open port
if [[ ${CHECK_OPEN_PORT} == yes ]]; then
if [[ -f ${OPEN_PORT_YESTERDAY} ]]; then
diff -u ${OPEN_PORT_YESTERDAY} ${OPEN_PORT_TODAY} 1> ${OPEN_PORT_DIFF}
if [ -s ${OPEN_PORT_DIFF} ]; then
printf "\nSecurity Warning: There are modifications for port listening on your machine :\n" >> ${TMP}
grep '^+' ${OPEN_PORT_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Opened ports : ${file}\n"
done >> ${TMP}
grep '^-' ${OPEN_PORT_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Closed ports : ${file}\n"
done >> ${TMP}
fi
fi
fi
### Changed firewall
if [[ ${CHECK_FIREWALL} == yes ]]; then
if [[ -f ${FIREWALL_YESTERDAY} ]]; then
diff -u ${FIREWALL_YESTERDAY} ${FIREWALL_TODAY} 1> ${FIREWALL_DIFF}
if [ -s ${FIREWALL_DIFF} ]; then
printf "\nSecurity Warning: There are modifications for firewall configuration on your machine :\n" >> ${TMP}
grep '^+' ${FIREWALL_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- New entries : ${file}\n"
done >> ${TMP}
grep '^-' ${FIREWALL_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Removed entries : ${file}\n"
done >> ${TMP}
fi
fi
fi
### rpm database
if [[ ${CHECK_RPM} == yes ]]; then
if [[ -f ${RPM_QA_YESTERDAY} ]]; then
diff -u ${RPM_QA_YESTERDAY} ${RPM_QA_TODAY} > ${RPM_QA_DIFF}
if [ -s ${RPM_QA_DIFF} ]; then
printf "\nSecurity Warning: These packages have changed on the system :\n" >> ${TMP}
grep '^+' ${RPM_QA_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly installed package : ${file}\n"
done >> ${TMP}
grep '^-' ${RPM_QA_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer present package : ${file}\n"
done >> ${TMP}
fi
fi
if [[ -f ${RPM_VA_YESTERDAY} ]]; then
diff -u ${RPM_VA_YESTERDAY} ${RPM_VA_TODAY} > ${RPM_VA_DIFF}
if [ -s ${RPM_VA_DIFF} ]; then
printf "\nSecurity Warning: These files belonging to packages have changed of status on the system :\n" >> ${TMP}
grep '^+' ${RPM_VA_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly modified : ${file}\n"
done >> ${TMP}
grep '^-' ${RPM_VA_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer modified : ${file}\n"
done >> ${TMP}
fi
fi
if [[ -f ${RPM_VA_CONFIG_YESTERDAY} ]]; then
diff -u ${RPM_VA_CONFIG_YESTERDAY} ${RPM_VA_CONFIG_TODAY} > ${RPM_VA_CONFIG_DIFF}
if [ -s ${RPM_VA_CONFIG_DIFF} ]; then
printf "\nSecurity Warning: These config files belonging to packages have changed of status on the system :\n" >> ${TMP}
grep '^+' ${RPM_VA_CONFIG_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Newly modified : ${file}\n"
done >> ${TMP}
grep '^-' ${RPM_VA_CONFIG_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- No longer modified : ${file}\n"
done >> ${TMP}
fi
fi
fi
### Changed chkrootkit
if [[ ${CHECK_CHKROOTKIT} == yes ]]; then
if [[ -f ${CHKROOTKIT_YESTERDAY} ]]; then
diff -u ${CHKROOTKIT_YESTERDAY} ${CHKROOTKIT_TODAY} 1> ${CHKROOTKIT_DIFF}
if [ -s ${CHKROOTKIT_DIFF} ]; then
printf "\nSecurity Warning: There are modifications for chkrootkit results :\n" >> ${TMP}
grep '^+' ${CHKROOTKIT_DIFF} | grep -vw "^+++ " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Added : ${file}\n"
done >> ${TMP}
grep '^-' ${CHKROOTKIT_DIFF} | grep -vw "^--- " | sed 's|^.||'|sed -e 's/%/%%/g' | while read file; do
printf "\t\t- Removed : ${file}\n"
done >> ${TMP}
fi
fi
fi
######## Report ######
date=`date`
hostname=`hostname`
if [[ -s ${TMP} ]]; then
Syslog ${TMP}
Ttylog ${TMP}
echo -e "\n\n*** Diff Check, ${date} ***\n" >> ${SECURITY_LOG}
cat ${TMP} >> ${SECURITY_LOG}
Notifylog "MSEC has performed Diff Check on ${hostname} on ${date}. Changes in system security were detected and are available in ${SECURITY_LOG}."
else
Notifylog "MSEC has performed Diff Check on ${hostname} on ${date}. No changes were detected in system security."
fi
Maillog "[msec] *** Diff Check on ${hostname}, ${date} ***" "${TMP}"
if [[ -f ${TMP} ]]; then
rm -f ${TMP}
fi
|