security revision 1.45
11.1Scgd#!/bin/sh - 21.1Scgd# 31.45Ssommerfe# $NetBSD: security,v 1.45 2000/07/02 22:27:47 sommerfeld Exp $ 41.9Scgd# from: @(#)security 8.1 (Berkeley) 6/9/93 51.1Scgd# 61.1Scgd 71.9ScgdPATH=/sbin:/usr/sbin:/bin:/usr/bin 81.1Scgd 91.31Slukemif [ -f /etc/rc.subr ]; then 101.31Slukem . /etc/rc.subr 111.31Slukemelse 121.31Slukem echo "Can't read /etc/rc.subr; aborting." 131.31Slukem exit 1; 141.31Slukemfi 151.31Slukem 161.9Scgdumask 077 171.1Scgd 181.15Smrgif [ -s /etc/security.conf ]; then 191.15Smrg . /etc/security.conf 201.15Smrgfi 211.15Smrg 221.15SmrgSECUREDIR=/tmp/_securedir.$$ 231.15Smrgif ! mkdir $SECUREDIR; then 241.15Smrg echo can not create $SECUREDIR. 251.15Smrg exit 1 261.15Smrgfi 271.15Smrg 281.15Smrgif ! cd $SECUREDIR; then 291.15Smrg echo can not chdir to $SECUREDIR. 301.15Smrg exit 1 311.15Smrgfi 321.15Smrg 331.34Sabsif [ -z "$max_loginlen" ];then 341.34Sabs max_loginlen=8 351.34Sabsfi 361.34Sabs 371.15SmrgERR=secure1.$$ 381.15SmrgTMP1=secure2.$$ 391.15SmrgTMP2=secure3.$$ 401.28SlukemMPBYUID=secure4.$$ 411.29SlukemMPBYPATH=secure5.$$ 421.27SlukemLIST=secure6.$$ 431.27SlukemOUTPUT=secure7.$$ 441.32SlukemLABELS=secure8.$$ 451.15Smrg 461.27Slukemtrap '/bin/rm -rf $SECUREDIR ; exit 0' 0 2 3 471.15Smrg 481.15SmrgMP=/etc/master.passwd 491.9Scgd 501.27Slukem# these is used several times. 511.34Sabsawk -F: '!/^+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 521.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 531.9Scgd 541.9Scgd# Check the master password file syntax. 551.32Slukem# 561.31Slukemif checkyesno check_passwd; then 571.34Sabs awk -v "len=$max_loginlen" ' 581.25Slukem BEGIN { 591.25Slukem while ( getline < "/etc/shells" > 0 ) { 601.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 611.25Slukem continue; 621.25Slukem shells[$1]++; 631.25Slukem } 641.25Slukem FS=":"; 651.25Slukem } 661.25Slukem 671.25Slukem { 681.15Smrg if ($0 ~ /^[ ]*$/) { 691.25Slukem printf "Line %d is a blank line.\n", NR; 701.15Smrg next; 711.15Smrg } 721.34Sabs if (NF != 10 && ($1 != "+" || NF != 1)) 731.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 741.34Sabs if ($1 == "+" ) { 751.34Sabs if (NF != 1 && $3 == 0) 761.34Sabs printf "Line %d includes entries with uid 0.\n", NR; 771.34Sabs next; 781.34Sabs } 791.15Smrg if ($1 !~ /^[A-Za-z0-9]*$/) 801.25Slukem printf "Login %s has non-alphanumeric characters.\n", 811.25Slukem $1; 821.34Sabs if (length($1) > len) 831.34Sabs printf "Login %s has more than "len" characters.\n", $1; 841.15Smrg if ($2 == "") 851.25Slukem printf "Login %s has no password.\n", $1; 861.33Stv if (length($2) != 13 && length($2) != 20 && $2 != "") { 871.25Slukem if ($10 == "" || shells[$10]) 881.27Slukem printf "Login %s is off but still has a valid shell (%s)\n", 891.25Slukem $1, $10; 901.25Slukem } else if (! shells[$10]) 911.25Slukem printf "Login %s does not have a valid shell (%s)\n", 921.25Slukem $1, $10; 931.15Smrg if ($3 == 0 && $1 != "root" && $1 != "toor") 941.25Slukem printf "Login %s has a user id of 0.\n", $1; 951.15Smrg if ($3 < 0) 961.25Slukem printf "Login %s has a negative user id.\n", $1; 971.15Smrg if ($4 < 0) 981.25Slukem printf "Login %s has a negative group id.\n", $1; 991.15Smrg }' < $MP > $OUTPUT 1001.15Smrg if [ -s $OUTPUT ] ; then 1011.15Smrg printf "\nChecking the $MP file:\n" 1021.15Smrg cat $OUTPUT 1031.15Smrg fi 1041.15Smrg 1051.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 1061.15Smrg if [ -s $OUTPUT ] ; then 1071.15Smrg printf "\n$MP has duplicate user names.\n" 1081.15Smrg column $OUTPUT 1091.15Smrg fi 1101.15Smrg 1111.37Swrstuden# To not exclude 'toor', a standard duplicate root account, from the duplicate 1121.37Swrstuden# account test, uncomment the line below (without egrep in it)and comment 1131.37Swrstuden# out the line (with egrep in it) below it. 1141.37Swrstuden# 1151.37Swrstuden# < $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2 1161.36Swrstuden < $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2 1171.15Smrg if [ -s $TMP2 ] ; then 1181.15Smrg printf "\n$MP has duplicate user id's.\n" 1191.15Smrg while read uid; do 1201.28Slukem grep -w $uid $MPBYUID 1211.15Smrg done < $TMP2 | column 1221.15Smrg fi 1231.9Scgdfi 1241.9Scgd 1251.9Scgd# Backup the master password file; a special case, the normal backup 1261.9Scgd# mechanisms also print out file differences and we don't want to do 1271.9Scgd# that because this file has encrypted passwords in it. 1281.32Slukem# 1291.9ScgdCUR=/var/backups/`basename $MP`.current 1301.9ScgdBACK=/var/backups/`basename $MP`.backup 1311.9Scgdif [ -s $CUR ] ; then 1321.9Scgd if cmp -s $CUR $MP; then 1331.9Scgd : 1341.9Scgd else 1351.9Scgd cp -p $CUR $BACK 1361.9Scgd cp -p $MP $CUR 1371.38Skleink chown root:wheel $CUR 1381.9Scgd fi 1391.9Scgdelse 1401.9Scgd cp -p $MP $CUR 1411.38Skleink chown root:wheel $CUR 1421.9Scgdfi 1431.9Scgd 1441.9Scgd# Check the group file syntax. 1451.32Slukem# 1461.31Slukemif checkyesno check_group; then 1471.15Smrg GRP=/etc/group 1481.15Smrg awk -F: '{ 1491.15Smrg if ($0 ~ /^[ ]*$/) { 1501.25Slukem printf "Line %d is a blank line.\n", NR; 1511.15Smrg next; 1521.15Smrg } 1531.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 1541.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 1551.34Sabs if ($1 == "+" ) { 1561.34Sabs next; 1571.34Sabs } 1581.15Smrg if ($1 !~ /^[A-za-z0-9]*$/) 1591.25Slukem printf "Group %s has non-alphanumeric characters.\n", 1601.25Slukem $1; 1611.15Smrg if (length($1) > 8) 1621.25Slukem printf "Group %s has more than 8 characters.\n", $1; 1631.15Smrg if ($3 !~ /[0-9]*/) 1641.25Slukem printf "Login %s has a negative group id.\n", $1; 1651.15Smrg }' < $GRP > $OUTPUT 1661.15Smrg if [ -s $OUTPUT ] ; then 1671.15Smrg printf "\nChecking the $GRP file:\n" 1681.15Smrg cat $OUTPUT 1691.15Smrg fi 1701.15Smrg 1711.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 1721.15Smrg if [ -s $OUTPUT ] ; then 1731.15Smrg printf "\n$GRP has duplicate group names.\n" 1741.15Smrg column $OUTPUT 1751.15Smrg fi 1761.9Scgdfi 1771.9Scgd 1781.9Scgd# Check for root paths, umask values in startup files. 1791.9Scgd# The check for the root paths is problematical -- it's likely to fail 1801.9Scgd# in other environments. Once the shells have been modified to warn 1811.9Scgd# of '.' in the path, the path tests should go away. 1821.32Slukem# 1831.31Slukemif checkyesno check_rootdotfiles; then 1841.28Slukem > $OUTPUT 1851.15Smrg rhome=`csh -fc "echo ~root"` 1861.15Smrg umaskset=no 1871.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 1881.15Smrg for i in $list ; do 1891.15Smrg if [ -f $i ] ; then 1901.45Ssommerfe if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; then 1911.15Smrg umaskset=yes 1921.15Smrg fi 1931.45Ssommerfe # double check the umask value itself; ensure that both the 1941.45Ssommerfe # 020 and 002 bits are set. 1951.45Ssommerfe # we handle this in decimal initially to extract the digits, 1961.45Ssommerfe # and then extract the `2' bit of each digit. 1971.45Ssommerfe # this is made especially painful because 1981.45Ssommerfe # bitwise operations were left out of awk. 1991.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 2001.45Ssommerfe awk '{ g= ($2 % 100) - ($2 % 10); 2011.45Ssommerfe g /= 10; 2021.45Ssommerfe g = g % 4; 2031.45Ssommerfe g -= g % 2; 2041.45Ssommerfe if (g != 2) { print "\tRoot umask is group writeable" } 2051.45Ssommerfe o = ($2 % 10); 2061.45Ssommerfe o = o % 4; 2071.45Ssommerfe o -= o % 2; 2081.45Ssommerfe if (o != 2) { print "\tRoot umask is other writeable" } }' | 2091.45Ssommerfe sort -u >> $OUTPUT 2101.26Slukem SAVE_PATH=$PATH 2111.26Slukem unset PATH 2121.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 2131.15Smrg source $i 2141.15Smrg /bin/ls -ldgT \$path > $TMP1 2151.9Scgdend-of-csh 2161.26Slukem PATH=$SAVE_PATH 2171.15Smrg awk '{ 2181.15Smrg if ($10 ~ /^\.$/) { 2191.27Slukem print "\tThe root path includes ."; 2201.15Smrg next; 2211.15Smrg } 2221.15Smrg } 2231.15Smrg $1 ~ /^d....w/ \ 2241.27Slukem { print "\tRoot path directory " $10 " is group writeable." } \ 2251.15Smrg $1 ~ /^d.......w/ \ 2261.27Slukem { print "\tRoot path directory " $10 " is other writeable." }' \ 2271.15Smrg < $TMP1 >> $OUTPUT 2281.15Smrg fi 2291.15Smrg done 2301.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 2311.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 2321.15Smrg if [ -s $OUTPUT ]; then 2331.15Smrg cat $OUTPUT 2341.15Smrg fi 2351.15Smrg if [ $umaskset = "no" ] ; then 2361.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 2371.15Smrg fi 2381.9Scgd fi 2391.9Scgd 2401.28Slukem > $OUTPUT 2411.15Smrg rhome=/root 2421.15Smrg umaskset=no 2431.23Slukem list="/etc/profile ${rhome}/.profile" 2441.15Smrg for i in $list; do 2451.15Smrg if [ -f $i ] ; then 2461.15Smrg if egrep umask $i > /dev/null ; then 2471.15Smrg umaskset=yes 2481.15Smrg fi 2491.15Smrg egrep umask $i | 2501.15Smrg awk '$2 % 100 < 20 \ 2511.27Slukem { print "\tRoot umask is group writeable" } \ 2521.15Smrg $2 % 10 < 2 \ 2531.27Slukem { print "\tRoot umask is other writeable" }' \ 2541.27Slukem >> $OUTPUT 2551.26Slukem SAVE_PATH=$PATH 2561.26Slukem unset PATH 2571.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 2581.15Smrg . $i 2591.26Slukem list=\`echo \$PATH | /usr/bin/sed -e \ 2601.26Slukem 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\` 2611.15Smrg /bin/ls -ldgT \$list > $TMP1 2621.9Scgdend-of-sh 2631.26Slukem PATH=$SAVE_PATH 2641.15Smrg awk '{ 2651.15Smrg if ($10 ~ /^\.$/) { 2661.27Slukem print "\tThe root path includes ."; 2671.15Smrg next; 2681.15Smrg } 2691.15Smrg } 2701.15Smrg $1 ~ /^d....w/ \ 2711.27Slukem { print "\tRoot path directory " $10 " is group writeable." } \ 2721.15Smrg $1 ~ /^d.......w/ \ 2731.27Slukem { print "\tRoot path directory " $10 " is other writeable." }' \ 2741.15Smrg < $TMP1 >> $OUTPUT 2751.9Scgd 2761.15Smrg fi 2771.15Smrg done 2781.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 2791.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 2801.15Smrg if [ -s $OUTPUT ]; then 2811.15Smrg cat $OUTPUT 2821.15Smrg fi 2831.15Smrg if [ $umaskset = "no" ] ; then 2841.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 2851.15Smrg fi 2861.9Scgd fi 2871.9Scgdfi 2881.9Scgd 2891.9Scgd# Root and uucp should both be in /etc/ftpusers. 2901.32Slukem# 2911.31Slukemif checkyesno check_ftpusers; then 2921.28Slukem > $OUTPUT 2931.28Slukem list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID` 2941.27Slukem for i in $list; do 2951.29Slukem if /usr/libexec/ftpd -C $i ; then 2961.29Slukem printf "\t$i is not denied\n" >> $OUTPUT 2971.27Slukem fi 2981.27Slukem done 2991.28Slukem if [ -s $OUTPUT ]; then 3001.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 3011.28Slukem cat $OUTPUT 3021.28Slukem fi 3031.9Scgdfi 3041.9Scgd 3051.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 3061.32Slukem# 3071.31Slukemif checkyesno check_aliases; then 3081.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 3091.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 3101.43Sitojun printf "\nEntry for uudecode in $f file.\n" 3111.43Sitojun fi 3121.43Sitojun done 3131.9Scgdfi 3141.9Scgd 3151.9Scgd# Files that should not have + signs. 3161.32Slukem# 3171.31Slukemif checkyesno check_rhosts; then 3181.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 3191.15Smrg for f in $list ; do 3201.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 3211.15Smrg printf "\nPlus sign in $f file.\n" 3221.15Smrg fi 3231.15Smrg done 3241.15Smrg 3251.15Smrg # Check for special users with .rhosts files. Only root and toor should 3261.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 3271.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 3281.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 3291.20Smycroft { print $1 " " $9 }' $MP | 3301.19Smycroft sort -k2 | 3311.15Smrg while read uid homedir; do 3321.15Smrg if [ -f ${homedir}/.rhosts ] ; then 3331.15Smrg rhost=`ls -ldgT ${homedir}/.rhosts` 3341.15Smrg printf "$uid: $rhost\n" 3351.15Smrg fi 3361.15Smrg done > $OUTPUT 3371.15Smrg if [ -s $OUTPUT ] ; then 3381.15Smrg printf "\nChecking for special users with .rhosts files.\n" 3391.15Smrg cat $OUTPUT 3401.15Smrg fi 3411.15Smrg 3421.15Smrg while read uid homedir; do 3431.35Sfair if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 3441.41Schristos cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 3451.15Smrg printf "$uid: + in .rhosts file.\n" 3461.15Smrg fi 3471.29Slukem done < $MPBYPATH > $OUTPUT 3481.15Smrg if [ -s $OUTPUT ] ; then 3491.15Smrg printf "\nChecking .rhosts files syntax.\n" 3501.15Smrg cat $OUTPUT 3511.15Smrg fi 3521.9Scgdfi 3531.9Scgd 3541.9Scgd# Check home directories. Directories should not be owned by someone else 3551.9Scgd# or writeable. 3561.32Slukem# 3571.31Slukemif checkyesno check_homes; then 3581.15Smrg while read uid homedir; do 3591.15Smrg if [ -d ${homedir}/ ] ; then 3601.15Smrg file=`ls -ldgT ${homedir}` 3611.15Smrg printf "$uid $file\n" 3621.9Scgd fi 3631.29Slukem done < $MPBYPATH | 3641.15Smrg awk '$1 != $4 && $4 != "root" \ 3651.15Smrg { print "user " $1 " home directory is owned by " $4 } 3661.15Smrg $2 ~ /^-....w/ \ 3671.15Smrg { print "user " $1 " home directory is group writeable" } 3681.15Smrg $2 ~ /^-.......w/ \ 3691.27Slukem { print "user " $1 " home directory is other writeable" }' \ 3701.27Slukem > $OUTPUT 3711.15Smrg if [ -s $OUTPUT ] ; then 3721.15Smrg printf "\nChecking home directories.\n" 3731.15Smrg cat $OUTPUT 3741.15Smrg fi 3751.15Smrg 3761.15Smrg # Files that should not be owned by someone else or readable. 3771.27Slukem list=".Xauthority .netrc" 3781.15Smrg while read uid homedir; do 3791.15Smrg for f in $list ; do 3801.15Smrg file=${homedir}/${f} 3811.15Smrg if [ -f $file ] ; then 3821.15Smrg printf "$uid $f `ls -ldgT $file`\n" 3831.15Smrg fi 3841.15Smrg done 3851.29Slukem done < $MPBYPATH | 3861.15Smrg awk '$1 != $5 && $5 != "root" \ 3871.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 3881.15Smrg $3 ~ /^-...r/ \ 3891.15Smrg { print "user " $1 " " $2 " file is group readable" } 3901.15Smrg $3 ~ /^-......r/ \ 3911.15Smrg { print "user " $1 " " $2 " file is other readable" } 3921.15Smrg $3 ~ /^-....w/ \ 3931.15Smrg { print "user " $1 " " $2 " file is group writeable" } 3941.15Smrg $3 ~ /^-.......w/ \ 3951.27Slukem { print "user " $1 " " $2 " file is other writeable" }' \ 3961.27Slukem > $OUTPUT 3971.15Smrg 3981.15Smrg # Files that should not be owned by someone else or writeable. 3991.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 4001.19Smycroft .cshrc .emacs .exrc .forward .history .klogin .login .logout \ 4011.27Slukem .profile .qmail .rc_history .rhosts .tcshrc .twmrc .xinitrc \ 4021.27Slukem .xsession" 4031.15Smrg while read uid homedir; do 4041.15Smrg for f in $list ; do 4051.15Smrg file=${homedir}/${f} 4061.15Smrg if [ -f $file ] ; then 4071.15Smrg printf "$uid $f `ls -ldgT $file`\n" 4081.15Smrg fi 4091.15Smrg done 4101.29Slukem done < $MPBYPATH | 4111.15Smrg awk '$1 != $5 && $5 != "root" \ 4121.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 4131.15Smrg $3 ~ /^-....w/ \ 4141.15Smrg { print "user " $1 " " $2 " file is group writeable" } 4151.15Smrg $3 ~ /^-.......w/ \ 4161.27Slukem { print "user " $1 " " $2 " file is other writeable" }' \ 4171.27Slukem >> $OUTPUT 4181.15Smrg if [ -s $OUTPUT ] ; then 4191.15Smrg printf "\nChecking dot files.\n" 4201.15Smrg cat $OUTPUT 4211.15Smrg fi 4221.9Scgdfi 4231.9Scgd 4241.9Scgd# Mailboxes should be owned by user and unreadable. 4251.32Slukem# 4261.31Slukemif checkyesno check_varmail; then 4271.15Smrg ls -l /var/mail | sed 1d | \ 4281.15Smrg awk '$3 != $9 \ 4291.15Smrg { print "user " $9 " mailbox is owned by " $3 } 4301.15Smrg $1 != "-rw-------" \ 4311.15Smrg { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT 4321.15Smrg if [ -s $OUTPUT ] ; then 4331.15Smrg printf "\nChecking mailbox ownership.\n" 4341.15Smrg cat $OUTPUT 4351.15Smrg fi 4361.15Smrgfi 4371.15Smrg 4381.32Slukem# NFS exports shouldn't be globally exported 4391.32Slukem# 4401.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 4411.32Slukem awk '{ 4421.22Slukem # ignore comments and blank lines 4431.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 4441.22Slukem next; 4451.22Slukem 4461.15Smrg readonly = 0; 4471.15Smrg for (i = 2; i <= NF; ++i) { 4481.15Smrg if ($i ~ /-ro/) 4491.15Smrg readonly = 1; 4501.15Smrg else if ($i !~ /^-/) 4511.15Smrg next; 4521.15Smrg } 4531.15Smrg if (readonly) 4541.15Smrg print "File system " $1 " globally exported, read-only." 4551.15Smrg else 4561.15Smrg print "File system " $1 " globally exported, read-write." 4571.32Slukem }' < /etc/exports > $OUTPUT 4581.32Slukem if [ -s $OUTPUT ] ; then 4591.15Smrg printf "\nChecking for globally exported file systems.\n" 4601.15Smrg cat $OUTPUT 4611.15Smrg fi 4621.9Scgdfi 4631.9Scgd 4641.9Scgd# Display any changes in setuid files and devices. 4651.32Slukem# 4661.31Slukemif checkyesno check_devices; then 4671.28Slukem > $ERR 4681.15Smrg (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \ 4691.15Smrg -o -fstype procfs \) -a -prune -o \ 4701.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 4711.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 4721.24Slukem -type b -o -type c \) -print0 | \ 4731.24Slukem xargs -0 ls -ldgTq | sort +9 > $LIST) 2> $OUTPUT 4741.15Smrg 4751.15Smrg # Display any errors that occurred during system file walk. 4761.15Smrg if [ -s $OUTPUT ] ; then 4771.28Slukem printf "Setuid/device find errors:\n" >> $ERR 4781.28Slukem cat $OUTPUT >> $ERR 4791.28Slukem printf "\n" >> $ERR 4801.15Smrg fi 4811.15Smrg 4821.15Smrg # Display any changes in the setuid file list. 4831.15Smrg egrep -v '^[bc]' $LIST > $TMP1 4841.15Smrg if [ -s $TMP1 ] ; then 4851.15Smrg # Check to make sure uudecode isn't setuid. 4861.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 4871.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 4881.15Smrg fi 4891.15Smrg 4901.15Smrg CUR=/var/backups/setuid.current 4911.15Smrg BACK=/var/backups/setuid.backup 4921.9Scgd 4931.15Smrg if [ -s $CUR ] ; then 4941.15Smrg if cmp -s $CUR $TMP1 ; then 4951.15Smrg : 4961.15Smrg else 4971.15Smrg > $TMP2 4981.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 4991.15Smrg if [ -s $OUTPUT ] ; then 5001.28Slukem printf "Setuid additions:\n" >> $ERR 5011.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5021.28Slukem printf "\n" >> $ERR 5031.15Smrg fi 5041.15Smrg 5051.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 5061.15Smrg if [ -s $OUTPUT ] ; then 5071.28Slukem printf "Setuid deletions:\n" >> $ERR 5081.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5091.28Slukem printf "\n" >> $ERR 5101.15Smrg fi 5111.15Smrg 5121.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 5131.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 5141.27Slukem uniq -u > $OUTPUT 5151.15Smrg if [ -s $OUTPUT ] ; then 5161.28Slukem printf "Setuid changes:\n" >> $ERR 5171.28Slukem column -t $OUTPUT >> $ERR 5181.28Slukem printf "\n" >> $ERR 5191.15Smrg fi 5201.9Scgd 5211.15Smrg cp $CUR $BACK 5221.15Smrg cp $TMP1 $CUR 5231.9Scgd fi 5241.15Smrg else 5251.28Slukem printf "Setuid additions:\n" >> $ERR 5261.28Slukem column -t $TMP1 >> $ERR 5271.28Slukem printf "\n" >> $ERR 5281.9Scgd cp $TMP1 $CUR 5291.9Scgd fi 5301.15Smrg fi 5311.15Smrg 5321.27Slukem # Check for block and character disk devices that are readable or 5331.27Slukem # writeable or not owned by root.operator. 5341.15Smrg >$TMP1 5351.27Slukem DISKLIST="acd ccd cd ch fd hk hp mcd md ra rb rd rl rx rz \ 5361.27Slukem sd se ss tz uk up vnd wd xd xy" 5371.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 5381.15Smrg for i in $DISKLIST; do 5391.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 5401.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 5411.15Smrg done 5421.15Smrg 5431.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 5441.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 5451.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 5461.15Smrg if [ -s $OUTPUT ] ; then 5471.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 5481.28Slukem cat $OUTPUT >> $ERR 5491.28Slukem printf "\n" >> $ERR 5501.9Scgd fi 5511.9Scgd 5521.15Smrg # Display any changes in the device file list. 5531.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 5541.15Smrg if [ -s $TMP1 ] ; then 5551.15Smrg CUR=/var/backups/device.current 5561.15Smrg BACK=/var/backups/device.backup 5571.15Smrg 5581.15Smrg if [ -s $CUR ] ; then 5591.15Smrg if cmp -s $CUR $TMP1 ; then 5601.15Smrg : 5611.15Smrg else 5621.15Smrg > $TMP2 5631.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 5641.15Smrg if [ -s $OUTPUT ] ; then 5651.28Slukem printf "Device additions:\n" >> $ERR 5661.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5671.28Slukem printf "\n" >> $ERR 5681.15Smrg fi 5691.15Smrg 5701.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 5711.15Smrg if [ -s $OUTPUT ] ; then 5721.28Slukem printf "Device deletions:\n" >> $ERR 5731.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5741.28Slukem printf "\n" >> $ERR 5751.15Smrg fi 5761.15Smrg 5771.27Slukem # Report any block device change. Ignore 5781.27Slukem # character devices, only the name is 5791.27Slukem # significant. 5801.15Smrg cat $TMP2 $CUR $TMP1 | \ 5811.27Slukem sed -e '/^c/d' | \ 5821.27Slukem sort -k11 | \ 5831.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 5841.27Slukem uniq -u > $OUTPUT 5851.15Smrg if [ -s $OUTPUT ] ; then 5861.28Slukem printf "Block device changes:\n" >> $ERR 5871.28Slukem column -t $OUTPUT >> $ERR 5881.28Slukem printf "\n" >> $ERR 5891.15Smrg fi 5901.9Scgd 5911.15Smrg cp $CUR $BACK 5921.15Smrg cp $TMP1 $CUR 5931.9Scgd fi 5941.15Smrg else 5951.28Slukem printf "Device additions:\n" >> $ERR 5961.28Slukem column -t $TMP1 >> $ERR 5971.28Slukem printf "\n" >> $ERR 5981.28Slukem cp $TMP1 $CUR >> $ERR 5991.9Scgd fi 6001.28Slukem fi 6011.28Slukem if [ -s $ERR ] ; then 6021.28Slukem printf "\nChecking setuid files and devices:\n" 6031.28Slukem cat $ERR 6041.28Slukem printf "\n" 6051.9Scgd fi 6061.9Scgdfi 6071.9Scgd 6081.9Scgd# Check special files. 6091.9Scgd# Check system binaries. 6101.9Scgd# 6111.9Scgd# Create the mtree tree specifications using: 6121.9Scgd# 6131.9Scgd# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure 6141.38Skleink# chown root:wheel DIR.secure 6151.16Smikel# chmod 600 DIR.secure 6161.9Scgd# 6171.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 6181.9Scgd# the hacker can modify the tree specification to match the replaced binary. 6191.9Scgd# For details on really protecting yourself against modified binaries, see 6201.9Scgd# the mtree(8) manual page. 6211.32Slukem# 6221.31Slukemif checkyesno check_mtree; then 6231.9Scgd mtree -e -p / -f /etc/mtree/special > $OUTPUT 6241.15Smrg if [ -s $OUTPUT ]; then 6251.9Scgd printf "\nChecking special files and directories.\n" 6261.9Scgd cat $OUTPUT 6271.9Scgd fi 6281.9Scgd 6291.9Scgd > $OUTPUT 6301.16Smikel for file in /etc/mtree/*.secure; do 6311.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 6321.9Scgd tree=`sed -n -e '3s/.* //p' -e 3q $file` 6331.9Scgd mtree -f $file -p $tree > $TMP1 6341.9Scgd if [ -s $TMP1 ]; then 6351.9Scgd printf "\nChecking $tree:\n" >> $OUTPUT 6361.9Scgd cat $TMP1 >> $OUTPUT 6371.9Scgd fi 6381.9Scgd done 6391.15Smrg if [ -s $OUTPUT ]; then 6401.9Scgd printf "\nChecking system binaries:\n" 6411.9Scgd cat $OUTPUT 6421.9Scgd fi 6431.9Scgdfi 6441.9Scgd 6451.32SlukemCHANGELIST="" 6461.32Slukem 6471.32Slukem# Backup disklabels of available disks 6481.32Slukem# 6491.32Slukemif checkyesno check_disklabels; then 6501.32Slukem # generate list of old disklabels and remove them 6511.32Slukem ls -1d /var/backups/disklabel.* 2>/dev/null | 6521.32Slukem egrep -v '\.(backup|current)$' > $LABELS 6531.32Slukem xargs rm < $LABELS 6541.32Slukem 6551.40Sperry disks=`iostat -x | sed 1d | awk '$1 !~ /^[cfm]d/ { print $1; }'` 6561.32Slukem for i in $disks; do 6571.32Slukem dlf="/var/backups/disklabel.$i" 6581.32Slukem disklabel $i > $dlf 2>/dev/null 6591.32Slukem done 6601.32Slukem 6611.32Slukem # append list of new disklabels, sort list 6621.32Slukem ls -1d /var/backups/disklabel.* 2>/dev/null | 6631.32Slukem egrep -v '\.(backup|current)$' >> $LABELS 6641.32Slukem sort -u -o $LABELS $LABELS 6651.32Slukem CHANGELIST=$LABELS 6661.32Slukemfi 6671.32Slukem 6681.9Scgd# List of files that get backed up and checked for any modifications. Each 6691.9Scgd# file is expected to have two backups, /var/backups/file.{current,backup}. 6701.9Scgd# Any changes cause the files to rotate. 6711.32Slukem# 6721.31Slukemif checkyesno check_changelist && [ -s /etc/changelist ] ; then 6731.32Slukem CHANGELIST="/etc/changelist $CHANGELIST" 6741.32Slukemfi 6751.32Slukem 6761.32Slukemif [ -n "$CHANGELIST" ]; then 6771.32Slukem for file in `egrep -hv "^#|$MP" $CHANGELIST`; do 6781.9Scgd CUR=/var/backups/`basename $file`.current 6791.9Scgd BACK=/var/backups/`basename $file`.backup 6801.30Smycroft if [ -f $file ]; then 6811.30Smycroft if [ -f $CUR ] ; then 6821.9Scgd diff $CUR $file > $OUTPUT 6831.9Scgd if [ -s $OUTPUT ] ; then 6841.9Scgd printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file 6851.9Scgd cat $OUTPUT 6861.30Smycroft mv -f $CUR $BACK 6871.9Scgd cp -p $file $CUR 6881.38Skleink chown root:wheel $CUR 6891.9Scgd fi 6901.9Scgd else 6911.30Smycroft printf "\n======\n%s added\n======\n" $file 6921.30Smycroft diff /dev/null $file 6931.9Scgd cp -p $file $CUR 6941.38Skleink chown root:wheel $CUR 6951.30Smycroft fi 6961.30Smycroft else 6971.30Smycroft if [ -f $CUR ]; then 6981.30Smycroft printf "\n======\n%s removed\n======\n" $file 6991.30Smycroft diff $CUR /dev/null 7001.30Smycroft mv -f $CUR $BACK 7011.9Scgd fi 7021.9Scgd fi 7031.9Scgd done 7041.42Sfairfi 7051.42Sfair 7061.42Sfair# run skeyaudit to inform users of ready to expire S/Keys 7071.42Sfair# 7081.42Sfairif checkyesno run_skeyaudit; then 7091.42Sfair skeyaudit 7101.44Sadfi 7111.44Sad 7121.44Sadif [ -f /etc/security.local ]; then 7131.44Sad echo "" 7141.44Sad echo "Running /etc/security.local:" 7151.44Sad . /etc/security.local 7161.9Scgdfi 717