1 | #! /bin/sh
|
---|
2 |
|
---|
3 | BUILDOPTS="--quiet $TRUST --enable-xml-log --enable-suidcheck --prefix=$PW_DIR --localstatedir=$PW_DIR --with-config-file=$RCFILE --with-log-file=$LOGFILE --with-pid-file=$PW_DIR/.samhain_lock --with-data-file=$PW_DIR/.samhain_file"
|
---|
4 | export BUILDOPTS
|
---|
5 |
|
---|
6 | MAXTEST=6; export MAXTEST
|
---|
7 |
|
---|
8 | ## Quarantine SUID/SGID files if found
|
---|
9 | #
|
---|
10 | # SuidCheckQuarantineFiles = yes
|
---|
11 |
|
---|
12 | ## Method for Quarantining files:
|
---|
13 | # 0 - Delete or truncate the file.
|
---|
14 | # 1 - Remove SUID/SGID permissions from file.
|
---|
15 | # 2 - Move SUID/SGID file to quarantine dir.
|
---|
16 | #
|
---|
17 | # SuidCheckQuarantineMethod = 0
|
---|
18 |
|
---|
19 | ## For method 0 and 2, really delete instead of truncating
|
---|
20 | #
|
---|
21 | # SuidCheckQuarantineDelete = yes
|
---|
22 |
|
---|
23 | SUIDPOLICY_6="
|
---|
24 | [ReadOnly]
|
---|
25 | file=${BASE}
|
---|
26 | [SuidCheck]
|
---|
27 | SuidCheckActive = yes
|
---|
28 | SuidCheckInterval = 10
|
---|
29 | SeveritySuidCheck = crit
|
---|
30 | SuidCheckQuarantineFiles = no
|
---|
31 | SuidCheckQuarantineMethod = 2
|
---|
32 | SuidCheckQuarantineDelete = yes
|
---|
33 | "
|
---|
34 |
|
---|
35 | mod_suiddata_6 () {
|
---|
36 | sleep 1
|
---|
37 | chmod 4755 "${BASE}/a/a/y"
|
---|
38 | }
|
---|
39 |
|
---|
40 | chk_suiddata_6 () {
|
---|
41 | sleep 1
|
---|
42 | tmp=`ls -l "${BASE}/a/a/y" 2>/dev/null | awk '{ print $1}'`
|
---|
43 | if [ "x$tmp" = "x-rwsr-xr-x" ]; then
|
---|
44 | egrep "CRIT.*POLICY \[SuidCheck\].*${BASE}/a/a/y" $LOGFILE >/dev/null 2>&1
|
---|
45 | if [ $? -ne 0 ]; then
|
---|
46 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y";
|
---|
47 | return 1
|
---|
48 | fi
|
---|
49 | egrep "CRIT.*POLICY ADDED.*${BASE}/a/a/y" $LOGFILE >/dev/null 2>&1
|
---|
50 | if [ $? -ne 0 ]; then
|
---|
51 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y";
|
---|
52 | return 1
|
---|
53 | fi
|
---|
54 | return 0;
|
---|
55 | else
|
---|
56 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (suid not kept)";
|
---|
57 | return 1
|
---|
58 | fi
|
---|
59 | }
|
---|
60 |
|
---|
61 | SUIDPOLICY_5="
|
---|
62 | [ReadOnly]
|
---|
63 | file=${BASE}
|
---|
64 | [SuidCheck]
|
---|
65 | SuidCheckActive = yes
|
---|
66 | SuidCheckInterval = 10
|
---|
67 | SeveritySuidCheck = crit
|
---|
68 | SuidCheckQuarantineFiles = yes
|
---|
69 | SuidCheckQuarantineMethod = 2
|
---|
70 | SuidCheckQuarantineDelete = yes
|
---|
71 | "
|
---|
72 |
|
---|
73 | mod_suiddata_5 () {
|
---|
74 | sleep 1
|
---|
75 | chmod 4755 "${BASE}/a/a/y"
|
---|
76 | }
|
---|
77 |
|
---|
78 | chk_suiddata_5 () {
|
---|
79 | sleep 1
|
---|
80 | if [ -f "${BASE}/a/a/y" ]; then
|
---|
81 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (not deleted)";
|
---|
82 | return 1
|
---|
83 | fi
|
---|
84 | if [ -f .quarantine/y ]; then
|
---|
85 | if [ -f .quarantine/y.info ]; then
|
---|
86 | return 0;
|
---|
87 | else
|
---|
88 | [ -z "$verbose" ] || log_msg_fail ".quarantine/y.info (missing)";
|
---|
89 | return 1
|
---|
90 | fi
|
---|
91 | else
|
---|
92 | [ -z "$verbose" ] || log_msg_fail ".quarantine/y (missing)";
|
---|
93 | return 1
|
---|
94 | fi
|
---|
95 | }
|
---|
96 |
|
---|
97 | SUIDPOLICY_4="
|
---|
98 | [ReadOnly]
|
---|
99 | file=${BASE}
|
---|
100 | [SuidCheck]
|
---|
101 | SuidCheckActive = yes
|
---|
102 | SuidCheckInterval = 10
|
---|
103 | SeveritySuidCheck = crit
|
---|
104 | SuidCheckQuarantineFiles = yes
|
---|
105 | SuidCheckQuarantineMethod = 2
|
---|
106 | SuidCheckQuarantineDelete = no
|
---|
107 | "
|
---|
108 |
|
---|
109 | mod_suiddata_4 () {
|
---|
110 | sleep 1
|
---|
111 | chmod 4755 "${BASE}/a/a/y"
|
---|
112 | }
|
---|
113 |
|
---|
114 | chk_suiddata_4 () {
|
---|
115 | sleep 1
|
---|
116 | tmp=`cat "${BASE}/a/a/y" 2>/dev/null | wc -c`
|
---|
117 | if [ $tmp -ne 0 ]; then
|
---|
118 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (not truncated)";
|
---|
119 | return 1
|
---|
120 | fi
|
---|
121 | if [ -f .quarantine/y ]; then
|
---|
122 | if [ -f .quarantine/y.info ]; then
|
---|
123 | return 0;
|
---|
124 | else
|
---|
125 | [ -z "$verbose" ] || log_msg_fail ".quarantine/y.info (missing)";
|
---|
126 | return 1
|
---|
127 | fi
|
---|
128 | else
|
---|
129 | [ -z "$verbose" ] || log_msg_fail ".quarantine/y (missing)";
|
---|
130 | return 1
|
---|
131 | fi
|
---|
132 | }
|
---|
133 |
|
---|
134 | SUIDPOLICY_3="
|
---|
135 | [ReadOnly]
|
---|
136 | file=${BASE}
|
---|
137 | [SuidCheck]
|
---|
138 | SuidCheckActive = yes
|
---|
139 | SuidCheckInterval = 10
|
---|
140 | SeveritySuidCheck = crit
|
---|
141 | SuidCheckQuarantineFiles = yes
|
---|
142 | SuidCheckQuarantineMethod = 1
|
---|
143 | SuidCheckQuarantineDelete = no
|
---|
144 | "
|
---|
145 |
|
---|
146 | mod_suiddata_3 () {
|
---|
147 | sleep 1
|
---|
148 | chmod 4755 "${BASE}/a/a/y"
|
---|
149 | }
|
---|
150 |
|
---|
151 | chk_suiddata_3 () {
|
---|
152 | sleep 1
|
---|
153 | tmp=`ls -l "${BASE}/a/a/y" 2>/dev/null | awk '{ print $1}'`
|
---|
154 | if [ "x$tmp" = "x-rwxr-xr-x" ]; then
|
---|
155 | return 0;
|
---|
156 | else
|
---|
157 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (suid not removed)";
|
---|
158 | return 1
|
---|
159 | fi
|
---|
160 | }
|
---|
161 |
|
---|
162 | SUIDPOLICY_2="
|
---|
163 | [ReadOnly]
|
---|
164 | file=${BASE}
|
---|
165 | [SuidCheck]
|
---|
166 | SuidCheckActive = yes
|
---|
167 | SuidCheckInterval = 10
|
---|
168 | SeveritySuidCheck = crit
|
---|
169 | SuidCheckQuarantineFiles = yes
|
---|
170 | SuidCheckQuarantineMethod = 0
|
---|
171 | SuidCheckQuarantineDelete = no
|
---|
172 | "
|
---|
173 |
|
---|
174 | mod_suiddata_2 () {
|
---|
175 | sleep 1
|
---|
176 | chmod 4755 "${BASE}/a/a/y"
|
---|
177 | }
|
---|
178 |
|
---|
179 | chk_suiddata_2 () {
|
---|
180 | sleep 1
|
---|
181 | tmp=`cat "${BASE}/a/a/y" 2>/dev/null | wc -c`
|
---|
182 | if [ $tmp -ne 0 ]; then
|
---|
183 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (not truncated)";
|
---|
184 | return 1
|
---|
185 | fi
|
---|
186 | }
|
---|
187 |
|
---|
188 | SUIDPOLICY_1="
|
---|
189 | [ReadOnly]
|
---|
190 | file=${BASE}
|
---|
191 | [SuidCheck]
|
---|
192 | SuidCheckActive = yes
|
---|
193 | SuidCheckInterval = 10
|
---|
194 | SeveritySuidCheck = crit
|
---|
195 | SuidCheckQuarantineFiles = yes
|
---|
196 | SuidCheckQuarantineMethod = 0
|
---|
197 | SuidCheckQuarantineDelete = yes
|
---|
198 | "
|
---|
199 |
|
---|
200 | mod_suiddata_1 () {
|
---|
201 | sleep 1
|
---|
202 | chmod 4755 "${BASE}/a/a/y"
|
---|
203 | }
|
---|
204 |
|
---|
205 | chk_suiddata_1 () {
|
---|
206 | sleep 1
|
---|
207 | if [ -f "${BASE}/a/a/y" ]; then
|
---|
208 | [ -z "$verbose" ] || log_msg_fail "${BASE}/a/a/y (not removed)";
|
---|
209 | return 1
|
---|
210 | fi
|
---|
211 | }
|
---|
212 |
|
---|
213 | prep_suidpolicy ()
|
---|
214 | {
|
---|
215 | test -f "${RCFILE}" || touch "${RCFILE}"
|
---|
216 | eval echo '"$'"SUIDPOLICY_$1"'"' >>"${RCFILE}"
|
---|
217 | }
|
---|
218 |
|
---|
219 | testrun_internal_1c ()
|
---|
220 | {
|
---|
221 | [ -z "$verbose" ] || echo Working directory: $PW_DIR
|
---|
222 | [ -z "$verbose" ] || { echo MAKE is $MAKE; echo; }
|
---|
223 |
|
---|
224 | #
|
---|
225 | # test standalone compilation
|
---|
226 | #
|
---|
227 | [ -z "$verbose" ] || { echo; echo "${S}Building standalone agent${E}"; echo; }
|
---|
228 |
|
---|
229 | if test -r "Makefile"; then
|
---|
230 | $MAKE distclean >/dev/null
|
---|
231 | fi
|
---|
232 |
|
---|
233 | ${TOP_SRCDIR}/configure ${BUILDOPTS}
|
---|
234 |
|
---|
235 | #
|
---|
236 | if test x$? = x0; then
|
---|
237 | [ -z "$verbose" ] || log_msg_ok "configure...";
|
---|
238 | $MAKE 'DBGDEF=-DSH_SUIDTESTDIR=\"${BASE}\"' >/dev/null
|
---|
239 | if test x$? = x0; then
|
---|
240 | [ -z "$verbose" ] || log_msg_ok "make...";
|
---|
241 | else
|
---|
242 | [ -z "$quiet" ] && log_msg_fail "make...";
|
---|
243 | return 1
|
---|
244 | fi
|
---|
245 |
|
---|
246 | else
|
---|
247 | [ -z "$quiet" ] && log_msg_fail "configure...";
|
---|
248 | return 1
|
---|
249 | fi
|
---|
250 |
|
---|
251 | [ -z "$verbose" ] || { echo; echo "${S}Running test suite${E}"; echo; }
|
---|
252 |
|
---|
253 | tcount=1
|
---|
254 | POLICY=`eval echo '"$'"SUIDPOLICY_$tcount"'"'`
|
---|
255 |
|
---|
256 | until [ -z "$POLICY" ]
|
---|
257 | do
|
---|
258 | prep_init
|
---|
259 | check_err $? ${tcount}; errval=$?
|
---|
260 | if [ $errval -eq 0 ]; then
|
---|
261 | prep_testdata
|
---|
262 | check_err $? ${tcount}; errval=$?
|
---|
263 | fi
|
---|
264 | if [ $errval -eq 0 ]; then
|
---|
265 | prep_suidpolicy ${tcount}
|
---|
266 | check_err $? ${tcount}; errval=$?
|
---|
267 | fi
|
---|
268 | if [ $errval -eq 0 ]; then
|
---|
269 | run_init
|
---|
270 | check_err $? ${tcount}; errval=$?
|
---|
271 | fi
|
---|
272 | if [ $errval -eq 0 ]; then
|
---|
273 | eval mod_suiddata_${tcount}
|
---|
274 | check_err $? ${tcount}; errval=$?
|
---|
275 | fi
|
---|
276 | if [ $errval -eq 0 ]; then
|
---|
277 | run_check
|
---|
278 | check_err $? ${tcount}; errval=$?
|
---|
279 | fi
|
---|
280 | if [ $errval -eq 0 ]; then
|
---|
281 | eval chk_suiddata_${tcount}
|
---|
282 | check_err $? ${tcount}; errval=$?
|
---|
283 | fi
|
---|
284 | if [ $testrun1_setup -eq 0 ]; then
|
---|
285 | if [ $errval -eq 0 ]; then
|
---|
286 | run_update
|
---|
287 | check_err $? ${tcount}; errval=$?
|
---|
288 | fi
|
---|
289 | if [ $errval -eq 0 ]; then
|
---|
290 | run_check_after_update
|
---|
291 | check_err $? ${tcount}; errval=$?
|
---|
292 | fi
|
---|
293 | fi
|
---|
294 | #
|
---|
295 | if [ $errval -eq 0 ]; then
|
---|
296 | [ -z "$quiet" ] && log_ok ${tcount} ${MAXTEST};
|
---|
297 | fi
|
---|
298 | let "tcount = tcount + 1" >/dev/null
|
---|
299 | POLICY=`eval echo '"$'"SUIDPOLICY_$tcount"'"'`
|
---|
300 | done
|
---|
301 |
|
---|
302 | return 0
|
---|
303 | }
|
---|
304 |
|
---|
305 | testrun1c ()
|
---|
306 | {
|
---|
307 | log_start "RUN STANDALONE W/SUIDCHK"
|
---|
308 | testrun_internal_1c
|
---|
309 | log_end "RUN STANDALONE W/SUIDCHK"
|
---|
310 | return 0
|
---|
311 | }
|
---|
312 |
|
---|