security revision 1.27
11.1Scgd#!/bin/sh - 21.1Scgd# 31.27Slukem# $NetBSD: security,v 1.27 1997/08/22 09:40:17 lukem 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.9Scgdumask 077 101.1Scgd 111.15Smrgif [ -s /etc/security.conf ]; then 121.15Smrg . /etc/security.conf 131.15Smrgfi 141.15Smrg 151.15SmrgSECUREDIR=/tmp/_securedir.$$ 161.15Smrgif ! mkdir $SECUREDIR; then 171.15Smrg echo can not create $SECUREDIR. 181.15Smrg exit 1 191.15Smrgfi 201.15Smrg 211.15Smrgif ! cd $SECUREDIR; then 221.15Smrg echo can not chdir to $SECUREDIR. 231.15Smrg exit 1 241.15Smrgfi 251.15Smrg 261.15SmrgERR=secure1.$$ 271.15SmrgTMP1=secure2.$$ 281.15SmrgTMP2=secure3.$$ 291.27SlukemMPUID=secure4.$$ 301.27SlukemMPPATH=secure5.$$ 311.27SlukemLIST=secure6.$$ 321.27SlukemOUTPUT=secure7.$$ 331.15Smrg 341.27Slukemtrap '/bin/rm -rf $SECUREDIR ; exit 0' 0 2 3 351.15Smrg 361.15SmrgMP=/etc/master.passwd 371.9Scgd 381.27Slukem# these is used several times. 391.27Slukemawk -F: '{ print $1 " " $3 }' $MP | sort -k2n > $MPUID 401.27Slukemawk -F: '{ print $1 " " $9 }' $MP | sort -k2 > $MPPATH 411.9Scgd 421.9Scgd# Check the master password file syntax. 431.17Smycroftif [ "$check_passwd" = YES ]; then 441.25Slukem awk ' 451.25Slukem BEGIN { 461.25Slukem while ( getline < "/etc/shells" > 0 ) { 471.25Slukem if ($LINE ~ /^\#/ || $LINE ~ /^$/ ) 481.25Slukem continue; 491.25Slukem shells[$1]++; 501.25Slukem } 511.25Slukem FS=":"; 521.25Slukem } 531.25Slukem 541.25Slukem { 551.15Smrg if ($0 ~ /^[ ]*$/) { 561.25Slukem printf "Line %d is a blank line.\n", NR; 571.15Smrg next; 581.15Smrg } 591.15Smrg if (NF != 10) 601.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 611.15Smrg if ($1 !~ /^[A-Za-z0-9]*$/) 621.25Slukem printf "Login %s has non-alphanumeric characters.\n", 631.25Slukem $1; 641.15Smrg if (length($1) > 8) 651.25Slukem printf "Login %s has more than 8 characters.\n", $1; 661.15Smrg if ($2 == "") 671.25Slukem printf "Login %s has no password.\n", $1; 681.25Slukem if (length($2) != 13 && $2 != "") { 691.25Slukem if ($10 == "" || shells[$10]) 701.27Slukem printf "Login %s is off but still has a valid shell (%s)\n", 711.25Slukem $1, $10; 721.25Slukem } else if (! shells[$10]) 731.25Slukem printf "Login %s does not have a valid shell (%s)\n", 741.25Slukem $1, $10; 751.15Smrg if ($3 == 0 && $1 != "root" && $1 != "toor") 761.25Slukem printf "Login %s has a user id of 0.\n", $1; 771.15Smrg if ($3 < 0) 781.25Slukem printf "Login %s has a negative user id.\n", $1; 791.15Smrg if ($4 < 0) 801.25Slukem printf "Login %s has a negative group id.\n", $1; 811.15Smrg }' < $MP > $OUTPUT 821.15Smrg if [ -s $OUTPUT ] ; then 831.15Smrg printf "\nChecking the $MP file:\n" 841.15Smrg cat $OUTPUT 851.15Smrg fi 861.15Smrg 871.15Smrg awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT 881.15Smrg if [ -s $OUTPUT ] ; then 891.15Smrg printf "\n$MP has duplicate user names.\n" 901.15Smrg column $OUTPUT 911.15Smrg fi 921.15Smrg 931.27Slukem < $MPUID uniq -d -f 1 | awk '{ print $2 }' > $TMP2 941.15Smrg if [ -s $TMP2 ] ; then 951.15Smrg printf "\n$MP has duplicate user id's.\n" 961.15Smrg while read uid; do 971.27Slukem grep -w $uid $MPUID 981.15Smrg done < $TMP2 | column 991.15Smrg fi 1001.9Scgdfi 1011.9Scgd 1021.9Scgd# Backup the master password file; a special case, the normal backup 1031.9Scgd# mechanisms also print out file differences and we don't want to do 1041.9Scgd# that because this file has encrypted passwords in it. 1051.9ScgdCUR=/var/backups/`basename $MP`.current 1061.9ScgdBACK=/var/backups/`basename $MP`.backup 1071.9Scgdif [ -s $CUR ] ; then 1081.9Scgd if cmp -s $CUR $MP; then 1091.9Scgd : 1101.9Scgd else 1111.9Scgd cp -p $CUR $BACK 1121.9Scgd cp -p $MP $CUR 1131.9Scgd chown root.wheel $CUR 1141.9Scgd fi 1151.9Scgdelse 1161.9Scgd cp -p $MP $CUR 1171.9Scgd chown root.wheel $CUR 1181.9Scgdfi 1191.9Scgd 1201.9Scgd# Check the group file syntax. 1211.17Smycroftif [ "$check_group" = YES ]; then 1221.15Smrg GRP=/etc/group 1231.15Smrg awk -F: '{ 1241.15Smrg if ($0 ~ /^[ ]*$/) { 1251.25Slukem printf "Line %d is a blank line.\n", NR; 1261.15Smrg next; 1271.15Smrg } 1281.15Smrg if (NF != 4) 1291.25Slukem printf "Line %d has the wrong number of fields.\n", NR; 1301.15Smrg if ($1 !~ /^[A-za-z0-9]*$/) 1311.25Slukem printf "Group %s has non-alphanumeric characters.\n", 1321.25Slukem $1; 1331.15Smrg if (length($1) > 8) 1341.25Slukem printf "Group %s has more than 8 characters.\n", $1; 1351.15Smrg if ($3 !~ /[0-9]*/) 1361.25Slukem printf "Login %s has a negative group id.\n", $1; 1371.15Smrg }' < $GRP > $OUTPUT 1381.15Smrg if [ -s $OUTPUT ] ; then 1391.15Smrg printf "\nChecking the $GRP file:\n" 1401.15Smrg cat $OUTPUT 1411.15Smrg fi 1421.15Smrg 1431.15Smrg awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT 1441.15Smrg if [ -s $OUTPUT ] ; then 1451.15Smrg printf "\n$GRP has duplicate group names.\n" 1461.15Smrg column $OUTPUT 1471.15Smrg fi 1481.9Scgdfi 1491.9Scgd 1501.9Scgd# Check for root paths, umask values in startup files. 1511.9Scgd# The check for the root paths is problematical -- it's likely to fail 1521.9Scgd# in other environments. Once the shells have been modified to warn 1531.9Scgd# of '.' in the path, the path tests should go away. 1541.17Smycroftif [ "$check_rootdotfiles" = YES ]; then 1551.15Smrg cp /dev/null $OUTPUT 1561.15Smrg rhome=`csh -fc "echo ~root"` 1571.15Smrg umaskset=no 1581.15Smrg list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login" 1591.15Smrg for i in $list ; do 1601.15Smrg if [ -f $i ] ; then 1611.15Smrg if egrep umask $i > /dev/null ; then 1621.15Smrg umaskset=yes 1631.15Smrg fi 1641.15Smrg egrep umask $i | 1651.15Smrg awk '$2 % 100 < 20 \ 1661.27Slukem { print "\tRoot umask is group writeable" } 1671.15Smrg $2 % 10 < 2 \ 1681.27Slukem { print "\tRoot umask is other writeable" }' \ 1691.27Slukem >> $OUTPUT 1701.26Slukem SAVE_PATH=$PATH 1711.26Slukem unset PATH 1721.15Smrg /bin/csh -f -s << end-of-csh > /dev/null 2>&1 1731.15Smrg source $i 1741.15Smrg /bin/ls -ldgT \$path > $TMP1 1751.9Scgdend-of-csh 1761.26Slukem PATH=$SAVE_PATH 1771.15Smrg awk '{ 1781.15Smrg if ($10 ~ /^\.$/) { 1791.27Slukem print "\tThe root path includes ."; 1801.15Smrg next; 1811.15Smrg } 1821.15Smrg } 1831.15Smrg $1 ~ /^d....w/ \ 1841.27Slukem { print "\tRoot path directory " $10 " is group writeable." } \ 1851.15Smrg $1 ~ /^d.......w/ \ 1861.27Slukem { print "\tRoot path directory " $10 " is other writeable." }' \ 1871.15Smrg < $TMP1 >> $OUTPUT 1881.15Smrg fi 1891.15Smrg done 1901.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 1911.27Slukem printf "\nChecking root csh paths, umask values:\n$list\n\n" 1921.15Smrg if [ -s $OUTPUT ]; then 1931.15Smrg cat $OUTPUT 1941.15Smrg fi 1951.15Smrg if [ $umaskset = "no" ] ; then 1961.27Slukem printf "\tRoot csh startup files do not set the umask.\n" 1971.15Smrg fi 1981.9Scgd fi 1991.9Scgd 2001.15Smrg cp /dev/null $OUTPUT 2011.15Smrg rhome=/root 2021.15Smrg umaskset=no 2031.23Slukem list="/etc/profile ${rhome}/.profile" 2041.15Smrg for i in $list; do 2051.15Smrg if [ -f $i ] ; then 2061.15Smrg if egrep umask $i > /dev/null ; then 2071.15Smrg umaskset=yes 2081.15Smrg fi 2091.15Smrg egrep umask $i | 2101.15Smrg awk '$2 % 100 < 20 \ 2111.27Slukem { print "\tRoot umask is group writeable" } \ 2121.15Smrg $2 % 10 < 2 \ 2131.27Slukem { print "\tRoot umask is other writeable" }' \ 2141.27Slukem >> $OUTPUT 2151.26Slukem SAVE_PATH=$PATH 2161.26Slukem unset PATH 2171.15Smrg /bin/sh << end-of-sh > /dev/null 2>&1 2181.15Smrg . $i 2191.26Slukem list=\`echo \$PATH | /usr/bin/sed -e \ 2201.26Slukem 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\` 2211.15Smrg /bin/ls -ldgT \$list > $TMP1 2221.9Scgdend-of-sh 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.9Scgd 2361.15Smrg fi 2371.15Smrg done 2381.15Smrg if [ $umaskset = "no" -o -s $OUTPUT ] ; then 2391.15Smrg printf "\nChecking root sh paths, umask values:\n$list\n" 2401.15Smrg if [ -s $OUTPUT ]; then 2411.15Smrg cat $OUTPUT 2421.15Smrg fi 2431.15Smrg if [ $umaskset = "no" ] ; then 2441.27Slukem printf "\tRoot sh startup files do not set the umask.\n" 2451.15Smrg fi 2461.9Scgd fi 2471.9Scgdfi 2481.9Scgd 2491.9Scgd# Root and uucp should both be in /etc/ftpusers. 2501.27Slukem# XXX This should be updated to support the new format... 2511.17Smycroftif [ "$check_ftpusers" = YES ]; then 2521.27Slukem list="root uucp" 2531.27Slukem for i in $list; do 2541.27Slukem if ! egrep "^$i$" /etc/ftpusers > /dev/null ; then 2551.27Slukem printf "\n$i is not listed in /etc/ftpusers file.\n" 2561.27Slukem fi 2571.27Slukem done 2581.9Scgdfi 2591.9Scgd 2601.9Scgd# Uudecode should not be in the /etc/aliases file. 2611.17Smycroftif [ "$check_aliases" = YES ]; then 2621.18Smikel if egrep '^[^#]*(uudecode|decode).*\|' /etc/aliases; then 2631.18Smikel printf "\nEntry for uudecode in /etc/aliases file.\n" 2641.15Smrg fi 2651.9Scgdfi 2661.9Scgd 2671.9Scgd# Files that should not have + signs. 2681.17Smycroftif [ "$check_rhosts" = YES ]; then 2691.15Smrg list="/etc/hosts.equiv /etc/hosts.lpd" 2701.15Smrg for f in $list ; do 2711.15Smrg if [ -f $f ] && egrep '\+' $f > /dev/null ; then 2721.15Smrg printf "\nPlus sign in $f file.\n" 2731.15Smrg fi 2741.15Smrg done 2751.15Smrg 2761.15Smrg # Check for special users with .rhosts files. Only root and toor should 2771.16Smikel # have .rhosts files. Also, .rhosts files should not have plus signs. 2781.15Smrg awk -F: '$1 != "root" && $1 != "toor" && \ 2791.15Smrg ($3 < 100 || $1 == "ftp" || $1 == "uucp") \ 2801.20Smycroft { print $1 " " $9 }' $MP | 2811.19Smycroft sort -k2 | 2821.15Smrg while read uid homedir; do 2831.15Smrg if [ -f ${homedir}/.rhosts ] ; then 2841.15Smrg rhost=`ls -ldgT ${homedir}/.rhosts` 2851.15Smrg printf "$uid: $rhost\n" 2861.15Smrg fi 2871.15Smrg done > $OUTPUT 2881.15Smrg if [ -s $OUTPUT ] ; then 2891.15Smrg printf "\nChecking for special users with .rhosts files.\n" 2901.15Smrg cat $OUTPUT 2911.15Smrg fi 2921.15Smrg 2931.15Smrg while read uid homedir; do 2941.15Smrg if [ -f ${homedir}/.rhosts ] && \ 2951.15Smrg egrep '\+' ${homedir}/.rhosts > /dev/null ; then 2961.15Smrg printf "$uid: + in .rhosts file.\n" 2971.15Smrg fi 2981.27Slukem done < $MPPATH > $OUTPUT 2991.15Smrg if [ -s $OUTPUT ] ; then 3001.15Smrg printf "\nChecking .rhosts files syntax.\n" 3011.15Smrg cat $OUTPUT 3021.15Smrg fi 3031.9Scgdfi 3041.9Scgd 3051.9Scgd# Check home directories. Directories should not be owned by someone else 3061.9Scgd# or writeable. 3071.17Smycroftif [ "$check_homes" = YES ]; then 3081.15Smrg while read uid homedir; do 3091.15Smrg if [ -d ${homedir}/ ] ; then 3101.15Smrg file=`ls -ldgT ${homedir}` 3111.15Smrg printf "$uid $file\n" 3121.9Scgd fi 3131.27Slukem done < $MPPATH | 3141.15Smrg awk '$1 != $4 && $4 != "root" \ 3151.15Smrg { print "user " $1 " home directory is owned by " $4 } 3161.15Smrg $2 ~ /^-....w/ \ 3171.15Smrg { print "user " $1 " home directory is group writeable" } 3181.15Smrg $2 ~ /^-.......w/ \ 3191.27Slukem { print "user " $1 " home directory is other writeable" }' \ 3201.27Slukem > $OUTPUT 3211.15Smrg if [ -s $OUTPUT ] ; then 3221.15Smrg printf "\nChecking home directories.\n" 3231.15Smrg cat $OUTPUT 3241.15Smrg fi 3251.15Smrg 3261.15Smrg # Files that should not be owned by someone else or readable. 3271.27Slukem list=".Xauthority .netrc" 3281.15Smrg while read uid homedir; do 3291.15Smrg for f in $list ; do 3301.15Smrg file=${homedir}/${f} 3311.15Smrg if [ -f $file ] ; then 3321.15Smrg printf "$uid $f `ls -ldgT $file`\n" 3331.15Smrg fi 3341.15Smrg done 3351.27Slukem done < $MPPATH | 3361.15Smrg awk '$1 != $5 && $5 != "root" \ 3371.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 3381.15Smrg $3 ~ /^-...r/ \ 3391.15Smrg { print "user " $1 " " $2 " file is group readable" } 3401.15Smrg $3 ~ /^-......r/ \ 3411.15Smrg { print "user " $1 " " $2 " file is other readable" } 3421.15Smrg $3 ~ /^-....w/ \ 3431.15Smrg { print "user " $1 " " $2 " file is group writeable" } 3441.15Smrg $3 ~ /^-.......w/ \ 3451.27Slukem { print "user " $1 " " $2 " file is other writeable" }' \ 3461.27Slukem > $OUTPUT 3471.15Smrg 3481.15Smrg # Files that should not be owned by someone else or writeable. 3491.19Smycroft list=".bash_history .bash_login .bash_logout .bash_profile .bashrc \ 3501.19Smycroft .cshrc .emacs .exrc .forward .history .klogin .login .logout \ 3511.27Slukem .profile .qmail .rc_history .rhosts .tcshrc .twmrc .xinitrc \ 3521.27Slukem .xsession" 3531.15Smrg while read uid homedir; do 3541.15Smrg for f in $list ; do 3551.15Smrg file=${homedir}/${f} 3561.15Smrg if [ -f $file ] ; then 3571.15Smrg printf "$uid $f `ls -ldgT $file`\n" 3581.15Smrg fi 3591.15Smrg done 3601.27Slukem done < $MPPATH | 3611.15Smrg awk '$1 != $5 && $5 != "root" \ 3621.15Smrg { print "user " $1 " " $2 " file is owned by " $5 } 3631.15Smrg $3 ~ /^-....w/ \ 3641.15Smrg { print "user " $1 " " $2 " file is group writeable" } 3651.15Smrg $3 ~ /^-.......w/ \ 3661.27Slukem { print "user " $1 " " $2 " file is other writeable" }' \ 3671.27Slukem >> $OUTPUT 3681.15Smrg if [ -s $OUTPUT ] ; then 3691.15Smrg printf "\nChecking dot files.\n" 3701.15Smrg cat $OUTPUT 3711.15Smrg fi 3721.9Scgdfi 3731.9Scgd 3741.9Scgd# Mailboxes should be owned by user and unreadable. 3751.17Smycroftif [ "$check_varmail" = YES ]; then 3761.15Smrg ls -l /var/mail | sed 1d | \ 3771.15Smrg awk '$3 != $9 \ 3781.15Smrg { print "user " $9 " mailbox is owned by " $3 } 3791.15Smrg $1 != "-rw-------" \ 3801.15Smrg { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT 3811.15Smrg if [ -s $OUTPUT ] ; then 3821.15Smrg printf "\nChecking mailbox ownership.\n" 3831.15Smrg cat $OUTPUT 3841.15Smrg fi 3851.15Smrgfi 3861.15Smrg 3871.17Smycroftif [ "$check_nfs" = YES ]; then 3881.15Smrg if [ -f /etc/exports ]; then 3891.15Smrg # File systems should not be globally exported. 3901.15Smrg awk '{ 3911.22Slukem # ignore comments and blank lines 3921.22Slukem if ($LINE ~ /^\#/ || $LINE ~ /^$/ ) 3931.22Slukem next; 3941.22Slukem 3951.15Smrg readonly = 0; 3961.15Smrg for (i = 2; i <= NF; ++i) { 3971.15Smrg if ($i ~ /-ro/) 3981.15Smrg readonly = 1; 3991.15Smrg else if ($i !~ /^-/) 4001.15Smrg next; 4011.15Smrg } 4021.15Smrg if (readonly) 4031.15Smrg print "File system " $1 " globally exported, read-only." 4041.15Smrg else 4051.15Smrg print "File system " $1 " globally exported, read-write." 4061.15Smrg }' < /etc/exports > $OUTPUT 4071.15Smrg if [ -s $OUTPUT ] ; then 4081.15Smrg printf "\nChecking for globally exported file systems.\n" 4091.15Smrg cat $OUTPUT 4101.15Smrg fi 4111.15Smrg fi 4121.9Scgdfi 4131.9Scgd 4141.9Scgd# Display any changes in setuid files and devices. 4151.17Smycroftif [ "$check_devices" = YES ]; then 4161.15Smrg printf "\nChecking setuid files and devices:\n" 4171.15Smrg (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \ 4181.15Smrg -o -fstype procfs \) -a -prune -o \ 4191.21Smycroft \( \( -perm -u+s -a ! -type d \) -o \ 4201.21Smycroft \( -perm -g+s -a ! -type d \) -o \ 4211.24Slukem -type b -o -type c \) -print0 | \ 4221.24Slukem xargs -0 ls -ldgTq | sort +9 > $LIST) 2> $OUTPUT 4231.15Smrg 4241.15Smrg # Display any errors that occurred during system file walk. 4251.15Smrg if [ -s $OUTPUT ] ; then 4261.15Smrg printf "Setuid/device find errors:\n" 4271.15Smrg cat $OUTPUT 4281.15Smrg printf "\n" 4291.15Smrg fi 4301.15Smrg 4311.15Smrg # Display any changes in the setuid file list. 4321.15Smrg egrep -v '^[bc]' $LIST > $TMP1 4331.15Smrg if [ -s $TMP1 ] ; then 4341.15Smrg # Check to make sure uudecode isn't setuid. 4351.15Smrg if grep -w uudecode $TMP1 > /dev/null ; then 4361.15Smrg printf "\nUudecode is setuid.\n" 4371.15Smrg fi 4381.15Smrg 4391.15Smrg CUR=/var/backups/setuid.current 4401.15Smrg BACK=/var/backups/setuid.backup 4411.9Scgd 4421.15Smrg if [ -s $CUR ] ; then 4431.15Smrg if cmp -s $CUR $TMP1 ; then 4441.15Smrg : 4451.15Smrg else 4461.15Smrg > $TMP2 4471.15Smrg join -110 -210 -v2 $CUR $TMP1 > $OUTPUT 4481.15Smrg if [ -s $OUTPUT ] ; then 4491.15Smrg printf "Setuid additions:\n" 4501.15Smrg tee -a $TMP2 < $OUTPUT 4511.15Smrg printf "\n" 4521.15Smrg fi 4531.15Smrg 4541.15Smrg join -110 -210 -v1 $CUR $TMP1 > $OUTPUT 4551.15Smrg if [ -s $OUTPUT ] ; then 4561.15Smrg printf "Setuid deletions:\n" 4571.15Smrg tee -a $TMP2 < $OUTPUT 4581.15Smrg printf "\n" 4591.15Smrg fi 4601.15Smrg 4611.20Smycroft sort -k10 $TMP2 $CUR $TMP1 | \ 4621.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 4631.27Slukem uniq -u > $OUTPUT 4641.15Smrg if [ -s $OUTPUT ] ; then 4651.15Smrg printf "Setuid changes:\n" 4661.15Smrg column -t $OUTPUT 4671.15Smrg printf "\n" 4681.15Smrg fi 4691.9Scgd 4701.15Smrg cp $CUR $BACK 4711.15Smrg cp $TMP1 $CUR 4721.9Scgd fi 4731.15Smrg else 4741.15Smrg printf "Setuid additions:\n" 4751.15Smrg column -t $TMP1 4761.15Smrg printf "\n" 4771.9Scgd cp $TMP1 $CUR 4781.9Scgd fi 4791.15Smrg fi 4801.15Smrg 4811.27Slukem # Check for block and character disk devices that are readable or 4821.27Slukem # writeable or not owned by root.operator. 4831.15Smrg >$TMP1 4841.27Slukem DISKLIST="acd ccd cd ch fd hk hp mcd md ra rb rd rl rx rz \ 4851.27Slukem sd se ss tz uk up vnd wd xd xy" 4861.27Slukem# DISKLIST="$DISKLIST ct mt st wt" 4871.15Smrg for i in $DISKLIST; do 4881.15Smrg egrep "^b.*/${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 4891.15Smrg egrep "^c.*/r${i}[0-9][0-9]*[a-p]$" $LIST >> $TMP1 4901.15Smrg done 4911.15Smrg 4921.15Smrg awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \ 4931.25Slukem { printf "Disk %s is user %s, group %s, permissions %s.\n", \ 4941.25Slukem $11, $3, $4, $1; }' < $TMP1 > $OUTPUT 4951.15Smrg if [ -s $OUTPUT ] ; then 4961.15Smrg printf "\nChecking disk ownership and permissions.\n" 4971.15Smrg cat $OUTPUT 4981.9Scgd printf "\n" 4991.9Scgd fi 5001.9Scgd 5011.15Smrg # Display any changes in the device file list. 5021.20Smycroft egrep '^[bc]' $LIST | sort -k11 > $TMP1 5031.15Smrg if [ -s $TMP1 ] ; then 5041.15Smrg CUR=/var/backups/device.current 5051.15Smrg BACK=/var/backups/device.backup 5061.15Smrg 5071.15Smrg if [ -s $CUR ] ; then 5081.15Smrg if cmp -s $CUR $TMP1 ; then 5091.15Smrg : 5101.15Smrg else 5111.15Smrg > $TMP2 5121.15Smrg join -111 -211 -v2 $CUR $TMP1 > $OUTPUT 5131.15Smrg if [ -s $OUTPUT ] ; then 5141.15Smrg printf "Device additions:\n" 5151.15Smrg tee -a $TMP2 < $OUTPUT 5161.15Smrg printf "\n" 5171.15Smrg fi 5181.15Smrg 5191.15Smrg join -111 -211 -v1 $CUR $TMP1 > $OUTPUT 5201.15Smrg if [ -s $OUTPUT ] ; then 5211.15Smrg printf "Device deletions:\n" 5221.15Smrg tee -a $TMP2 < $OUTPUT 5231.15Smrg printf "\n" 5241.15Smrg fi 5251.15Smrg 5261.27Slukem # Report any block device change. Ignore 5271.27Slukem # character devices, only the name is 5281.27Slukem # significant. 5291.15Smrg cat $TMP2 $CUR $TMP1 | \ 5301.27Slukem sed -e '/^c/d' | \ 5311.27Slukem sort -k11 | \ 5321.27Slukem sed -e 's/[ ][ ]*/ /g' | \ 5331.27Slukem uniq -u > $OUTPUT 5341.15Smrg if [ -s $OUTPUT ] ; then 5351.15Smrg printf "Block device changes:\n" 5361.15Smrg column -t $OUTPUT 5371.15Smrg printf "\n" 5381.15Smrg fi 5391.9Scgd 5401.15Smrg cp $CUR $BACK 5411.15Smrg cp $TMP1 $CUR 5421.9Scgd fi 5431.15Smrg else 5441.15Smrg printf "Device additions:\n" 5451.15Smrg column -t $TMP1 5461.15Smrg printf "\n" 5471.9Scgd cp $TMP1 $CUR 5481.9Scgd fi 5491.9Scgd fi 5501.9Scgdfi 5511.9Scgd 5521.9Scgd# Check special files. 5531.9Scgd# Check system binaries. 5541.9Scgd# 5551.9Scgd# Create the mtree tree specifications using: 5561.9Scgd# 5571.9Scgd# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure 5581.16Smikel# chown root.wheel DIR.secure 5591.16Smikel# chmod 600 DIR.secure 5601.9Scgd# 5611.9Scgd# Note, this is not complete protection against Trojan horsed binaries, as 5621.9Scgd# the hacker can modify the tree specification to match the replaced binary. 5631.9Scgd# For details on really protecting yourself against modified binaries, see 5641.9Scgd# the mtree(8) manual page. 5651.17Smycroftif [ "$check_mtree" = YES ]; then 5661.9Scgd mtree -e -p / -f /etc/mtree/special > $OUTPUT 5671.15Smrg if [ -s $OUTPUT ]; then 5681.9Scgd printf "\nChecking special files and directories.\n" 5691.9Scgd cat $OUTPUT 5701.9Scgd fi 5711.9Scgd 5721.9Scgd > $OUTPUT 5731.16Smikel for file in /etc/mtree/*.secure; do 5741.16Smikel [ $file = '/etc/mtree/*.secure' ] && continue 5751.9Scgd tree=`sed -n -e '3s/.* //p' -e 3q $file` 5761.9Scgd mtree -f $file -p $tree > $TMP1 5771.9Scgd if [ -s $TMP1 ]; then 5781.9Scgd printf "\nChecking $tree:\n" >> $OUTPUT 5791.9Scgd cat $TMP1 >> $OUTPUT 5801.9Scgd fi 5811.9Scgd done 5821.15Smrg if [ -s $OUTPUT ]; then 5831.9Scgd printf "\nChecking system binaries:\n" 5841.9Scgd cat $OUTPUT 5851.9Scgd fi 5861.9Scgdfi 5871.9Scgd 5881.9Scgd# List of files that get backed up and checked for any modifications. Each 5891.9Scgd# file is expected to have two backups, /var/backups/file.{current,backup}. 5901.9Scgd# Any changes cause the files to rotate. 5911.17Smycroftif [ "$check_changelist" = YES ] && [ -s /etc/changelist ] ; then 5921.27Slukem for file in `egrep -v "^#|$MP" /etc/changelist`; do 5931.9Scgd CUR=/var/backups/`basename $file`.current 5941.9Scgd BACK=/var/backups/`basename $file`.backup 5951.9Scgd if [ -s $file ]; then 5961.9Scgd if [ -s $CUR ] ; then 5971.9Scgd diff $CUR $file > $OUTPUT 5981.9Scgd if [ -s $OUTPUT ] ; then 5991.9Scgd printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file 6001.9Scgd cat $OUTPUT 6011.9Scgd cp -p $CUR $BACK 6021.9Scgd cp -p $file $CUR 6031.9Scgd chown root.wheel $CUR $BACK 6041.9Scgd fi 6051.9Scgd else 6061.9Scgd cp -p $file $CUR 6071.9Scgd chown root.wheel $CUR 6081.9Scgd fi 6091.9Scgd fi 6101.9Scgd done 6111.9Scgdfi 612