Removed
Link Here
|
1 |
#!/bin/sh -f |
2 |
# |
3 |
# Copyright (c) 2004 Oliver Eikemeier. All rights reserved. |
4 |
# Copyright (c) 2014 Matthew Seaman <matthew@FreeBSD.org> |
5 |
# Copyright (c) 2016 Miroslav Lachman <000.fbsd@quip.cz> |
6 |
# |
7 |
# Redistribution and use in source and binary forms, with or without |
8 |
# modification, are permitted provided that the following conditions are |
9 |
# met: |
10 |
# |
11 |
# 1. Redistributions of source code must retain the above copyright notice |
12 |
# this list of conditions and the following disclaimer. |
13 |
# |
14 |
# 2. Redistributions in binary form must reproduce the above copyright |
15 |
# notice, this list of conditions and the following disclaimer in the |
16 |
# documentation and/or other materials provided with the distribution. |
17 |
# |
18 |
# 3. Neither the name of the author nor the names of its contributors may be |
19 |
# used to endorse or promote products derived from this software without |
20 |
# specific prior written permission. |
21 |
# |
22 |
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
23 |
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY |
24 |
# AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
25 |
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
26 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
27 |
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
31 |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 |
|
33 |
if [ -r /etc/defaults/periodic.conf ]; then |
34 |
. /etc/defaults/periodic.conf |
35 |
source_periodic_confs |
36 |
fi |
37 |
|
38 |
: ${security_status_baseaudit_enable:=YES} |
39 |
: ${security_status_baseaudit_period:=daily} |
40 |
: ${security_status_baseaudit_quiet:=NO} |
41 |
: ${security_status_baseaudit_chroots=$pkg_chroots} |
42 |
: ${security_status_baseaudit_jails=$pkg_jails} |
43 |
: ${security_status_baseaudit_jails_ignore=""} |
44 |
: ${security_status_baseaudit_expiry:=2} |
45 |
|
46 |
# Compute PKG_DBDIR from the config file. |
47 |
pkgcmd=%%PREFIX%%/sbin/pkg |
48 |
PKG_DBDIR=`${pkgcmd} config PKG_DBDIR` |
49 |
auditfile="${PKG_DBDIR}/vuln.xml" |
50 |
|
51 |
audit_base() { |
52 |
local pkgargs="$1" |
53 |
local basedir="$2" |
54 |
local rc |
55 |
local then |
56 |
local now |
57 |
local usrlv |
58 |
local krnlv |
59 |
local strlen |
60 |
local chrootv |
61 |
local jailv |
62 |
local jid |
63 |
|
64 |
## get version from chroot |
65 |
if [ -n "`echo "$pkgargs" | egrep '^-c'`" ]; then |
66 |
if [ -x "$basedir/bin/freebsd-version" ]; then |
67 |
chrootv=$($basedir/bin/freebsd-version -u) |
68 |
## safety check - strlen |
69 |
strlen=$(echo "$chrootv" | wc -c) |
70 |
if [ $strlen -gt 17 -o $strlen -lt 11 ]; then |
71 |
echo "Wrong version string, cannot run audit" |
72 |
return 3 |
73 |
fi |
74 |
usrlv=$(echo $chrootv | sed 's,^,FreeBSD-,;s,-RELEASE-p,_,;s,-RELEASE$,,') |
75 |
else |
76 |
echo "Cannot guess chroot version" |
77 |
return 3 |
78 |
fi |
79 |
## get version from jail |
80 |
elif [ -n "`echo "$pkgargs" | egrep '^-j'`" ]; then |
81 |
jid=$(echo "$pkgargs" | awk '$1 ~ /^-[j]/ { print $2 }') |
82 |
jailv=$(jexec $jid freebsd-version -u) |
83 |
## safety check - strlen |
84 |
strlen=$(echo "$jailv" | wc -c) |
85 |
if [ $strlen -gt 17 -o $strlen -lt 11 ]; then |
86 |
echo "Wrong version string, cannot run audit" |
87 |
return 3 |
88 |
fi |
89 |
usrlv=$(echo $jailv | sed 's,^,FreeBSD-,;s,-RELEASE-p,_,;s,-RELEASE$,,') |
90 |
## get version from host |
91 |
else |
92 |
usrlv=$(freebsd-version -u | sed 's,^,FreeBSD-,;s,-RELEASE-p,_,;s,-RELEASE$,,') |
93 |
fi |
94 |
|
95 |
then=`stat -f '%m' "${basedir}${auditfile}" 2> /dev/null` || rc=3 |
96 |
now=`date +%s` || rc=3 |
97 |
## Add 10 minutes of padding since the check is in seconds. |
98 |
if [ $rc -ne 0 -o \ |
99 |
$(( 86400 \* "${security_status_baseaudit_expiry}" )) \ |
100 |
-le $(( ${now} - ${then} + 600 )) ]; then |
101 |
## When non-interactive, sleep to reduce congestion on mirrors |
102 |
anticongestion |
103 |
f="-F" |
104 |
else |
105 |
echo -n 'Database fetched: ' |
106 |
date -r "${then}" || rc=3 |
107 |
fi |
108 |
|
109 |
## cannot check kernel in jail or chroot |
110 |
if [ -z "`echo "$pkgargs" | egrep '^-[cj]'`" -a `sysctl -n security.jail.jailed` = 0 ]; then |
111 |
krnlv=$(freebsd-version -k | sed 's,^,FreeBSD-kernel-,;s,-RELEASE-p,_,;s,-RELEASE$,,') |
112 |
${pkgcmd} audit $f $q $krnlv || { rc=$?; [ $rc -lt 3 ] && rc=3; } |
113 |
fi |
114 |
|
115 |
${pkgcmd} audit $f $q $usrlv || { rc=$?; [ $rc -lt 3 ] && rc=3; } |
116 |
|
117 |
return $rc |
118 |
} |
119 |
|
120 |
# Use $pkg_chroots to provide a default list of chroots, and |
121 |
# $pkg_jails to provide a default list of jails (or '*' for all jails) |
122 |
# for all pkg periodic scripts, or set |
123 |
# $security_status_baseaudit_chroots and |
124 |
# $security_status_baseaudit_jails for this script only. |
125 |
|
126 |
audit_base_all() { |
127 |
local rc |
128 |
local last_rc |
129 |
local jails |
130 |
|
131 |
# We always show audit results for the base system, but only print |
132 |
# a banner line if we're also showing audit results for any |
133 |
# chroots or jails. |
134 |
|
135 |
if [ -n "${security_status_baseaudit_chroots}" -o \ |
136 |
-n "${security_status_baseaudit_jails}" ]; then |
137 |
echo "Host system:" |
138 |
fi |
139 |
|
140 |
audit_base '' '' |
141 |
last_rc=$? |
142 |
[ $last_rc -gt 1 ] && rc=$last_rc |
143 |
|
144 |
for c in $security_status_baseaudit_chroots ; do |
145 |
echo |
146 |
echo "chroot: $c" |
147 |
audit_base "-c $c" $c |
148 |
last_rc=$? |
149 |
[ $last_rc -gt 1 ] && rc=$last_rc |
150 |
done |
151 |
|
152 |
case $security_status_baseaudit_jails in |
153 |
\*) |
154 |
jails=$(jls -q -h name path | sed -e 1d -e 's/ /|/') |
155 |
;; |
156 |
'') |
157 |
jails= |
158 |
;; |
159 |
*) |
160 |
# Given the jail name or jid, find the jail path |
161 |
jails= |
162 |
for j in $security_status_baseaudit_jails ; do |
163 |
p=$(jls -j $j -h name path | sed -e 1d -e 's/ /|/') |
164 |
jails="${jails} ${p}" |
165 |
done |
166 |
;; |
167 |
esac |
168 |
|
169 |
for j in $jails ; do |
170 |
# ignore some jails |
171 |
if [ -n "$security_status_baseaudit_jails_ignore" ]; then |
172 |
# we iterate to get exact matches because we want substring matches |
173 |
# foo should not match foo.bar |
174 |
for ignore in $security_status_baseaudit_jails_ignore ; do |
175 |
if [ "${j%|*}" == "$ignore" ]; then |
176 |
echo |
177 |
echo "ignoring jail: ${j%|*}" |
178 |
# continue with the main loop |
179 |
continue 2 |
180 |
fi |
181 |
done |
182 |
fi |
183 |
echo |
184 |
echo "jail: ${j%|*}" |
185 |
audit_base "-j ${j%|*}" ${j##*|} |
186 |
last_rc=$? |
187 |
[ $last_rc -gt 1 ] && rc=$last_rc |
188 |
done |
189 |
|
190 |
return $rc |
191 |
} |
192 |
|
193 |
security_daily_compat_var security_status_baseaudit_enable |
194 |
security_daily_compat_var security_status_baseaudit_quiet |
195 |
security_daily_compat_var security_status_baseaudit_chroots |
196 |
security_daily_compat_var security_status_baseaudit_jails |
197 |
security_daily_compat_var security_status_baseaudit_exipiry |
198 |
|
199 |
rc=0 |
200 |
|
201 |
if check_yesno_period security_status_baseaudit_enable |
202 |
then |
203 |
echo |
204 |
echo 'Checking for security vulnerabilities in base (userland & kernel):' |
205 |
|
206 |
if ! ${pkgcmd} -N >/dev/null 2>&1 ; then |
207 |
echo 'pkg-audit is enabled but pkg is not used' |
208 |
rc=2 |
209 |
else |
210 |
case "${security_status_baseaudit_quiet}" in |
211 |
[Yy][Ee][Ss]) |
212 |
q='-q' |
213 |
;; |
214 |
*) |
215 |
q= |
216 |
;; |
217 |
esac |
218 |
|
219 |
audit_base_all ; rc=$? |
220 |
fi |
221 |
fi |
222 |
|
223 |
exit "$rc" |