security revision 1.49
11.1Scgd#!/bin/sh - 21.1Scgd# 31.49Sjdolecek# $NetBSD: security,v 1.49 2001/02/11 09:55:09 jdolecek 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.49Sjdolecekif [ -z "$max_grouplen" ]; then 381.49Sjdolecek max_grouplen=8 391.49Sjdolecekfi 401.49Sjdolecek 411.15SmrgERR=secure1.$$ 421.15SmrgTMP1=secure2.$$ 431.15SmrgTMP2=secure3.$$ 441.28SlukemMPBYUID=secure4.$$ 451.29SlukemMPBYPATH=secure5.$$ 461.27SlukemLIST=secure6.$$ 471.27SlukemOUTPUT=secure7.$$ 481.32SlukemLABELS=secure8.$$ 491.15Smrg 501.27Slukemtrap '/bin/rm -rf $SECUREDIR ; exit 0' 0 2 3 511.15Smrg 521.48Sabs# Handle backup_dir not being set in .conf file 531.48Sabsbackup_dir=${backup_dir:-/var/backups} 541.48Sabs 551.15SmrgMP=/etc/master.passwd 561.9Scgd 571.27Slukem# these is used several times. 581.34Sabsawk -F: '!/^+/ { print $1 " " $3 }' $MP | sort -k2n > $MPBYUID 591.29Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPBYPATH 601.9Scgd 611.9Scgd# Check the master password file syntax. 621.32Slukem# 631.31Slukemif checkyesno check_passwd; then 641.34Sabs awk -v "len=$max_loginlen" ' 651.25Slukem BEGIN { 661.25Slukem while ( getline < "/etc/shells" > 0 ) { 671.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 681.25Slukem continue; 691.25Slukem shells[$1]++; 701.25Slukem } 711.25Slukem FS=":"; 721.25Slukem } 731.25Slukem 741.25Slukem { 751.15Smrg if ($0 ~ /^[ ]*$/) { 761.25Slukem printf "Line %d is a blank line.\n", NR; 771.15Smrg next; 781.15Smrg } 791.34Sabs if (NF != 10 && ($1 != "+" || NF != 1)) 801.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 811.34Sabs if ($1 == "+" ) { 821.34Sabs if (NF != 1 && $3 == 0) 831.34Sabs printf "Line %d includes entries with uid 0.\n", NR; 841.34Sabs next; 851.34Sabs } 861.15Smrg if ($1 !~ /^[A-Za-z0-9]*$/) 871.25Slukem printf "Login %s has non-alphanumeric characters.\n", 881.25Slukem $1; 891.34Sabs if (length($1) > len) 901.34Sabs printf "Login %s has more than "len" characters.\n", $1; 911.15Smrg if ($2 == "") 921.25Slukem printf "Login %s has no password.\n", $1; 931.33Stv if (length($2) != 13 && length($2) != 20 && $2 != "") { 941.25Slukem if ($10 == "" || shells[$10]) 951.27Slukem printf "Login %s is off but still has a valid shell (%s)\n", 961.25Slukem $1, $10; 971.25Slukem } else if (! shells[$10]) 981.25Slukem printf "Login %s does not have a valid shell (%s)\n", 991.25Slukem $1, $10; 1001.15Smrg if ($3 == 0 && $1 != "root" && $1 != "toor") 1011.25Slukem printf "Login %s has a user id of 0.\n", $1; 1021.15Smrg if ($3 < 0) 1031.25Slukem printf "Login %s has a negative user id.\n", $1; 1041.15Smrg if ($4 < 0) 1051.25Slukem printf "Login %s has a negative group id.\n", $1; 1061.15Smrg }' < $MP > $OUTPUT 1071.15Smrg if [ -s $OUTPUT ] ; then 1081.15Smrg printf "\nChecking the $MP file:\n" 1091.15Smrg cat $OUTPUT 1101.15Smrg fi 1111.15Smrg 1121.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 1131.15Smrg if [ -s $OUTPUT ] ; then 1141.15Smrg printf "\n$MP has duplicate user names.\n" 1151.15Smrg column $OUTPUT 1161.15Smrg fi 1171.15Smrg 1181.37Swrstuden# To not exclude 'toor', a standard duplicate root account, from the duplicate 1191.37Swrstuden# account test, uncomment the line below (without egrep in it)and comment 1201.37Swrstuden# out the line (with egrep in it) below it. 1211.37Swrstuden# 1221.37Swrstuden# < $MPBYUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2 1231.36Swrstuden < $MPBYUID egrep -v '^toor ' | uniq -d -f 1 | awk '{ print $2 }' > $TMP2 1241.15Smrg if [ -s $TMP2 ] ; then 1251.15Smrg printf "\n$MP has duplicate user id's.\n" 1261.15Smrg while read uid; do 1271.28Slukem grep -w $uid $MPBYUID 1281.15Smrg done < $TMP2 | column 1291.15Smrg fi 1301.9Scgdfi 1311.9Scgd 1321.9Scgd# Backup the master password file; a special case, the normal backup 1331.9Scgd# mechanisms also print out file differences and we don't want to do 1341.9Scgd# that because this file has encrypted passwords in it. 1351.32Slukem# 1361.48SabsCUR=$backup_dir/${MP##*/}.current 1371.48SabsBACK=$backup_dir/${MP##*/}.backup 1381.9Scgdif [ -s $CUR ] ; then 1391.9Scgd if cmp -s $CUR $MP; then 1401.9Scgd : 1411.9Scgd else 1421.9Scgd cp -p $CUR $BACK 1431.9Scgd cp -p $MP $CUR 1441.38Skleink chown root:wheel $CUR 1451.9Scgd fi 1461.9Scgdelse 1471.9Scgd cp -p $MP $CUR 1481.38Skleink chown root:wheel $CUR 1491.9Scgdfi 1501.9Scgd 1511.9Scgd# Check the group file syntax. 1521.32Slukem# 1531.31Slukemif checkyesno check_group; then 1541.15Smrg GRP=/etc/group 1551.49Sjdolecek awk -F: -v "len=$max_grouplen" '{ 1561.15Smrg if ($0 ~ /^[ ]*$/) { 1571.25Slukem printf "Line %d is a blank line.\n", NR; 1581.15Smrg next; 1591.15Smrg } 1601.34Sabs if (NF != 4 && ($1 != "+" || NF != 1)) 1611.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 1621.34Sabs if ($1 == "+" ) { 1631.34Sabs next; 1641.34Sabs } 1651.15Smrg if ($1 !~ /^[A-za-z0-9]*$/) 1661.25Slukem printf "Group %s has non-alphanumeric characters.\n", 1671.25Slukem $1; 1681.49Sjdolecek if (length($1) > len) 1691.49Sjdolecek printf "Group %s has more than "len" characters.\n", $1; 1701.15Smrg if ($3 !~ /[0-9]*/) 1711.25Slukem printf "Login %s has a negative group id.\n", $1; 1721.15Smrg }' < $GRP > $OUTPUT 1731.15Smrg if [ -s $OUTPUT ] ; then 1741.15Smrg printf "\nChecking the $GRP file:\n" 1751.15Smrg cat $OUTPUT 1761.15Smrg fi 1771.15Smrg 1781.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 1791.15Smrg if [ -s $OUTPUT ] ; then 1801.15Smrg printf "\n$GRP has duplicate group names.\n" 1811.15Smrg column $OUTPUT 1821.15Smrg fi 1831.9Scgdfi 1841.9Scgd 1851.9Scgd# Check for root paths, umask values in startup files. 1861.9Scgd# The check for the root paths is problematical -- it's likely to fail 1871.9Scgd# in other environments. Once the shells have been modified to warn 1881.9Scgd# of '.' in the path, the path tests should go away. 1891.32Slukem# 1901.31Slukemif checkyesno check_rootdotfiles; then 1911.28Slukem > $OUTPUT 1921.15Smrg rhome=`csh -fc "echo ~root"` 1931.15Smrg umaskset=no 1941.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 1951.15Smrg for i in $list ; do 1961.15Smrg if [ -f $i ] ; then 1971.45Ssommerfe if egrep '^[ \t]*umask[ \t]+[0-7]+' $i > /dev/null ; then 1981.15Smrg umaskset=yes 1991.15Smrg fi 2001.45Ssommerfe # double check the umask value itself; ensure that both the 2011.45Ssommerfe # 020 and 002 bits are set. 2021.45Ssommerfe # we handle this in decimal initially to extract the digits, 2031.45Ssommerfe # and then extract the `2' bit of each digit. 2041.45Ssommerfe # this is made especially painful because 2051.45Ssommerfe # bitwise operations were left out of awk. 2061.45Ssommerfe egrep '^[ \t]*umask[ \t]+[0-7]+' $i | 2071.45Ssommerfe awk '{ g= ($2 % 100) - ($2 % 10); 2081.45Ssommerfe g /= 10; 2091.45Ssommerfe g = g % 4; 2101.45Ssommerfe g -= g % 2; 2111.45Ssommerfe if (g != 2) { print "\tRoot umask is group writeable" } 2121.45Ssommerfe o = ($2 % 10); 2131.45Ssommerfe o = o % 4; 2141.45Ssommerfe o -= o % 2; 2151.45Ssommerfe if (o != 2) { print "\tRoot umask is other writeable" } }' | 2161.45Ssommerfe sort -u >> $OUTPUT 2171.26Slukem SAVE_PATH=$PATH 2181.26Slukem unset PATH 2191.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 2201.15Smrg source $i 2211.15Smrg /bin/ls -ldgT \$path > $TMP1 2221.9Scgdend-of-csh 2231.26Slukem PATH=$SAVE_PATH 2241.15Smrg awk '{ 2251.15Smrg if ($10 ~ /^\.$/) { 2261.27Slukem print "\tThe root path includes ."; 2271.15Smrg next; 2281.15Smrg } 2291.15Smrg } 2301.15Smrg $1 ~ /^d....w/ \ 2311.27Slukem { print "\tRoot path directory " $10 " is group writeable." } \ 2321.15Smrg $1 ~ /^d.......w/ \ 2331.27Slukem { print "\tRoot path directory " $10 " is other writeable." }' \ 2341.15Smrg < $TMP1 >> $OUTPUT 2351.15Smrg fi 2361.15Smrg done 2371.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 2381.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 2391.15Smrg if [ -s $OUTPUT ]; then 2401.15Smrg cat $OUTPUT 2411.15Smrg fi 2421.15Smrg if [ $umaskset = "no" ] ; then 2431.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 2441.15Smrg fi 2451.9Scgd fi 2461.9Scgd 2471.28Slukem > $OUTPUT 2481.15Smrg rhome=/root 2491.15Smrg umaskset=no 2501.23Slukem list="/etc/profile ${rhome}/.profile" 2511.15Smrg for i in $list; do 2521.15Smrg if [ -f $i ] ; then 2531.15Smrg if egrep umask $i > /dev/null ; then 2541.15Smrg umaskset=yes 2551.15Smrg fi 2561.15Smrg egrep umask $i | 2571.15Smrg awk '$2 % 100 < 20 \ 2581.27Slukem { print "\tRoot umask is group writeable" } \ 2591.15Smrg $2 % 10 < 2 \ 2601.27Slukem { print "\tRoot umask is other writeable" }' \ 2611.27Slukem >> $OUTPUT 2621.26Slukem SAVE_PATH=$PATH 2631.26Slukem unset PATH 2641.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 2651.15Smrg . $i 2661.26Slukem list=\`echo \$PATH | /usr/bin/sed -e \ 2671.26Slukem 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\` 2681.15Smrg /bin/ls -ldgT \$list > $TMP1 2691.9Scgdend-of-sh 2701.26Slukem PATH=$SAVE_PATH 2711.15Smrg awk '{ 2721.15Smrg if ($10 ~ /^\.$/) { 2731.27Slukem print "\tThe root path includes ."; 2741.15Smrg next; 2751.15Smrg } 2761.15Smrg } 2771.15Smrg $1 ~ /^d....w/ \ 2781.27Slukem { print "\tRoot path directory " $10 " is group writeable." } \ 2791.15Smrg $1 ~ /^d.......w/ \ 2801.27Slukem { print "\tRoot path directory " $10 " is other writeable." }' \ 2811.15Smrg < $TMP1 >> $OUTPUT 2821.9Scgd 2831.15Smrg fi 2841.15Smrg done 2851.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 2861.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 2871.15Smrg if [ -s $OUTPUT ]; then 2881.15Smrg cat $OUTPUT 2891.15Smrg fi 2901.15Smrg if [ $umaskset = "no" ] ; then 2911.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 2921.15Smrg fi 2931.9Scgd fi 2941.9Scgdfi 2951.9Scgd 2961.9Scgd# Root and uucp should both be in /etc/ftpusers. 2971.32Slukem# 2981.31Slukemif checkyesno check_ftpusers; then 2991.28Slukem > $OUTPUT 3001.28Slukem list="uucp "`awk '$2 == 0 { print $1 }' $MPBYUID` 3011.27Slukem for i in $list; do 3021.29Slukem if /usr/libexec/ftpd -C $i ; then 3031.29Slukem printf "\t$i is not denied\n" >> $OUTPUT 3041.27Slukem fi 3051.27Slukem done 3061.28Slukem if [ -s $OUTPUT ]; then 3071.28Slukem printf "\nChecking the /etc/ftpusers configuration:\n" 3081.28Slukem cat $OUTPUT 3091.28Slukem fi 3101.9Scgdfi 3111.9Scgd 3121.43Sitojun# Uudecode should not be in the /etc/mail/aliases file. 3131.32Slukem# 3141.31Slukemif checkyesno check_aliases; then 3151.43Sitojun for f in /etc/mail/aliases /etc/aliases; do 3161.43Sitojun if [ -f $f ] && egrep '^[^#]*(uudecode|decode).*\|' $f; then 3171.43Sitojun printf "\nEntry for uudecode in $f file.\n" 3181.43Sitojun fi 3191.43Sitojun done 3201.9Scgdfi 3211.9Scgd 3221.9Scgd# Files that should not have + signs. 3231.32Slukem# 3241.31Slukemif checkyesno check_rhosts; then 3251.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 3261.15Smrg for f in $list ; do 3271.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 3281.15Smrg printf "\nPlus sign in $f file.\n" 3291.15Smrg fi 3301.15Smrg done 3311.15Smrg 3321.15Smrg # Check for special users with .rhosts files. Only root and toor should 3331.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 3341.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 3351.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 3361.20Smycroft { print $1 " " $9 }' $MP | 3371.19Smycroft sort -k2 | 3381.15Smrg while read uid homedir; do 3391.15Smrg if [ -f ${homedir}/.rhosts ] ; then 3401.15Smrg rhost=`ls -ldgT ${homedir}/.rhosts` 3411.46Schristos printf -- "$uid: $rhost\n" 3421.15Smrg fi 3431.15Smrg done > $OUTPUT 3441.15Smrg if [ -s $OUTPUT ] ; then 3451.15Smrg printf "\nChecking for special users with .rhosts files.\n" 3461.15Smrg cat $OUTPUT 3471.15Smrg fi 3481.15Smrg 3491.15Smrg while read uid homedir; do 3501.35Sfair if [ -f ${homedir}/.rhosts -a -r ${homedir}/.rhosts ] && \ 3511.41Schristos cat -f ${homedir}/.rhosts | egrep '\+' > /dev/null ; then 3521.46Schristos printf -- "$uid: + in .rhosts file.\n" 3531.15Smrg fi 3541.29Slukem done < $MPBYPATH > $OUTPUT 3551.15Smrg if [ -s $OUTPUT ] ; then 3561.15Smrg printf "\nChecking .rhosts files syntax.\n" 3571.15Smrg cat $OUTPUT 3581.15Smrg fi 3591.9Scgdfi 3601.9Scgd 3611.9Scgd# Check home directories. Directories should not be owned by someone else 3621.9Scgd# or writeable. 3631.32Slukem# 3641.31Slukemif checkyesno check_homes; then 3651.15Smrg while read uid homedir; do 3661.15Smrg if [ -d ${homedir}/ ] ; then 3671.15Smrg file=`ls -ldgT ${homedir}` 3681.46Schristos printf -- "$uid $file\n" 3691.9Scgd fi 3701.29Slukem done < $MPBYPATH | 3711.15Smrg awk '$1 != $4 && $4 != "root" \ 3721.15Smrg { print "user " $1 " home directory is owned by " $4 } 3731.15Smrg $2 ~ /^-....w/ \ 3741.15Smrg { print "user " $1 " home directory is group writeable" } 3751.15Smrg $2 ~ /^-.......w/ \ 3761.27Slukem { print "user " $1 " home directory is other writeable" }' \ 3771.27Slukem > $OUTPUT 3781.15Smrg if [ -s $OUTPUT ] ; then 3791.15Smrg printf "\nChecking home directories.\n" 3801.15Smrg cat $OUTPUT 3811.15Smrg fi 3821.15Smrg 3831.15Smrg # Files that should not be owned by someone else or readable. 3841.27Slukem list=".Xauthority .netrc" 3851.15Smrg while read uid homedir; do 3861.15Smrg for f in $list ; do 3871.15Smrg file=${homedir}/${f} 3881.15Smrg if [ -f $file ] ; then 3891.46Schristos printf -- "$uid $f `ls -ldgT $file`\n" 3901.15Smrg fi 3911.15Smrg done 3921.29Slukem done < $MPBYPATH | 3931.15Smrg awk '$1 != $5 && $5 != "root" \ 3941.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 3951.15Smrg $3 ~ /^-...r/ \ 3961.15Smrg { print "user " $1 " " $2 " file is group readable" } 3971.15Smrg $3 ~ /^-......r/ \ 3981.15Smrg { print "user " $1 " " $2 " file is other readable" } 3991.15Smrg $3 ~ /^-....w/ \ 4001.15Smrg { print "user " $1 " " $2 " file is group writeable" } 4011.15Smrg $3 ~ /^-.......w/ \ 4021.27Slukem { print "user " $1 " " $2 " file is other writeable" }' \ 4031.27Slukem > $OUTPUT 4041.15Smrg 4051.15Smrg # Files that should not be owned by someone else or writeable. 4061.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 4071.19Smycroft .cshrc .emacs .exrc .forward .history .klogin .login .logout \ 4081.27Slukem .profile .qmail .rc_history .rhosts .tcshrc .twmrc .xinitrc \ 4091.27Slukem .xsession" 4101.15Smrg while read uid homedir; do 4111.15Smrg for f in $list ; do 4121.15Smrg file=${homedir}/${f} 4131.15Smrg if [ -f $file ] ; then 4141.46Schristos printf -- "$uid $f `ls -ldgT $file`\n" 4151.15Smrg fi 4161.15Smrg done 4171.29Slukem done < $MPBYPATH | 4181.15Smrg awk '$1 != $5 && $5 != "root" \ 4191.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 4201.15Smrg $3 ~ /^-....w/ \ 4211.15Smrg { print "user " $1 " " $2 " file is group writeable" } 4221.15Smrg $3 ~ /^-.......w/ \ 4231.27Slukem { print "user " $1 " " $2 " file is other writeable" }' \ 4241.27Slukem >> $OUTPUT 4251.15Smrg if [ -s $OUTPUT ] ; then 4261.15Smrg printf "\nChecking dot files.\n" 4271.15Smrg cat $OUTPUT 4281.15Smrg fi 4291.9Scgdfi 4301.9Scgd 4311.9Scgd# Mailboxes should be owned by user and unreadable. 4321.32Slukem# 4331.31Slukemif checkyesno check_varmail; then 4341.15Smrg ls -l /var/mail | sed 1d | \ 4351.15Smrg awk '$3 != $9 \ 4361.15Smrg { print "user " $9 " mailbox is owned by " $3 } 4371.15Smrg $1 != "-rw-------" \ 4381.15Smrg { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT 4391.15Smrg if [ -s $OUTPUT ] ; then 4401.15Smrg printf "\nChecking mailbox ownership.\n" 4411.15Smrg cat $OUTPUT 4421.15Smrg fi 4431.15Smrgfi 4441.15Smrg 4451.32Slukem# NFS exports shouldn't be globally exported 4461.32Slukem# 4471.32Slukemif checkyesno check_nfs && [ -f /etc/exports ]; then 4481.32Slukem awk '{ 4491.22Slukem # ignore comments and blank lines 4501.39Shubertf if ($0 ~ /^\#/ || $0 ~ /^$/ ) 4511.22Slukem next; 4521.22Slukem 4531.15Smrg readonly = 0; 4541.15Smrg for (i = 2; i <= NF; ++i) { 4551.15Smrg if ($i ~ /-ro/) 4561.15Smrg readonly = 1; 4571.15Smrg else if ($i !~ /^-/) 4581.15Smrg next; 4591.15Smrg } 4601.15Smrg if (readonly) 4611.15Smrg print "File system " $1 " globally exported, read-only." 4621.15Smrg else 4631.15Smrg print "File system " $1 " globally exported, read-write." 4641.32Slukem }' < /etc/exports > $OUTPUT 4651.32Slukem if [ -s $OUTPUT ] ; then 4661.15Smrg printf "\nChecking for globally exported file systems.\n" 4671.15Smrg cat $OUTPUT 4681.15Smrg fi 4691.9Scgdfi 4701.9Scgd 4711.9Scgd# Display any changes in setuid files and devices. 4721.32Slukem# 4731.31Slukemif checkyesno check_devices; then 4741.28Slukem > $ERR 4751.15Smrg (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \ 4761.15Smrg -o -fstype procfs \) -a -prune -o \ 4771.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 4781.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 4791.24Slukem -type b -o -type c \) -print0 | \ 4801.24Slukem xargs -0 ls -ldgTq | sort +9 > $LIST) 2> $OUTPUT 4811.15Smrg 4821.15Smrg # Display any errors that occurred during system file walk. 4831.15Smrg if [ -s $OUTPUT ] ; then 4841.28Slukem printf "Setuid/device find errors:\n" >> $ERR 4851.28Slukem cat $OUTPUT >> $ERR 4861.28Slukem printf "\n" >> $ERR 4871.15Smrg fi 4881.15Smrg 4891.15Smrg # Display any changes in the setuid file list. 4901.15Smrg egrep -v '^[bc]' $LIST > $TMP1 4911.15Smrg if [ -s $TMP1 ] ; then 4921.15Smrg # Check to make sure uudecode isn't setuid. 4931.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 4941.28Slukem printf "\nUudecode is setuid.\n" >> $ERR 4951.15Smrg fi 4961.15Smrg 4971.48Sabs CUR=$backup_dir/setuid.current 4981.48Sabs BACK=$backup_dir/setuid.backup 4991.9Scgd 5001.15Smrg if [ -s $CUR ] ; then 5011.15Smrg if cmp -s $CUR $TMP1 ; then 5021.15Smrg : 5031.15Smrg else 5041.15Smrg > $TMP2 5051.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 5061.15Smrg if [ -s $OUTPUT ] ; then 5071.28Slukem printf "Setuid additions:\n" >> $ERR 5081.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5091.28Slukem printf "\n" >> $ERR 5101.15Smrg fi 5111.15Smrg 5121.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 5131.15Smrg if [ -s $OUTPUT ] ; then 5141.28Slukem printf "Setuid deletions:\n" >> $ERR 5151.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5161.28Slukem printf "\n" >> $ERR 5171.15Smrg fi 5181.15Smrg 5191.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 5201.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 5211.27Slukem uniq -u > $OUTPUT 5221.15Smrg if [ -s $OUTPUT ] ; then 5231.28Slukem printf "Setuid changes:\n" >> $ERR 5241.28Slukem column -t $OUTPUT >> $ERR 5251.28Slukem printf "\n" >> $ERR 5261.15Smrg fi 5271.9Scgd 5281.15Smrg cp $CUR $BACK 5291.15Smrg cp $TMP1 $CUR 5301.9Scgd fi 5311.15Smrg else 5321.28Slukem printf "Setuid additions:\n" >> $ERR 5331.28Slukem column -t $TMP1 >> $ERR 5341.28Slukem printf "\n" >> $ERR 5351.9Scgd cp $TMP1 $CUR 5361.9Scgd fi 5371.15Smrg fi 5381.15Smrg 5391.27Slukem # Check for block and character disk devices that are readable or 5401.27Slukem # writeable or not owned by root.operator. 5411.15Smrg >$TMP1 5421.27Slukem DISKLIST="acd ccd cd ch fd hk hp mcd md ra rb rd rl rx rz \ 5431.27Slukem sd se ss tz uk up vnd wd xd xy" 5441.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 5451.15Smrg for i in $DISKLIST; do 5461.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 5471.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 5481.15Smrg done 5491.15Smrg 5501.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 5511.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 5521.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 5531.15Smrg if [ -s $OUTPUT ] ; then 5541.28Slukem printf "\nChecking disk ownership and permissions.\n" >> $ERR 5551.28Slukem cat $OUTPUT >> $ERR 5561.28Slukem printf "\n" >> $ERR 5571.9Scgd fi 5581.9Scgd 5591.15Smrg # Display any changes in the device file list. 5601.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 5611.15Smrg if [ -s $TMP1 ] ; then 5621.48Sabs CUR=$backup_dir/device.current 5631.48Sabs BACK=$backup_dir/device.backup 5641.15Smrg 5651.15Smrg if [ -s $CUR ] ; then 5661.15Smrg if cmp -s $CUR $TMP1 ; then 5671.15Smrg : 5681.15Smrg else 5691.15Smrg > $TMP2 5701.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 5711.15Smrg if [ -s $OUTPUT ] ; then 5721.28Slukem printf "Device additions:\n" >> $ERR 5731.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5741.28Slukem printf "\n" >> $ERR 5751.15Smrg fi 5761.15Smrg 5771.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 5781.15Smrg if [ -s $OUTPUT ] ; then 5791.28Slukem printf "Device deletions:\n" >> $ERR 5801.28Slukem tee -a $TMP2 < $OUTPUT >> $ERR 5811.28Slukem printf "\n" >> $ERR 5821.15Smrg fi 5831.15Smrg 5841.27Slukem # Report any block device change. Ignore 5851.27Slukem # character devices, only the name is 5861.27Slukem # significant. 5871.15Smrg cat $TMP2 $CUR $TMP1 | \ 5881.27Slukem sed -e '/^c/d' | \ 5891.27Slukem sort -k11 | \ 5901.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 5911.27Slukem uniq -u > $OUTPUT 5921.15Smrg if [ -s $OUTPUT ] ; then 5931.28Slukem printf "Block device changes:\n" >> $ERR 5941.28Slukem column -t $OUTPUT >> $ERR 5951.28Slukem printf "\n" >> $ERR 5961.15Smrg fi 5971.9Scgd 5981.15Smrg cp $CUR $BACK 5991.15Smrg cp $TMP1 $CUR 6001.9Scgd fi 6011.15Smrg else 6021.28Slukem printf "Device additions:\n" >> $ERR 6031.28Slukem column -t $TMP1 >> $ERR 6041.28Slukem printf "\n" >> $ERR 6051.28Slukem cp $TMP1 $CUR >> $ERR 6061.9Scgd fi 6071.28Slukem fi 6081.28Slukem if [ -s $ERR ] ; then 6091.28Slukem printf "\nChecking setuid files and devices:\n" 6101.28Slukem cat $ERR 6111.28Slukem printf "\n" 6121.9Scgd fi 6131.9Scgdfi 6141.9Scgd 6151.9Scgd# Check special files. 6161.9Scgd# Check system binaries. 6171.9Scgd# 6181.9Scgd# Create the mtree tree specifications using: 6191.9Scgd# 6201.9Scgd# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure 6211.38Skleink# chown root:wheel DIR.secure 6221.16Smikel# chmod 600 DIR.secure 6231.9Scgd# 6241.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 6251.9Scgd# the hacker can modify the tree specification to match the replaced binary. 6261.9Scgd# For details on really protecting yourself against modified binaries, see 6271.9Scgd# the mtree(8) manual page. 6281.32Slukem# 6291.31Slukemif checkyesno check_mtree; then 6301.9Scgd mtree -e -p / -f /etc/mtree/special > $OUTPUT 6311.15Smrg if [ -s $OUTPUT ]; then 6321.9Scgd printf "\nChecking special files and directories.\n" 6331.9Scgd cat $OUTPUT 6341.9Scgd fi 6351.9Scgd 6361.9Scgd > $OUTPUT 6371.16Smikel for file in /etc/mtree/*.secure; do 6381.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 6391.9Scgd tree=`sed -n -e '3s/.* //p' -e 3q $file` 6401.9Scgd mtree -f $file -p $tree > $TMP1 6411.9Scgd if [ -s $TMP1 ]; then 6421.9Scgd printf "\nChecking $tree:\n" >> $OUTPUT 6431.9Scgd cat $TMP1 >> $OUTPUT 6441.9Scgd fi 6451.9Scgd done 6461.15Smrg if [ -s $OUTPUT ]; then 6471.9Scgd printf "\nChecking system binaries:\n" 6481.9Scgd cat $OUTPUT 6491.9Scgd fi 6501.9Scgdfi 6511.9Scgd 6521.32SlukemCHANGELIST="" 6531.32Slukem 6541.32Slukem# Backup disklabels of available disks 6551.32Slukem# 6561.32Slukemif checkyesno check_disklabels; then 6571.32Slukem # generate list of old disklabels and remove them 6581.48Sabs ls -1d $backup_dir/disklabel.* 2>/dev/null | 6591.32Slukem egrep -v '\.(backup|current)$' > $LABELS 6601.32Slukem xargs rm < $LABELS 6611.32Slukem 6621.40Sperry disks=`iostat -x | sed 1d | awk '$1 !~ /^[cfm]d/ { print $1; }'` 6631.32Slukem for i in $disks; do 6641.48Sabs dlf="$backup_dir/disklabel.$i" 6651.32Slukem disklabel $i > $dlf 2>/dev/null 6661.32Slukem done 6671.32Slukem 6681.32Slukem # append list of new disklabels, sort list 6691.48Sabs ls -1d $backup_dir/disklabel.* 2>/dev/null | 6701.32Slukem egrep -v '\.(backup|current)$' >> $LABELS 6711.32Slukem sort -u -o $LABELS $LABELS 6721.32Slukem CHANGELIST=$LABELS 6731.32Slukemfi 6741.32Slukem 6751.9Scgd# List of files that get backed up and checked for any modifications. Each 6761.48Sabs# file is expected to have two backups, $backup_dir/file.{current,backup}. 6771.9Scgd# Any changes cause the files to rotate. 6781.32Slukem# 6791.31Slukemif checkyesno check_changelist && [ -s /etc/changelist ] ; then 6801.32Slukem CHANGELIST="/etc/changelist $CHANGELIST" 6811.32Slukemfi 6821.32Slukem 6831.32Slukemif [ -n "$CHANGELIST" ]; then 6841.32Slukem for file in `egrep -hv "^#|$MP" $CHANGELIST`; do 6851.48Sabs CUR=$backup_dir/${file##*/}.current 6861.48Sabs BACK=$backup_dir/${file##*/}.backup 6871.30Smycroft if [ -f $file ]; then 6881.30Smycroft if [ -f $CUR ] ; then 6891.9Scgd diff $CUR $file > $OUTPUT 6901.9Scgd if [ -s $OUTPUT ] ; then 6911.9Scgd printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file 6921.9Scgd cat $OUTPUT 6931.30Smycroft mv -f $CUR $BACK 6941.9Scgd cp -p $file $CUR 6951.38Skleink chown root:wheel $CUR 6961.9Scgd fi 6971.9Scgd else 6981.30Smycroft printf "\n======\n%s added\n======\n" $file 6991.30Smycroft diff /dev/null $file 7001.9Scgd cp -p $file $CUR 7011.38Skleink chown root:wheel $CUR 7021.30Smycroft fi 7031.30Smycroft else 7041.30Smycroft if [ -f $CUR ]; then 7051.30Smycroft printf "\n======\n%s removed\n======\n" $file 7061.30Smycroft diff $CUR /dev/null 7071.30Smycroft mv -f $CUR $BACK 7081.9Scgd fi 7091.9Scgd fi 7101.9Scgd done 7111.42Sfairfi 7121.42Sfair 7131.42Sfair# run skeyaudit to inform users of ready to expire S/Keys 7141.42Sfair# 7151.42Sfairif checkyesno run_skeyaudit; then 7161.42Sfair skeyaudit 7171.44Sadfi 7181.44Sad 7191.44Sadif [ -f /etc/security.local ]; then 7201.44Sad echo "" 7211.44Sad echo "Running /etc/security.local:" 7221.44Sad . /etc/security.local 7231.9Scgdfi 724