Date: Mon, 21 May 2001 21:52:43 +0100 (BST) From: Rik <rik@pkl.net> To: freebsd-security@freebsd.org Subject: A few more tests to add to /etc/security Message-ID: <Pine.LNX.4.21.0105212146080.17879-200000@pkl.net>
index | next in thread | raw e-mail
[-- Attachment #1 --]
Hi,
I have been using OpenBSD for a while, and I am about try try FreeBSD, and
while browsing /etc, I noticed that the /etc/security script is slightly
sparse, so I took the liberty of adding a few tests from the OpenBSD
/etc/security script.
I have *NOT* checked that they work, yet, although a lot of the tests
should work straight off. Pay particular attention to the master.passwd
checks, since I haven't a clue if there's a different format between
OpenBSD and FreeBSD...
Anyway, hope these help, have funm etc...
rik
[-- Attachment #2 --]
This patch adds in a bunch of checks that OpenBSD 2.9 (as of 21/May/2001,
prerelease) does.
It *HAS NOT* been checked. I don't even run FreeBSD (yet). You are welcome to
hack this around. Please check all of the new checks, since I haven't. They
are all worth doing, so please do include them.
Enjoy,
rik
--- fbsd-security Mon May 21 19:31:19 2001
+++ security Mon May 21 20:04:08 2001
@@ -61,7 +61,403 @@
host=`hostname`
[ $sflag = FALSE ] && echo "Subject: ${host} security check output"
-umask 027
+umask 077
+
+MP=/etc/master.passwd
+awk -F: '{
+ if ($0 ~ /^[ ]*$/) {
+ printf("Line %d is a blank line.\n", NR);
+ next;
+ }
+ if (NF != 10)
+ printf("Line %d has the wrong number of fields:\n%s\n", NR, $0);
+ if ($1 ~ /^[+-]/)
+ next;
+ if ($1 == "")
+ printf("Line %d has an empty login field:\n%s\n", NR, $0);
+ else if ($1 !~ /^[A-Za-z0-9][A-Za-z0-9_-]*$/)
+ printf("Login %s has non-alphanumeric characters.\n", $1);
+ if (length($1) > 31)
+ printf("Login %s has more than 31 characters.\n", $1);
+ if ($2 == "")
+ printf("Login %s has no password.\n", $1);
+ if ($2 != "" && length($2) != 13 && ($10 ~ /.*sh$/ || $10 == "") &&
+ ($2 !~ /^\$[0-9a-f]+\$/) && ($2 != "skey")) {
+ if (system("test -s /etc/skeykeys && grep -q \"^"$1" \"
+/etc/skeykeys") == 0)
+ printf("Login %s is off but still has a valid shell and an entry
+in /etc/skeykeys.\n", $1);
+ if (system("test -d "$9" -a ! -r "$9"") == 0)
+ printf("Login %s is off but still has valid shell and home
+directory is unreadable\n\t by root; cannot check for existence of alternate
+access files.\n", $1);
+ else if (system("for file in .ssh .rhosts .shosts .klogin; do if test
+-e "$9"/$file; then if ((ls -ld "$9"/$file | cut -b 2-10 | grep -q r) && (test
+! -O "$9"/$file)) ; then exit 1; fi; fi; done"))
+ printf("Login %s is off but still has a valid shell and alternate
+access files in\n\t home directory are still readable.\n",$1);
+ }
+ if ($3 == 0 && $1 != "root")
+ printf("Login %s has a user ID of 0.\n", $1);
+ if ($3 < 0)
+ printf("Login %s has a negative user ID.\n", $1);
+ if ($4 < 0)
+ printf("Login %s has a negative group ID.\n", $1);
+}' < $MP > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\nChecking the ${MP} file:"
+ cat $OUTPUT
+fi
+
+awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\n${MP} has duplicate user names."
+ column $OUTPUT
+fi
+
+awk -F: '/^[^\+]/ { print $1 " " $3 }' $MP | sort -n +1 | tee $TMP1 |
+uniq -d -f 1 | awk '{ print $2 }' > $TMP2
+if [ -s $TMP2 ] ; then
+ echo "\n${MP} has duplicate user ID's."
+ while read uid; do
+ grep -w $uid $TMP1
+ done < $TMP2 | column
+fi
+
+# Check the group file syntax.
+GRP=/etc/group
+awk -F: '{
+ if ($0 ~ /^[ ]*$/) {
+ printf("Line %d is a blank line.\n", NR);
+ next;
+ }
+ if ($1 ~ /^[+-].*$/)
+ next;
+ if (NF != 4)
+ printf("Line %d has the wrong number of fields:\n%s\n", NR, $0);
+ if ($1 !~ /^[A-za-z0-9][A-za-z0-9_-]*$/)
+ printf("Group %s has non-alphanumeric characters.\n", $1);
+ if (length($1) > 31)
+ printf("Group %s has more than 31 characters.\n", $1);
+ if ($3 !~ /[0-9]*/)
+ printf("Login %s has a negative group ID.\n", $1);
+}' < $GRP > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\nChecking the ${GRP} file:"
+ cat $OUTPUT
+fi
+
+awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\n${GRP} has duplicate group names."
+ column $OUTPUT
+fi
+
+echo "Checking root csh paths, and umask values:\n${list}"
+rhome=/root
+umaskset=no
+list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
+for i in $list ; do
+ if [ -s $i ] ; then
+ if egrep umask $i > /dev/null ; then
+ umaskset=yes
+ fi
+ egrep umask $i |
+ awk '$2 % 100 < 20 \
+ { print "Root umask is group writeable" }
+ $2 % 10 < 2 \
+ { print "Root umask is other writeable" }'
+ SAVE_PATH=$PATH
+ unset PATH
+ /bin/csh -f -s << end-of-csh > /dev/null 2>&1
+ source $i
+ if (\$?path) then
+ /bin/ls -ldgT \$path > $TMP
+ else
+ cat /dev/null > $TMP
+ endif
+end-of-csh
+ PATH=$SAVE_PATH
+ awk '{
+ if ($10 ~ /^\.$/) {
+ print "The root path includes .";
+ next;
+ }
+ }
+ $1 ~ /^d....w/ \
+ { print "Root path directory " $10 " is group writeable." } \
+ $1 ~ /^d.......w/ \
+ { print $Root path directory " $10 " is other writeable." }' \
+ < $TMP
+ if
+done
+if [ $umaskset = "no" ] ; then
+ echo "\nRoot csh startup files do not set the umask."
+fi
+
+echo "Checking root sh paths, umask values:\n{$list}"
+rhome=/root
+umaskset=no
+list="/etc/profile ${rhome}/.profile"
+for i in $list; do
+ if [ -s $i ] ; then
+ if egrep umask $i > /dev/null ; then
+ umaskset=yes
+ fi
+ egrep umask $i |
+ awk '$2 % 100 < 20 \
+ { print "Root umask is group writeable" } \
+ $2 % 10 < 2 \
+ { print "Root umask is other writeable" }' >> $OUTPUT
+ SAVE_PATH=$PATH
+ SAVE_ENV=$ENV
+ unset PATH ENV
+ /bin/sh << end-of-sh > /dev/null 2>&1
+ . $i
+ if [ X"\$PATH" != "X" ]; then
+ list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
+ /bin/ls -ldgT \$list > $TMP1
+ else
+ > $TMP1
+ fi
+ echo \$ENV >> $TMP2
+end-of-sh
+ PATH=$SAVE_PATH
+ ENV=$SAVE_ENV
+ awk '{
+ if ($10 ~ /^\.$/) {
+ print "The root path includes .";
+ next;
+ }
+ }
+ $1 ~ /^d....w/ \
+ { print "Root path directory " $10 " is group writeable." } \
+ $1 ~ /^d.......w/ \
+ { print "Root path directory " $10 " is other writeable." }' \
+ < $TMP1 >> $OUTPUT
+
+ fi
+done
+if [ $umaskset = "no" ] ; then
+ echo "\nRoot sh startup files do not set the umask."
+fi
+
+echo "Checking root ksh paths, umask values:\n{$list}"
+# A good .kshrc will not have a umask or path, that being set in .profile
+# check anyway.
+> $OUTPUT
+rhome=/root
+list="/etc/ksh.kshrc `cat $TMP2`"
+(cd $rhome
+ for i in $list; do
+ if [ -s $i ] ; then
+ egrep umask $i |
+ awk '$2 % 100 < 20 \
+ { print "Root umask is group writeable" } \
+ $2 % 10 < 2 \
+ { print "Root umask is other writeable" }' >> $OUTPUT
+ if egrep PATH= $i > /dev/null ; then
+ SAVE_PATH=$PATH
+ unset PATH
+ /bin/ksh << end-of-sh > /dev/null 2>&1
+ . $i
+ if [ X"\$PATH" != "X" ]; then
+ list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
+ /bin/ls -ldgT \$list > $TMP1
+ else
+ > $TMP1
+ fi
+end-of-sh
+ PATH=$SAVE_PATH
+ awk '{
+ if ($10 ~ /^\.$/) {
+ print "The root path includes .";
+ next;
+ }
+ }
+ $1 ~ /^d....w/ \
+ { print "Root path directory " $10 " is group writeable." } \
+ $1 ~ /^d.......w/ \
+ { print "Root path directory " $10 " is other writeable." }' \
+ < $TMP1 >> $OUTPUT
+ fi
+
+ fi
+ done
+)
+
+# Root and uucp should both be in /etc/ftpusers.
+if egrep root /etc/ftpusers > /dev/null ; then
+ :
+else
+ echo "\nRoot not listed in /etc/ftpusers file."
+fi
+if egrep uucp /etc/ftpusers > /dev/null ; then
+ :
+else
+ echo "\nUucp not listed in /etc/ftpusers file."
+fi
+
+# Uudecode should not be in the /etc/mail/aliases file.
+if egrep 'uudecode|decode' /etc/mail/aliases; then
+ echo "\nThere is an entry for uudecode in the /etc/mail/aliases file."
+fi
+
+# Files that should not have + signs.
+list="/etc/hosts.equiv /etc/shosts.equiv /etc/hosts.lpd"
+for f in $list ; do
+ if [ -s $f ] ; then
+ awk '{
+ if ($0 ~ /^\+@.*$/)
+ next;
+ if ($0 ~ /^\+.*$/)
+ printf("\nPlus sign in %s file.\n", FILENAME);
+ }' $f
+ fi
+done
+
+# Check for special users with .rhosts/.shosts files. Only root
+# should have .rhosts/.shosts files. Also, .rhosts/.shosts
+# files should not have plus signs.
+awk -F: '$1 != "root" && $1 !~ /^[+-]/ && \
+ ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
+ { print $1 " " $6 }' /etc/passwd |
+while read uid homedir; do
+ for j in .rhosts .shosts; do
+ # Root owned .rhosts/.shosts files are ok.
+ if [ -s ${homedir}/$j -a ! -O ${homedir}/$j ] ; then
+ rhost=`ls -ldgT ${homedir}/$j`
+ echo "${uid}: ${rhost}"
+ fi
+ done
+done > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\nChecking for special users with .rhosts/.shosts files."
+ cat $OUTPUT
+fi
+
+awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ for j in .rhosts .shosts; do
+ if [ -s ${homedir}/$j ] ; then
+ awk '{
+ if ($0 ~ /^+@.*$/ )
+ next;
+ if ($0 ~ /^\+[ ]*$/ )
+ printf("%s has + sign in it.\n",
+ FILENAME);
+ }' ${homedir}/$j
+ fi
+ done
+done > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\nChecking .rhosts/.shosts files syntax."
+ cat $OUTPUT
+fi
+
+# Check home directories. Directories should not be owned by someone else
+# or writeable.
+awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ if [ -d ${homedir}/ ] ; then
+ file=`ls -ldgT ${homedir}`
+ echo "${uid} ${file}"
+ fi
+done |
+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/ \
+ { print "user " $1 " home directory is other writeable" }' > $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\nChecking home directories."
+ cat $OUTPUT
+fi
+
+# Files that should not be owned by someone else or readable.
+list=".netrc .rhosts .gnupg/secring.gpg .gnupg/random_seed \
+ .pgp/secring.pgp .shosts .ssh/identity .ssh/id_dsa .ssh/id_rsa"
+awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ for f in $list ; do
+ file=${homedir}/${f}
+ if [ -f $file ] ; then
+ echo "${uid} ${f} `ls -ldgT ${file}`"
+ fi
+ done
+done |
+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/ \
+ { print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
+
+# Files that should not be owned by someone else or writeable.
+list=".bashrc .bash_profile .bash_login .bash_logout .cshrc \
+ .emacs .exrc .forward .fvwmrc .inputrc .klogin .kshrc .login \
+ .logout .nexrc .profile .screenrc .ssh .ssh/config \
+ .ssh/authorized_keys .ssh/authorized_keys2 .ssh/environment \
+ .ssh/known_hosts .ssh/rc .tcshrc .twmrc .xsession .xinitrc \
+ .Xdefaults .Xauthority"
+awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
+while read uid homedir; do
+ for f in $list ; do
+ file=${homedir}/${f}
+ if [ -f $file ] ; then
+ echo "${uid} ${f} `ls -ldgT ${file}`"
+ fi
+ done
+done |
+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/ \
+ { print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
+if [ -s $OUTPUT ] ; then
+ echo "\nChecking dot files."
+ cat $OUTPUT
+fi
+
+# Mailboxes should be owned by user and unreadable.
+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
+ echo "\nChecking mailbox ownership."
+ cat $OUTPUT
+fi
+
+# File systems should not be globally exported.
+if [ -s /etc/exports ] ; then
+ awk '{
+ if (($1 ~ /^#/) || ($1 ~ /^$/))
+ next;
+ 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
+ echo "\nChecking for globally exported file systems."
+ cat $OUTPUT
+ fi
+fi
echo 'Checking setuid files and devices:'
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.21.0105212146080.17879-200000>
