1993-03-21 12:45:37 +03:00
|
|
|
#!/bin/sh -
|
|
|
|
#
|
1998-01-26 15:02:43 +03:00
|
|
|
# $NetBSD: security,v 1.31 1998/01/26 12:02:55 lukem Exp $
|
1994-06-15 08:28:06 +04:00
|
|
|
# from: @(#)security 8.1 (Berkeley) 6/9/93
|
1993-03-21 12:45:37 +03:00
|
|
|
#
|
1994-06-15 08:28:06 +04:00
|
|
|
|
|
|
|
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if [ -f /etc/rc.subr ]; then
|
|
|
|
. /etc/rc.subr
|
|
|
|
else
|
|
|
|
echo "Can't read /etc/rc.subr; aborting."
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
1994-06-15 08:28:06 +04:00
|
|
|
umask 077
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s /etc/security.conf ]; then
|
|
|
|
. /etc/security.conf
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
SECUREDIR=/tmp/_securedir.$$
|
|
|
|
if ! mkdir $SECUREDIR; then
|
|
|
|
echo can not create $SECUREDIR.
|
|
|
|
exit 1
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
if ! cd $SECUREDIR; then
|
|
|
|
echo can not chdir to $SECUREDIR.
|
|
|
|
exit 1
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
ERR=secure1.$$
|
|
|
|
TMP1=secure2.$$
|
|
|
|
TMP2=secure3.$$
|
1997-09-18 09:16:19 +04:00
|
|
|
MPBYUID=secure4.$$
|
1997-09-23 18:36:56 +04:00
|
|
|
MPBYPATH=secure5.$$
|
1997-08-22 13:40:17 +04:00
|
|
|
LIST=secure6.$$
|
|
|
|
OUTPUT=secure7.$$
|
1997-01-05 14:46:12 +03:00
|
|
|
|
1997-08-22 13:40:17 +04:00
|
|
|
trap '/bin/rm -rf $SECUREDIR ; exit 0' 0 2 3
|
1997-01-05 14:46:12 +03:00
|
|
|
|
|
|
|
MP=/etc/master.passwd
|
|
|
|
|
1997-08-22 13:40:17 +04:00
|
|
|
# these is used several times.
|
1997-09-18 09:16:19 +04:00
|
|
|
awk -F: '{ print $1 " " $3 }' $MP | sort -k2n > $MPBYUID
|
1997-09-23 18:36:56 +04:00
|
|
|
awk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH
|
1997-01-05 14:46:12 +03:00
|
|
|
|
|
|
|
# Check the master password file syntax.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_passwd; then
|
1997-06-24 06:32:38 +04:00
|
|
|
awk '
|
|
|
|
BEGIN {
|
|
|
|
while ( getline < "/etc/shells" > 0 ) {
|
|
|
|
if ($LINE ~ /^\#/ || $LINE ~ /^$/ )
|
|
|
|
continue;
|
|
|
|
shells[$1]++;
|
|
|
|
}
|
|
|
|
FS=":";
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($0 ~ /^[ ]*$/) {
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Line %d is a blank line.\n", NR;
|
1997-01-05 14:46:12 +03:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (NF != 10)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Line %d has the wrong number of fields.\n", NR;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($1 !~ /^[A-Za-z0-9]*$/)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has non-alphanumeric characters.\n",
|
|
|
|
$1;
|
1997-01-05 14:46:12 +03:00
|
|
|
if (length($1) > 8)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has more than 8 characters.\n", $1;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($2 == "")
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has no password.\n", $1;
|
|
|
|
if (length($2) != 13 && $2 != "") {
|
|
|
|
if ($10 == "" || shells[$10])
|
1997-08-22 13:40:17 +04:00
|
|
|
printf "Login %s is off but still has a valid shell (%s)\n",
|
1997-06-24 06:32:38 +04:00
|
|
|
$1, $10;
|
|
|
|
} else if (! shells[$10])
|
|
|
|
printf "Login %s does not have a valid shell (%s)\n",
|
|
|
|
$1, $10;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($3 == 0 && $1 != "root" && $1 != "toor")
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has a user id of 0.\n", $1;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($3 < 0)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has a negative user id.\n", $1;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($4 < 0)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has a negative group id.\n", $1;
|
1997-01-05 14:46:12 +03:00
|
|
|
}' < $MP > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking the $MP file:\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
|
|
|
|
|
|
|
awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\n$MP has duplicate user names.\n"
|
|
|
|
column $OUTPUT
|
|
|
|
fi
|
|
|
|
|
1997-09-18 09:16:19 +04:00
|
|
|
< $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $TMP2 ] ; then
|
|
|
|
printf "\n$MP has duplicate user id's.\n"
|
|
|
|
while read uid; do
|
1997-09-18 09:16:19 +04:00
|
|
|
grep -w $uid $MPBYUID
|
1997-01-05 14:46:12 +03:00
|
|
|
done < $TMP2 | column
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Backup the master password file; a special case, the normal backup
|
|
|
|
# mechanisms also print out file differences and we don't want to do
|
|
|
|
# that because this file has encrypted passwords in it.
|
|
|
|
CUR=/var/backups/`basename $MP`.current
|
|
|
|
BACK=/var/backups/`basename $MP`.backup
|
|
|
|
if [ -s $CUR ] ; then
|
|
|
|
if cmp -s $CUR $MP; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
cp -p $CUR $BACK
|
|
|
|
cp -p $MP $CUR
|
|
|
|
chown root.wheel $CUR
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cp -p $MP $CUR
|
|
|
|
chown root.wheel $CUR
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check the group file syntax.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_group; then
|
1997-01-05 14:46:12 +03:00
|
|
|
GRP=/etc/group
|
|
|
|
awk -F: '{
|
|
|
|
if ($0 ~ /^[ ]*$/) {
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Line %d is a blank line.\n", NR;
|
1997-01-05 14:46:12 +03:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (NF != 4)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Line %d has the wrong number of fields.\n", NR;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($1 !~ /^[A-za-z0-9]*$/)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Group %s has non-alphanumeric characters.\n",
|
|
|
|
$1;
|
1997-01-05 14:46:12 +03:00
|
|
|
if (length($1) > 8)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Group %s has more than 8 characters.\n", $1;
|
1997-01-05 14:46:12 +03:00
|
|
|
if ($3 !~ /[0-9]*/)
|
1997-06-24 06:32:38 +04:00
|
|
|
printf "Login %s has a negative group id.\n", $1;
|
1997-01-05 14:46:12 +03:00
|
|
|
}' < $GRP > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking the $GRP file:\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\n$GRP has duplicate group names.\n"
|
|
|
|
column $OUTPUT
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for root paths, umask values in startup files.
|
|
|
|
# The check for the root paths is problematical -- it's likely to fail
|
|
|
|
# in other environments. Once the shells have been modified to warn
|
|
|
|
# of '.' in the path, the path tests should go away.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_rootdotfiles; then
|
1997-09-18 09:16:19 +04:00
|
|
|
> $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
rhome=`csh -fc "echo ~root"`
|
|
|
|
umaskset=no
|
|
|
|
list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
|
|
|
|
for i in $list ; do
|
|
|
|
if [ -f $i ] ; then
|
|
|
|
if egrep umask $i > /dev/null ; then
|
|
|
|
umaskset=yes
|
|
|
|
fi
|
|
|
|
egrep umask $i |
|
|
|
|
awk '$2 % 100 < 20 \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot umask is group writeable" }
|
1997-01-05 14:46:12 +03:00
|
|
|
$2 % 10 < 2 \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot umask is other writeable" }' \
|
|
|
|
>> $OUTPUT
|
1997-08-19 16:08:35 +04:00
|
|
|
SAVE_PATH=$PATH
|
|
|
|
unset PATH
|
1997-01-05 14:46:12 +03:00
|
|
|
/bin/csh -f -s << end-of-csh > /dev/null 2>&1
|
|
|
|
source $i
|
|
|
|
/bin/ls -ldgT \$path > $TMP1
|
1994-06-15 08:28:06 +04:00
|
|
|
end-of-csh
|
1997-08-19 16:08:35 +04:00
|
|
|
PATH=$SAVE_PATH
|
1997-01-05 14:46:12 +03:00
|
|
|
awk '{
|
|
|
|
if ($10 ~ /^\.$/) {
|
1997-08-22 13:40:17 +04:00
|
|
|
print "\tThe root path includes .";
|
1997-01-05 14:46:12 +03:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$1 ~ /^d....w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot path directory " $10 " is group writeable." } \
|
1997-01-05 14:46:12 +03:00
|
|
|
$1 ~ /^d.......w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot path directory " $10 " is other writeable." }' \
|
1997-01-05 14:46:12 +03:00
|
|
|
< $TMP1 >> $OUTPUT
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $umaskset = "no" -o -s $OUTPUT ] ; then
|
1997-08-22 13:40:17 +04:00
|
|
|
printf "\nChecking root csh paths, umask values:\n$list\n\n"
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ]; then
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
|
|
|
if [ $umaskset = "no" ] ; then
|
1997-08-22 13:40:17 +04:00
|
|
|
printf "\tRoot csh startup files do not set the umask.\n"
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-09-18 09:16:19 +04:00
|
|
|
> $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
rhome=/root
|
|
|
|
umaskset=no
|
1997-06-23 15:59:30 +04:00
|
|
|
list="/etc/profile ${rhome}/.profile"
|
1997-01-05 14:46:12 +03:00
|
|
|
for i in $list; do
|
|
|
|
if [ -f $i ] ; then
|
|
|
|
if egrep umask $i > /dev/null ; then
|
|
|
|
umaskset=yes
|
|
|
|
fi
|
|
|
|
egrep umask $i |
|
|
|
|
awk '$2 % 100 < 20 \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot umask is group writeable" } \
|
1997-01-05 14:46:12 +03:00
|
|
|
$2 % 10 < 2 \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot umask is other writeable" }' \
|
|
|
|
>> $OUTPUT
|
1997-08-19 16:08:35 +04:00
|
|
|
SAVE_PATH=$PATH
|
|
|
|
unset PATH
|
1997-01-05 14:46:12 +03:00
|
|
|
/bin/sh << end-of-sh > /dev/null 2>&1
|
|
|
|
. $i
|
1997-08-19 16:08:35 +04:00
|
|
|
list=\`echo \$PATH | /usr/bin/sed -e \
|
|
|
|
's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\`
|
1997-01-05 14:46:12 +03:00
|
|
|
/bin/ls -ldgT \$list > $TMP1
|
1994-06-15 08:28:06 +04:00
|
|
|
end-of-sh
|
1997-08-19 16:08:35 +04:00
|
|
|
PATH=$SAVE_PATH
|
1997-01-05 14:46:12 +03:00
|
|
|
awk '{
|
|
|
|
if ($10 ~ /^\.$/) {
|
1997-08-22 13:40:17 +04:00
|
|
|
print "\tThe root path includes .";
|
1997-01-05 14:46:12 +03:00
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$1 ~ /^d....w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot path directory " $10 " is group writeable." } \
|
1997-01-05 14:46:12 +03:00
|
|
|
$1 ~ /^d.......w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "\tRoot path directory " $10 " is other writeable." }' \
|
1997-01-05 14:46:12 +03:00
|
|
|
< $TMP1 >> $OUTPUT
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ $umaskset = "no" -o -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking root sh paths, umask values:\n$list\n"
|
|
|
|
if [ -s $OUTPUT ]; then
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
|
|
|
if [ $umaskset = "no" ] ; then
|
1997-08-22 13:40:17 +04:00
|
|
|
printf "\tRoot sh startup files do not set the umask.\n"
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Root and uucp should both be in /etc/ftpusers.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_ftpusers; then
|
1997-09-18 09:16:19 +04:00
|
|
|
> $OUTPUT
|
|
|
|
list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID`
|
1997-08-22 13:40:17 +04:00
|
|
|
for i in $list; do
|
1997-09-23 18:36:56 +04:00
|
|
|
if /usr/libexec/ftpd -C $i ; then
|
|
|
|
printf "\t$i is not denied\n" >> $OUTPUT
|
1997-08-22 13:40:17 +04:00
|
|
|
fi
|
|
|
|
done
|
1997-09-18 09:16:19 +04:00
|
|
|
if [ -s $OUTPUT ]; then
|
|
|
|
printf "\nChecking the /etc/ftpusers configuration:\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Uudecode should not be in the /etc/aliases file.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_aliases; then
|
1997-04-17 11:42:07 +04:00
|
|
|
if egrep '^[^#]*(uudecode|decode).*\|' /etc/aliases; then
|
|
|
|
printf "\nEntry for uudecode in /etc/aliases file.\n"
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Files that should not have + signs.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_rhosts; then
|
1997-01-05 14:46:12 +03:00
|
|
|
list="/etc/hosts.equiv /etc/hosts.lpd"
|
|
|
|
for f in $list ; do
|
|
|
|
if [ -f $f ] && egrep '\+' $f > /dev/null ; then
|
|
|
|
printf "\nPlus sign in $f file.\n"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Check for special users with .rhosts files. Only root and toor should
|
1997-02-14 11:52:05 +03:00
|
|
|
# have .rhosts files. Also, .rhosts files should not have plus signs.
|
1997-01-05 14:46:12 +03:00
|
|
|
awk -F: '$1 != "root" && $1 != "toor" && \
|
|
|
|
($3 < 100 || $1 == "ftp" || $1 == "uucp") \
|
1997-04-21 15:19:57 +04:00
|
|
|
{ print $1 " " $9 }' $MP |
|
1997-04-21 15:14:41 +04:00
|
|
|
sort -k2 |
|
1997-01-05 14:46:12 +03:00
|
|
|
while read uid homedir; do
|
|
|
|
if [ -f ${homedir}/.rhosts ] ; then
|
|
|
|
rhost=`ls -ldgT ${homedir}/.rhosts`
|
|
|
|
printf "$uid: $rhost\n"
|
|
|
|
fi
|
|
|
|
done > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking for special users with .rhosts files.\n"
|
|
|
|
cat $OUTPUT
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
while read uid homedir; do
|
|
|
|
if [ -f ${homedir}/.rhosts ] && \
|
|
|
|
egrep '\+' ${homedir}/.rhosts > /dev/null ; then
|
|
|
|
printf "$uid: + in .rhosts file.\n"
|
|
|
|
fi
|
1997-09-23 18:36:56 +04:00
|
|
|
done < $MPBYPATH > $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking .rhosts files syntax.\n"
|
|
|
|
cat $OUTPUT
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check home directories. Directories should not be owned by someone else
|
|
|
|
# or writeable.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_homes; then
|
1997-01-05 14:46:12 +03:00
|
|
|
while read uid homedir; do
|
|
|
|
if [ -d ${homedir}/ ] ; then
|
|
|
|
file=`ls -ldgT ${homedir}`
|
|
|
|
printf "$uid $file\n"
|
|
|
|
fi
|
1997-09-23 18:36:56 +04:00
|
|
|
done < $MPBYPATH |
|
1997-01-05 14:46:12 +03:00
|
|
|
awk '$1 != $4 && $4 != "root" \
|
|
|
|
{ print "user " $1 " home directory is owned by " $4 }
|
|
|
|
$2 ~ /^-....w/ \
|
|
|
|
{ print "user " $1 " home directory is group writeable" }
|
|
|
|
$2 ~ /^-.......w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "user " $1 " home directory is other writeable" }' \
|
|
|
|
> $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking home directories.\n"
|
|
|
|
cat $OUTPUT
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
# Files that should not be owned by someone else or readable.
|
1997-08-22 13:40:17 +04:00
|
|
|
list=".Xauthority .netrc"
|
1997-01-05 14:46:12 +03:00
|
|
|
while read uid homedir; do
|
|
|
|
for f in $list ; do
|
|
|
|
file=${homedir}/${f}
|
|
|
|
if [ -f $file ] ; then
|
|
|
|
printf "$uid $f `ls -ldgT $file`\n"
|
|
|
|
fi
|
|
|
|
done
|
1997-09-23 18:36:56 +04:00
|
|
|
done < $MPBYPATH |
|
1997-01-05 14:46:12 +03:00
|
|
|
awk '$1 != $5 && $5 != "root" \
|
|
|
|
{ print "user " $1 " " $2 " file is owned by " $5 }
|
|
|
|
$3 ~ /^-...r/ \
|
|
|
|
{ print "user " $1 " " $2 " file is group readable" }
|
|
|
|
$3 ~ /^-......r/ \
|
|
|
|
{ print "user " $1 " " $2 " file is other readable" }
|
|
|
|
$3 ~ /^-....w/ \
|
|
|
|
{ print "user " $1 " " $2 " file is group writeable" }
|
|
|
|
$3 ~ /^-.......w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "user " $1 " " $2 " file is other writeable" }' \
|
|
|
|
> $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
|
|
|
|
# Files that should not be owned by someone else or writeable.
|
1997-04-21 15:14:41 +04:00
|
|
|
list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \
|
|
|
|
.cshrc .emacs .exrc .forward .history .klogin .login .logout \
|
1997-08-22 13:40:17 +04:00
|
|
|
.profile .qmail .rc_history .rhosts .tcshrc .twmrc .xinitrc \
|
|
|
|
.xsession"
|
1997-01-05 14:46:12 +03:00
|
|
|
while read uid homedir; do
|
|
|
|
for f in $list ; do
|
|
|
|
file=${homedir}/${f}
|
|
|
|
if [ -f $file ] ; then
|
|
|
|
printf "$uid $f `ls -ldgT $file`\n"
|
|
|
|
fi
|
|
|
|
done
|
1997-09-23 18:36:56 +04:00
|
|
|
done < $MPBYPATH |
|
1997-01-05 14:46:12 +03:00
|
|
|
awk '$1 != $5 && $5 != "root" \
|
|
|
|
{ print "user " $1 " " $2 " file is owned by " $5 }
|
|
|
|
$3 ~ /^-....w/ \
|
|
|
|
{ print "user " $1 " " $2 " file is group writeable" }
|
|
|
|
$3 ~ /^-.......w/ \
|
1997-08-22 13:40:17 +04:00
|
|
|
{ print "user " $1 " " $2 " file is other writeable" }' \
|
|
|
|
>> $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking dot files.\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Mailboxes should be owned by user and unreadable.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_varmail; then
|
1997-01-05 14:46:12 +03:00
|
|
|
ls -l /var/mail | sed 1d | \
|
|
|
|
awk '$3 != $9 \
|
|
|
|
{ print "user " $9 " mailbox is owned by " $3 }
|
|
|
|
$1 != "-rw-------" \
|
|
|
|
{ print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking mailbox ownership.\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_nfs; then
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -f /etc/exports ]; then
|
|
|
|
# File systems should not be globally exported.
|
|
|
|
awk '{
|
1997-06-23 05:49:15 +04:00
|
|
|
# ignore comments and blank lines
|
|
|
|
if ($LINE ~ /^\#/ || $LINE ~ /^$/ )
|
|
|
|
next;
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
readonly = 0;
|
|
|
|
for (i = 2; i <= NF; ++i) {
|
|
|
|
if ($i ~ /-ro/)
|
|
|
|
readonly = 1;
|
|
|
|
else if ($i !~ /^-/)
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if (readonly)
|
|
|
|
print "File system " $1 " globally exported, read-only."
|
|
|
|
else
|
|
|
|
print "File system " $1 " globally exported, read-write."
|
|
|
|
}' < /etc/exports > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\nChecking for globally exported file systems.\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Display any changes in setuid files and devices.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_devices; then
|
1997-09-18 09:16:19 +04:00
|
|
|
> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
(find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \
|
|
|
|
-o -fstype procfs \) -a -prune -o \
|
1997-04-21 21:38:39 +04:00
|
|
|
\( \( -perm -u+s -a ! -type d \) -o \
|
|
|
|
\( -perm -g+s -a ! -type d \) -o \
|
1997-06-24 05:16:47 +04:00
|
|
|
-type b -o -type c \) -print0 | \
|
|
|
|
xargs -0 ls -ldgTq | sort +9 > $LIST) 2> $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
|
|
|
|
# Display any errors that occurred during system file walk.
|
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Setuid/device find errors:\n" >> $ERR
|
|
|
|
cat $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
# Display any changes in the setuid file list.
|
|
|
|
egrep -v '^[bc]' $LIST > $TMP1
|
|
|
|
if [ -s $TMP1 ] ; then
|
|
|
|
# Check to make sure uudecode isn't setuid.
|
|
|
|
if grep -w uudecode $TMP1 > /dev/null ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "\nUudecode is setuid.\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
CUR=/var/backups/setuid.current
|
|
|
|
BACK=/var/backups/setuid.backup
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $CUR ] ; then
|
|
|
|
if cmp -s $CUR $TMP1 ; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
> $TMP2
|
|
|
|
join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Setuid additions:\n" >> $ERR
|
|
|
|
tee -a $TMP2 < $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Setuid deletions:\n" >> $ERR
|
|
|
|
tee -a $TMP2 < $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-04-21 15:19:57 +04:00
|
|
|
sort -k10 $TMP2 $CUR $TMP1 | \
|
1997-08-22 13:40:17 +04:00
|
|
|
sed -e 's/[ ][ ]*/ /g' | \
|
|
|
|
uniq -u > $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Setuid changes:\n" >> $ERR
|
|
|
|
column -t $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
cp $CUR $BACK
|
|
|
|
cp $TMP1 $CUR
|
|
|
|
fi
|
|
|
|
else
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Setuid additions:\n" >> $ERR
|
|
|
|
column -t $TMP1 >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1994-06-15 08:28:06 +04:00
|
|
|
cp $TMP1 $CUR
|
|
|
|
fi
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
|
|
|
|
1997-08-22 13:40:17 +04:00
|
|
|
# Check for block and character disk devices that are readable or
|
|
|
|
# writeable or not owned by root.operator.
|
1997-01-05 14:46:12 +03:00
|
|
|
>$TMP1
|
1997-08-22 13:40:17 +04:00
|
|
|
DISKLIST="acd ccd cd ch fd hk hp mcd md ra rb rd rl rx rz \
|
|
|
|
sd se ss tz uk up vnd wd xd xy"
|
|
|
|
# DISKLIST="$DISKLIST ct mt st wt"
|
1997-01-05 14:46:12 +03:00
|
|
|
for i in $DISKLIST; do
|
|
|
|
egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1
|
|
|
|
egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1
|
|
|
|
done
|
|
|
|
|
|
|
|
awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
|
1997-06-24 06:32:38 +04:00
|
|
|
{ printf "Disk %s is user %s, group %s, permissions %s.\n", \
|
|
|
|
$11, $3, $4, $1; }' < $TMP1 > $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "\nChecking disk ownership and permissions.\n" >> $ERR
|
|
|
|
cat $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
# Display any changes in the device file list.
|
1997-04-21 15:19:57 +04:00
|
|
|
egrep '^[bc]' $LIST | sort -k11 > $TMP1
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $TMP1 ] ; then
|
|
|
|
CUR=/var/backups/device.current
|
|
|
|
BACK=/var/backups/device.backup
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $CUR ] ; then
|
|
|
|
if cmp -s $CUR $TMP1 ; then
|
|
|
|
:
|
|
|
|
else
|
|
|
|
> $TMP2
|
|
|
|
join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Device additions:\n" >> $ERR
|
|
|
|
tee -a $TMP2 < $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Device deletions:\n" >> $ERR
|
|
|
|
tee -a $TMP2 < $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-08-22 13:40:17 +04:00
|
|
|
# Report any block device change. Ignore
|
|
|
|
# character devices, only the name is
|
|
|
|
# significant.
|
1997-01-05 14:46:12 +03:00
|
|
|
cat $TMP2 $CUR $TMP1 | \
|
1997-08-22 13:40:17 +04:00
|
|
|
sed -e '/^c/d' | \
|
|
|
|
sort -k11 | \
|
|
|
|
sed -e 's/[ ][ ]*/ /g' | \
|
|
|
|
uniq -u > $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ] ; then
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Block device changes:\n" >> $ERR
|
|
|
|
column -t $OUTPUT >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
1997-01-05 14:46:12 +03:00
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
|
1997-01-05 14:46:12 +03:00
|
|
|
cp $CUR $BACK
|
|
|
|
cp $TMP1 $CUR
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
1997-01-05 14:46:12 +03:00
|
|
|
else
|
1997-09-18 09:16:19 +04:00
|
|
|
printf "Device additions:\n" >> $ERR
|
|
|
|
column -t $TMP1 >> $ERR
|
|
|
|
printf "\n" >> $ERR
|
|
|
|
cp $TMP1 $CUR >> $ERR
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
fi
|
1997-09-18 09:16:19 +04:00
|
|
|
if [ -s $ERR ] ; then
|
|
|
|
printf "\nChecking setuid files and devices:\n"
|
|
|
|
cat $ERR
|
|
|
|
printf "\n"
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check special files.
|
|
|
|
# Check system binaries.
|
|
|
|
#
|
|
|
|
# Create the mtree tree specifications using:
|
|
|
|
#
|
|
|
|
# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
|
1997-02-14 11:52:05 +03:00
|
|
|
# chown root.wheel DIR.secure
|
|
|
|
# chmod 600 DIR.secure
|
1994-06-15 08:28:06 +04:00
|
|
|
#
|
|
|
|
# Note, this is not complete protection against Trojan horsed binaries, as
|
|
|
|
# the hacker can modify the tree specification to match the replaced binary.
|
|
|
|
# For details on really protecting yourself against modified binaries, see
|
|
|
|
# the mtree(8) manual page.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_mtree; then
|
1994-06-15 08:28:06 +04:00
|
|
|
mtree -e -p / -f /etc/mtree/special > $OUTPUT
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ]; then
|
1994-06-15 08:28:06 +04:00
|
|
|
printf "\nChecking special files and directories.\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
|
|
|
|
|
|
|
> $OUTPUT
|
1997-02-14 11:52:05 +03:00
|
|
|
for file in /etc/mtree/*.secure; do
|
|
|
|
[ $file = '/etc/mtree/*.secure' ] && continue
|
1994-06-15 08:28:06 +04:00
|
|
|
tree=`sed -n -e '3s/.* //p' -e 3q $file`
|
|
|
|
mtree -f $file -p $tree > $TMP1
|
|
|
|
if [ -s $TMP1 ]; then
|
|
|
|
printf "\nChecking $tree:\n" >> $OUTPUT
|
|
|
|
cat $TMP1 >> $OUTPUT
|
|
|
|
fi
|
|
|
|
done
|
1997-01-05 14:46:12 +03:00
|
|
|
if [ -s $OUTPUT ]; then
|
1994-06-15 08:28:06 +04:00
|
|
|
printf "\nChecking system binaries:\n"
|
|
|
|
cat $OUTPUT
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# List of files that get backed up and checked for any modifications. Each
|
|
|
|
# file is expected to have two backups, /var/backups/file.{current,backup}.
|
|
|
|
# Any changes cause the files to rotate.
|
1998-01-26 15:02:43 +03:00
|
|
|
if checkyesno check_changelist && [ -s /etc/changelist ] ; then
|
1997-08-22 13:40:17 +04:00
|
|
|
for file in `egrep -v "^#|$MP" /etc/changelist`; do
|
1994-06-15 08:28:06 +04:00
|
|
|
CUR=/var/backups/`basename $file`.current
|
|
|
|
BACK=/var/backups/`basename $file`.backup
|
1997-10-08 20:13:44 +04:00
|
|
|
if [ -f $file ]; then
|
|
|
|
if [ -f $CUR ] ; then
|
1994-06-15 08:28:06 +04:00
|
|
|
diff $CUR $file > $OUTPUT
|
|
|
|
if [ -s $OUTPUT ] ; then
|
|
|
|
printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file
|
|
|
|
cat $OUTPUT
|
1997-10-08 20:13:44 +04:00
|
|
|
mv -f $CUR $BACK
|
1994-06-15 08:28:06 +04:00
|
|
|
cp -p $file $CUR
|
1997-10-08 20:13:44 +04:00
|
|
|
chown root.wheel $CUR
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
else
|
1997-10-08 20:13:44 +04:00
|
|
|
printf "\n======\n%s added\n======\n" $file
|
|
|
|
diff /dev/null $file
|
1994-06-15 08:28:06 +04:00
|
|
|
cp -p $file $CUR
|
|
|
|
chown root.wheel $CUR
|
|
|
|
fi
|
1997-10-08 20:13:44 +04:00
|
|
|
else
|
|
|
|
if [ -f $CUR ]; then
|
|
|
|
printf "\n======\n%s removed\n======\n" $file
|
|
|
|
diff $CUR /dev/null
|
|
|
|
mv -f $CUR $BACK
|
|
|
|
fi
|
1994-06-15 08:28:06 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|