[BACK]Return to security CVS log [TXT][DIR] Up to [local] / src / etc

Annotation of src/etc/security, Revision 1.43

1.1       deraadt     1: #!/bin/sh -
                      2: #
1.43    ! todd        3: #      $OpenBSD: security,v 1.42 2000/12/17 22:35:19 marc Exp $
1.13      millert     4: #      from: @(#)security      8.1 (Berkeley) 6/9/93
1.1       deraadt     5: #
1.13      millert     6:
1.1       deraadt     7: PATH=/sbin:/usr/sbin:/bin:/usr/bin
                      8:
                      9: umask 077
                     10:
1.7       deraadt    11: DIR=/tmp/_secure$$
                     12: ERR=$DIR/_secure1
                     13: TMP1=$DIR/_secure2
                     14: TMP2=$DIR/_secure3
                     15: TMP3=$DIR/_secure4
                     16: LIST=$DIR/_secure5
                     17: OUTPUT=$DIR/_secure6
1.1       deraadt    18:
1.7       deraadt    19: if ! mkdir $DIR ; then
1.41      millert    20:        echo "tmp directory ${DIR} already exists, looks like:"
1.39      aaron      21:        ls -alqF $DIR
1.7       deraadt    22:        exit 1
                     23: fi
1.8       deraadt    24:
1.25      deraadt    25: trap 'rm -rf $DIR; exit 1' 0 1 2 3 13 15
1.1       deraadt    26:
                     27: # Check the master password file syntax.
                     28: MP=/etc/master.passwd
                     29: awk -F: '{
                     30:        if ($0 ~ /^[     ]*$/) {
                     31:                printf("Line %d is a blank line.\n", NR);
                     32:                next;
                     33:        }
                     34:        if (NF != 10)
1.32      espie      35:                printf("Line %d has the wrong number of fields:\n%s\n", NR, $0);
1.15      millert    36:        if ($1 ~ /^[+-]/)
1.2       deraadt    37:                next;
                     38:        if ($1 == "")
1.32      espie      39:                printf("Line %d has an empty login field:\n%s\n", NR, $0);
1.2       deraadt    40:        else if ($1 !~ /^[A-Za-z0-9][A-Za-z0-9_-]*$/)
1.1       deraadt    41:                printf("Login %s has non-alphanumeric characters.\n", $1);
                     42:        if (length($1) > 8)
                     43:                printf("Login %s has more than 8 characters.\n", $1);
                     44:        if ($2 == "")
                     45:                printf("Login %s has no password.\n", $1);
1.23      deraadt    46:        if ($2 != "" && length($2) != 13 && ($10 ~ /.*sh$/ || $10 == "") &&
                     47:            ($2 !~ /^\$[0-9a-f]+\$/) && ($2 != "skey")) {
1.26      millert    48:                if (system("test -s /etc/skeykeys && grep -q \"^"$1" \" /etc/skeykeys") == 0)
1.23      deraadt    49:                        printf("Login %s is off but still has a valid shell and an entry in /etc/skeykeys.\n", $1);
                     50:                if (system("test -d "$9" -a ! -r "$9"") == 0)
1.40      hugh       51:                        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);
1.23      deraadt    52:                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"))
                     53:                         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);
                     54:        }
1.9       deraadt    55:        if ($3 == 0 && $1 != "root")
1.36      aaron      56:                printf("Login %s has a user ID of 0.\n", $1);
1.1       deraadt    57:        if ($3 < 0)
1.36      aaron      58:                printf("Login %s has a negative user ID.\n", $1);
1.1       deraadt    59:        if ($4 < 0)
1.36      aaron      60:                printf("Login %s has a negative group ID.\n", $1);
1.1       deraadt    61: }' < $MP > $OUTPUT
                     62: if [ -s $OUTPUT ] ; then
1.41      millert    63:        echo "\nChecking the ${MP} file:"
1.1       deraadt    64:        cat $OUTPUT
                     65: fi
                     66:
                     67: awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
                     68: if [ -s $OUTPUT ] ; then
1.41      millert    69:        echo "\n${MP} has duplicate user names."
1.1       deraadt    70:        column $OUTPUT
                     71: fi
                     72:
1.9       deraadt    73: awk -F: '{ print $1 " " $3 }' $MP | sort -n +1 | tee $TMP1 |
1.1       deraadt    74: uniq -d -f 1 | awk '{ print $2 }' > $TMP2
                     75: if [ -s $TMP2 ] ; then
1.41      millert    76:        echo "\n${MP} has duplicate user ID's."
1.1       deraadt    77:         while read uid; do
                     78:                 grep -w $uid $TMP1
                     79:         done < $TMP2 | column
                     80: fi
                     81:
                     82: # Backup the master password file; a special case, the normal backup
                     83: # mechanisms also print out file differences and we don't want to do
                     84: # that because this file has encrypted passwords in it.
1.2       deraadt    85: if [ ! -d /var/backups ] ; then
                     86:        mkdir /var/backups
1.31      deraadt    87:        chmod 700 /var/backups
1.2       deraadt    88: fi
1.1       deraadt    89: CUR=/var/backups/`basename $MP`.current
                     90: BACK=/var/backups/`basename $MP`.backup
                     91: if [ -s $CUR ] ; then
                     92:        if cmp -s $CUR $MP; then
                     93:                :
                     94:        else
                     95:                cp -p $CUR $BACK
                     96:                cp -p $MP $CUR
                     97:                chown root.wheel $CUR
                     98:        fi
                     99: else
                    100:        cp -p $MP $CUR
                    101:        chown root.wheel $CUR
                    102: fi
                    103:
                    104: # Check the group file syntax.
                    105: GRP=/etc/group
                    106: awk -F: '{
                    107:        if ($0 ~ /^[     ]*$/) {
                    108:                printf("Line %d is a blank line.\n", NR);
                    109:                next;
                    110:        }
1.2       deraadt   111:        if ($1 ~ /^[+-].*$/)
                    112:                next;
1.1       deraadt   113:        if (NF != 4)
1.32      espie     114:                printf("Line %d has the wrong number of fields:\n%s\n", NR, $0);
1.13      millert   115:        if ($1 !~ /^[A-za-z0-9][A-za-z0-9_-]*$/)
1.1       deraadt   116:                printf("Group %s has non-alphanumeric characters.\n", $1);
                    117:        if (length($1) > 8)
                    118:                printf("Group %s has more than 8 characters.\n", $1);
                    119:        if ($3 !~ /[0-9]*/)
1.36      aaron     120:                printf("Login %s has a negative group ID.\n", $1);
1.1       deraadt   121: }' < $GRP > $OUTPUT
                    122: if [ -s $OUTPUT ] ; then
1.41      millert   123:        echo "\nChecking the ${GRP} file:"
1.1       deraadt   124:        cat $OUTPUT
                    125: fi
                    126:
                    127: awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
                    128: if [ -s $OUTPUT ] ; then
1.41      millert   129:        echo "\n${GRP} has duplicate group names."
1.1       deraadt   130:        column $OUTPUT
                    131: fi
                    132:
                    133: # Check for root paths, umask values in startup files.
                    134: # The check for the root paths is problematical -- it's likely to fail
                    135: # in other environments.  Once the shells have been modified to warn
                    136: # of '.' in the path, the path tests should go away.
                    137: > $OUTPUT
                    138: rhome=/root
                    139: umaskset=no
                    140: list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
                    141: for i in $list ; do
1.15      millert   142:        if [ -s $i ] ; then
1.1       deraadt   143:                if egrep umask $i > /dev/null ; then
                    144:                        umaskset=yes
                    145:                fi
                    146:                egrep umask $i |
                    147:                awk '$2 % 100 < 20 \
                    148:                        { print "Root umask is group writeable" }
                    149:                     $2 % 10 < 2 \
                    150:                        { print "Root umask is other writeable" }' >> $OUTPUT
1.21      deraadt   151:                SAVE_PATH=$PATH
                    152:                unset PATH
1.1       deraadt   153:                /bin/csh -f -s << end-of-csh > /dev/null 2>&1
                    154:                        source $i
1.29      marc      155:                        if (\$?path) then
                    156:                                /bin/ls -ldgT \$path > $TMP1
                    157:                        else
                    158:                                cat /dev/null > $TMP1
                    159:                        endif
1.1       deraadt   160: end-of-csh
1.21      deraadt   161:                PATH=$SAVE_PATH
1.1       deraadt   162:                awk '{
                    163:                        if ($10 ~ /^\.$/) {
                    164:                                print "The root path includes .";
                    165:                                next;
                    166:                        }
                    167:                     }
                    168:                     $1 ~ /^d....w/ \
                    169:         { print "Root path directory " $10 " is group writeable." } \
                    170:                     $1 ~ /^d.......w/ \
                    171:         { print "Root path directory " $10 " is other writeable." }' \
                    172:                < $TMP1 >> $OUTPUT
                    173:        fi
                    174: done
                    175: if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1.41      millert   176:        echo "\nChecking root csh paths, umask values:\n${list}"
1.13      millert   177:        if [ -s $OUTPUT ] ; then
1.1       deraadt   178:                cat $OUTPUT
                    179:        fi
                    180:        if [ $umaskset = "no" ] ; then
1.41      millert   181:                echo "\nRoot csh startup files do not set the umask."
1.1       deraadt   182:        fi
                    183: fi
                    184:
                    185: > $OUTPUT
1.29      marc      186: > $TMP2
1.1       deraadt   187: rhome=/root
                    188: umaskset=no
1.20      millert   189: list="/etc/profile ${rhome}/.profile"
1.1       deraadt   190: for i in $list; do
1.15      millert   191:        if [ -s $i ] ; then
1.1       deraadt   192:                if egrep umask $i > /dev/null ; then
                    193:                        umaskset=yes
                    194:                fi
                    195:                egrep umask $i |
                    196:                awk '$2 % 100 < 20 \
                    197:                        { print "Root umask is group writeable" } \
                    198:                     $2 % 10 < 2 \
                    199:                        { print "Root umask is other writeable" }' >> $OUTPUT
1.21      deraadt   200:                SAVE_PATH=$PATH
1.29      marc      201:                SAVE_ENV=$ENV
                    202:                unset PATH ENV
1.1       deraadt   203:                /bin/sh << end-of-sh > /dev/null 2>&1
                    204:                        . $i
1.29      marc      205:                        if [ X"\$PATH" != "X" ]; then
                    206:                                list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
                    207:                                /bin/ls -ldgT \$list > $TMP1
                    208:                        else
                    209:                                > $TMP1
                    210:                        fi
                    211:                        echo \$ENV >> $TMP2
1.1       deraadt   212: end-of-sh
1.21      deraadt   213:                PATH=$SAVE_PATH
1.29      marc      214:                ENV=$SAVE_ENV
1.1       deraadt   215:                awk '{
                    216:                        if ($10 ~ /^\.$/) {
                    217:                                print "The root path includes .";
                    218:                                next;
                    219:                        }
                    220:                     }
                    221:                     $1 ~ /^d....w/ \
                    222:         { print "Root path directory " $10 " is group writeable." } \
                    223:                     $1 ~ /^d.......w/ \
                    224:         { print "Root path directory " $10 " is other writeable." }' \
                    225:                < $TMP1 >> $OUTPUT
                    226:
                    227:        fi
                    228: done
                    229: if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1.41      millert   230:        echo "\nChecking root sh paths, umask values:\n${list}"
1.13      millert   231:        if [ -s $OUTPUT ] ; then
1.1       deraadt   232:                cat $OUTPUT
                    233:        fi
                    234:        if [ $umaskset = "no" ] ; then
1.41      millert   235:                echo "\nRoot sh startup files do not set the umask."
1.1       deraadt   236:        fi
                    237: fi
                    238:
1.27      marc      239: # A good .kshrc will not have a umask or path, that being set in .profile
                    240: # check anyway.
                    241: > $OUTPUT
                    242: rhome=/root
1.29      marc      243: list="/etc/ksh.kshrc `cat $TMP2`"
                    244: (cd $rhome
                    245:  for i in $list; do
1.27      marc      246:        if [ -s $i ] ; then
                    247:                egrep umask $i |
                    248:                awk '$2 % 100 < 20 \
                    249:                        { print "Root umask is group writeable" } \
                    250:                     $2 % 10 < 2 \
                    251:                        { print "Root umask is other writeable" }' >> $OUTPUT
                    252:                if egrep PATH= $i > /dev/null ; then
                    253:                        SAVE_PATH=$PATH
                    254:                        unset PATH
                    255:                        /bin/ksh << end-of-sh > /dev/null 2>&1
                    256:                                . $i
1.29      marc      257:                                if [ X"\$PATH" != "X" ]; then
                    258:                                        list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
                    259:                                        /bin/ls -ldgT \$list > $TMP1
                    260:                                else
                    261:                                        > $TMP1
                    262:                                fi
1.27      marc      263: end-of-sh
                    264:                        PATH=$SAVE_PATH
                    265:                        awk '{
                    266:                                if ($10 ~ /^\.$/) {
                    267:                                        print "The root path includes .";
                    268:                                        next;
                    269:                                }
                    270:                            }
                    271:                            $1 ~ /^d....w/ \
                    272:                { print "Root path directory " $10 " is group writeable." } \
                    273:                            $1 ~ /^d.......w/ \
                    274:                { print "Root path directory " $10 " is other writeable." }' \
                    275:                        < $TMP1 >> $OUTPUT
                    276:                fi
                    277:
                    278:        fi
1.29      marc      279:  done
                    280: )
1.27      marc      281: if [ -s $OUTPUT ] ; then
1.41      millert   282:        echo "\nChecking root ksh paths, umask values:\n${list}"
1.27      marc      283:        cat $OUTPUT
                    284: fi
                    285:
1.1       deraadt   286: # Root and uucp should both be in /etc/ftpusers.
                    287: if egrep root /etc/ftpusers > /dev/null ; then
                    288:        :
                    289: else
1.41      millert   290:        echo "\nRoot not listed in /etc/ftpusers file."
1.1       deraadt   291: fi
                    292: if egrep uucp /etc/ftpusers > /dev/null ; then
                    293:        :
                    294: else
1.41      millert   295:        echo "\nUucp not listed in /etc/ftpusers file."
1.1       deraadt   296: fi
                    297:
1.35      millert   298: # Uudecode should not be in the /etc/mail/aliases file.
                    299: if egrep 'uudecode|decode' /etc/mail/aliases; then
1.41      millert   300:        echo "\nThere is an entry for uudecode in the /etc/mail/aliases file."
1.1       deraadt   301: fi
                    302:
                    303: # Files that should not have + signs.
1.2       deraadt   304: list="/etc/hosts.equiv /etc/shosts.equiv /etc/hosts.lpd"
1.1       deraadt   305: for f in $list ; do
1.6       millert   306:        if [ -s $f ] ; then
1.2       deraadt   307:                awk '{
1.13      millert   308:                        if ($0 ~ /^\+@.*$/)
1.2       deraadt   309:                                next;
1.13      millert   310:                        if ($0 ~ /^\+.*$/)
1.2       deraadt   311:                                printf("\nPlus sign in %s file.\n", FILENAME);
                    312:                }' $f
1.1       deraadt   313:        fi
                    314: done
                    315:
1.13      millert   316: # Check for special users with .rhosts/.shosts files.  Only root
                    317: # should have .rhosts/.shosts files.  Also, .rhosts/.shosts
                    318: # files should not have plus signs.
1.14      millert   319: awk -F: '$1 != "root" && $1 !~ /^[+-]/ && \
1.1       deraadt   320:        ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
                    321:                { print $1 " " $6 }' /etc/passwd |
                    322: while read uid homedir; do
1.2       deraadt   323:        for j in .rhosts .shosts; do
1.14      millert   324:                # Root owned .rhosts/.shosts files are ok.
1.15      millert   325:                if [ -s ${homedir}/$j -a ! -O ${homedir}/$j ] ; then
1.2       deraadt   326:                        rhost=`ls -ldgT ${homedir}/$j`
1.41      millert   327:                        echo "${uid}: ${rhost}"
1.2       deraadt   328:                fi
                    329:        done
1.1       deraadt   330: done > $OUTPUT
                    331: if [ -s $OUTPUT ] ; then
1.41      millert   332:        echo "\nChecking for special users with .rhosts/.shosts files."
1.1       deraadt   333:        cat $OUTPUT
                    334: fi
                    335:
1.14      millert   336: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   337: while read uid homedir; do
1.2       deraadt   338:        for j in .rhosts .shosts; do
1.13      millert   339:                if [ -s ${homedir}/$j ] ; then
1.2       deraadt   340:                        awk '{
                    341:                                if ($0 ~ /^+@.*$/ )
                    342:                                        next;
1.4       deraadt   343:                                if ($0 ~ /^\+[  ]*$/ )
1.2       deraadt   344:                                        printf("%s has + sign in it.\n",
1.13      millert   345:                                                FILENAME);
1.2       deraadt   346:                        }' ${homedir}/$j
                    347:                fi
                    348:        done
1.1       deraadt   349: done > $OUTPUT
                    350: if [ -s $OUTPUT ] ; then
1.41      millert   351:        echo "\nChecking .rhosts/.shosts files syntax."
1.1       deraadt   352:        cat $OUTPUT
                    353: fi
                    354:
                    355: # Check home directories.  Directories should not be owned by someone else
                    356: # or writeable.
1.14      millert   357: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   358: while read uid homedir; do
                    359:        if [ -d ${homedir}/ ] ; then
                    360:                file=`ls -ldgT ${homedir}`
1.41      millert   361:                echo "${uid} ${file}"
1.1       deraadt   362:        fi
                    363: done |
                    364: awk '$1 != $4 && $4 != "root" \
                    365:        { print "user " $1 " home directory is owned by " $4 }
                    366:      $2 ~ /^-....w/ \
                    367:        { print "user " $1 " home directory is group writeable" }
                    368:      $2 ~ /^-.......w/ \
                    369:        { print "user " $1 " home directory is other writeable" }' > $OUTPUT
                    370: if [ -s $OUTPUT ] ; then
1.41      millert   371:        echo "\nChecking home directories."
1.1       deraadt   372:        cat $OUTPUT
                    373: fi
                    374:
                    375: # Files that should not be owned by someone else or readable.
1.43    ! todd      376: list=".netrc .rhosts .gnupg/secring.gpg .gnupg/random_seed \
        !           377:        .pgp/secring.pgp .shosts .ssh/identity .ssh/random_seed"
1.14      millert   378: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   379: while read uid homedir; do
                    380:        for f in $list ; do
                    381:                file=${homedir}/${f}
                    382:                if [ -f $file ] ; then
1.41      millert   383:                        echo "${uid} ${f} `ls -ldgT ${file}`"
1.1       deraadt   384:                fi
                    385:        done
                    386: done |
                    387: awk '$1 != $5 && $5 != "root" \
                    388:        { print "user " $1 " " $2 " file is owned by " $5 }
1.13      millert   389:      $3 ~ /^-...r/ \
                    390:        { print "user " $1 " " $2 " file is group readable" }
1.1       deraadt   391:      $3 ~ /^-......r/ \
                    392:        { print "user " $1 " " $2 " file is other readable" }
                    393:      $3 ~ /^-....w/ \
                    394:        { print "user " $1 " " $2 " file is group writeable" }
                    395:      $3 ~ /^-.......w/ \
                    396:        { print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
                    397:
                    398: # Files that should not be owned by someone else or writeable.
1.28      todd      399: list=".bashrc .bash_profile .bash_login .bash_logout .cshrc \
                    400:       .emacs .exrc .forward .fvwmrc .inputrc .klogin .kshrc .login \
                    401:       .logout .nexrc .profile .screenrc .ssh .ssh/config \
                    402:       .ssh/authorized_keys .ssh/environment .ssh/known_hosts .ssh/rc \
                    403:       .tcshrc .twmrc .xsession .xinitrc .Xdefaults .Xauthority"
1.14      millert   404: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1       deraadt   405: while read uid homedir; do
                    406:        for f in $list ; do
                    407:                file=${homedir}/${f}
                    408:                if [ -f $file ] ; then
1.41      millert   409:                        echo "${uid} ${f} `ls -ldgT ${file}`"
1.1       deraadt   410:                fi
                    411:        done
                    412: done |
                    413: awk '$1 != $5 && $5 != "root" \
                    414:        { print "user " $1 " " $2 " file is owned by " $5 }
                    415:      $3 ~ /^-....w/ \
                    416:        { print "user " $1 " " $2 " file is group writeable" }
                    417:      $3 ~ /^-.......w/ \
                    418:        { print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
                    419: if [ -s $OUTPUT ] ; then
1.41      millert   420:        echo "\nChecking dot files."
1.1       deraadt   421:        cat $OUTPUT
                    422: fi
                    423:
                    424: # Mailboxes should be owned by user and unreadable.
                    425: ls -l /var/mail | sed 1d | \
                    426: awk '$3 != $9 \
                    427:        { print "user " $9 " mailbox is owned by " $3 }
                    428:      $1 != "-rw-------" \
                    429:        { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT
                    430: if [ -s $OUTPUT ] ; then
1.41      millert   431:        echo "\nChecking mailbox ownership."
1.1       deraadt   432:        cat $OUTPUT
                    433: fi
                    434:
1.13      millert   435: # File systems should not be globally exported.
                    436: if [ -s /etc/exports ] ; then
                    437:        awk '{
1.19      flipk     438:                if (($1 ~ /^#/) || ($1 ~ /^$/))
1.1       deraadt   439:                        next;
1.13      millert   440:                readonly = 0;
                    441:                for (i = 2; i <= NF; ++i) {
1.19      flipk     442:                        if ($i ~ /^-ro$/)
1.13      millert   443:                                readonly = 1;
                    444:                        else if ($i !~ /^-/)
                    445:                                next;
                    446:                }
                    447:                if (readonly)
                    448:                        print "File system " $1 " globally exported, read-only."
                    449:                else
                    450:                        print "File system " $1 " globally exported, read-write."
                    451:        }' < /etc/exports > $OUTPUT
                    452:        if [ -s $OUTPUT ] ; then
1.41      millert   453:                echo "\nChecking for globally exported file systems."
1.13      millert   454:                cat $OUTPUT
                    455:        fi
1.1       deraadt   456: fi
                    457:
1.5       deraadt   458: # Display any changes in setuid/setgid files and devices.
                    459: pending="\nChecking setuid/setgid files and devices:\n"
1.1       deraadt   460: (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \
1.13      millert   461:        -o -fstype procfs \) -a -prune -o \
                    462:        -type f -a \( -perm -u+s -o -perm -g+s \) -print0 -o \
1.30      millert   463:        ! -type d -a ! -type f -a ! -type l -a ! -type s -a ! -type p \
                    464:        -print0 | xargs -0 ls -ldgT | sort +9 > $LIST) 2> $OUTPUT
1.1       deraadt   465:
                    466: # Display any errors that occurred during system file walk.
                    467: if [ -s $OUTPUT ] ; then
1.41      millert   468:        echo "${pending}Setuid/device find errors:"
1.2       deraadt   469:        pending=
1.1       deraadt   470:        cat $OUTPUT
1.41      millert   471:        echo ""
1.1       deraadt   472: fi
                    473:
1.12      millert   474: # Display any changes in the setuid/setgid file list.
1.13      millert   475: egrep -v '^[bc]' $LIST > $TMP1
1.1       deraadt   476: if [ -s $TMP1 ] ; then
                    477:        # Check to make sure uudecode isn't setuid.
                    478:        if grep -w uudecode $TMP1 > /dev/null ; then
1.41      millert   479:                echo "${pending}\nUudecode is setuid."
1.2       deraadt   480:                pending=
1.1       deraadt   481:        fi
                    482:
                    483:        CUR=/var/backups/setuid.current
                    484:        BACK=/var/backups/setuid.backup
                    485:
                    486:        if [ -s $CUR ] ; then
                    487:                if cmp -s $CUR $TMP1 ; then
                    488:                        :
                    489:                else
                    490:                        > $TMP2
1.13      millert   491:                        join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
1.1       deraadt   492:                        if [ -s $OUTPUT ] ; then
1.41      millert   493:                                echo "${pending}Setuid additions:"
1.2       deraadt   494:                                pending=
1.1       deraadt   495:                                tee -a $TMP2 < $OUTPUT
1.41      millert   496:                                echo ""
1.1       deraadt   497:                        fi
                    498:
1.13      millert   499:                        join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
1.1       deraadt   500:                        if [ -s $OUTPUT ] ; then
1.41      millert   501:                                echo "${pending}Setuid deletions:"
1.2       deraadt   502:                                pending=
1.1       deraadt   503:                                tee -a $TMP2 < $OUTPUT
1.41      millert   504:                                echo ""
1.1       deraadt   505:                        fi
                    506:
1.13      millert   507:                        sort +9 $TMP2 $CUR $TMP1 | \
1.1       deraadt   508:                            sed -e 's/[  ][      ]*/ /g' | uniq -u > $OUTPUT
                    509:                        if [ -s $OUTPUT ] ; then
1.41      millert   510:                                echo "${pending}Setuid changes:"
1.2       deraadt   511:                                pending=
1.1       deraadt   512:                                column -t $OUTPUT
1.41      millert   513:                                echo ""
1.1       deraadt   514:                        fi
                    515:
                    516:                        cp $CUR $BACK
                    517:                        cp $TMP1 $CUR
                    518:                fi
                    519:        else
1.41      millert   520:                echo "${pending}Setuid additions:"
1.2       deraadt   521:                pending=
1.1       deraadt   522:                column -t $TMP1
1.41      millert   523:                echo ""
1.1       deraadt   524:                cp $TMP1 $CUR
                    525:        fi
                    526: fi
                    527:
                    528: # Check for block and character disk devices that are readable or writeable
                    529: # or not owned by root.operator.
                    530: >$TMP1
1.13      millert   531: DISKLIST="ccd dk fd hd hk hp jb kra ra rb rd rl rx rz sd up vnd wd xd"
1.1       deraadt   532: for i in $DISKLIST; do
1.33      millert   533:        egrep "^b.*/${i}[0-9][0-9]*[B-H]?[a-p]$"  $LIST >> $TMP1
                    534:        egrep "^c.*/r${i}[0-9][0-9]*[B-H]?[a-p]$"  $LIST >> $TMP1
1.1       deraadt   535: done
                    536:
                    537: awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
                    538:        { printf("Disk %s is user %s, group %s, permissions %s.\n", \
                    539:            $11, $3, $4, $1); }' < $TMP1 > $OUTPUT
                    540: if [ -s $OUTPUT ] ; then
1.41      millert   541:        echo "\nChecking disk ownership and permissions."
1.1       deraadt   542:        cat $OUTPUT
1.41      millert   543:        echo ""
1.1       deraadt   544: fi
                    545:
                    546: # Display any changes in the device file list.
                    547: egrep '^[bc]' $LIST | sort +10 > $TMP1
                    548: if [ -s $TMP1 ] ; then
                    549:        CUR=/var/backups/device.current
                    550:        BACK=/var/backups/device.backup
                    551:
                    552:        if [ -s $CUR ] ; then
                    553:                if cmp -s $CUR $TMP1 ; then
                    554:                        :
                    555:                else
                    556:                        > $TMP2
                    557:                        join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
                    558:                        if [ -s $OUTPUT ] ; then
1.41      millert   559:                                echo "Device additions:"
1.1       deraadt   560:                                tee -a $TMP2 < $OUTPUT
1.41      millert   561:                                echo ""
1.1       deraadt   562:                        fi
                    563:
                    564:                        join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
                    565:                        if [ -s $OUTPUT ] ; then
1.41      millert   566:                                echo "Device deletions:"
1.1       deraadt   567:                                tee -a $TMP2 < $OUTPUT
1.41      millert   568:                                echo ""
1.1       deraadt   569:                        fi
                    570:
                    571:                        # Report any block device change.  Ignore character
                    572:                        # devices, only the name is significant.
                    573:                        cat $TMP2 $CUR $TMP1 | \
                    574:                        sed -e '/^c/d' | \
                    575:                        sort +10 | \
                    576:                        sed -e 's/[      ][      ]*/ /g' | \
                    577:                        uniq -u > $OUTPUT
                    578:                        if [ -s $OUTPUT ] ; then
1.41      millert   579:                                echo "Block device changes:"
1.1       deraadt   580:                                column -t $OUTPUT
1.41      millert   581:                                echo ""
1.1       deraadt   582:                        fi
                    583:
                    584:                        cp $CUR $BACK
                    585:                        cp $TMP1 $CUR
                    586:                fi
                    587:        else
1.41      millert   588:                echo "Device additions:"
1.1       deraadt   589:                column -t $TMP1
1.41      millert   590:                echo ""
1.1       deraadt   591:                cp $TMP1 $CUR
                    592:        fi
                    593: fi
                    594:
                    595: # Check special files.
                    596: # Check system binaries.
                    597: #
                    598: # Create the mtree tree specifications using:
                    599: #
                    600: #      mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
1.2       deraadt   601: #      chown root.wheel DIR.secure
                    602: #      chmod 600 DIR.secure
1.1       deraadt   603: #
                    604: # Note, this is not complete protection against Trojan horsed binaries, as
                    605: # the hacker can modify the tree specification to match the replaced binary.
                    606: # For details on really protecting yourself against modified binaries, see
                    607: # the mtree(8) manual page.
1.13      millert   608: if [ -d /etc/mtree ] ; then
1.2       deraadt   609:        cd /etc/mtree
1.1       deraadt   610:        mtree -e -p / -f /etc/mtree/special > $OUTPUT
                    611:        if [ -s $OUTPUT ] ; then
1.41      millert   612:                echo "\nChecking special files and directories."
                    613:                echo "Output format is:\n\tfilename:"
                    614:                echo "\t\tcriteria (shouldbe, reallyis)"
1.1       deraadt   615:                cat $OUTPUT
                    616:        fi
                    617:
                    618:        > $OUTPUT
                    619:        for file in *.secure; do
1.2       deraadt   620:                [ $file = '*.secure' ] && continue
1.1       deraadt   621:                tree=`sed -n -e '3s/.* //p' -e 3q $file`
                    622:                mtree -f $file -p $tree > $TMP1
1.13      millert   623:                if [ -s $TMP1 ] ; then
1.41      millert   624:                        echo "\nChecking ${tree}:" >> $OUTPUT
1.1       deraadt   625:                        cat $TMP1 >> $OUTPUT
                    626:                fi
                    627:        done
                    628:        if [ -s $OUTPUT ] ; then
1.41      millert   629:                echo "\nChecking system binaries:"
1.1       deraadt   630:                cat $OUTPUT
                    631:        fi
1.2       deraadt   632: else
                    633:        echo /etc/mtree is missing
1.1       deraadt   634: fi
                    635:
                    636: # List of files that get backed up and checked for any modifications.  Each
                    637: # file is expected to have two backups, /var/backups/file.{current,backup}.
                    638: # Any changes cause the files to rotate.
1.37      todd      639: _fnchg() {
                    640:        echo "$1" | sed 's/^\///;s/\//_/g'
                    641: }
1.1       deraadt   642: if [ -s /etc/changelist ] ; then
1.24      deraadt   643:        for file in `egrep -v "^#|$MP" /etc/changelist`; do
1.37      todd      644:                CUR=/var/backups/$(_fnchg  "$file").current
                    645:                BACK=/var/backups/$(_fnchg "$file").backup
                    646:                if [ -s $file -a ! -d $file ] ; then
1.1       deraadt   647:                        if [ -s $CUR ] ; then
1.42      marc      648:                                diff -u $CUR $file > $OUTPUT
1.1       deraadt   649:                                if [ -s $OUTPUT ] ; then
1.42      marc      650:                echo "\n======\n${file} diffs (-OLD  +NEW)\n======"
1.1       deraadt   651:                                        cat $OUTPUT
                    652:                                        cp -p $CUR $BACK
                    653:                                        cp -p $file $CUR
                    654:                                        chown root.wheel $CUR $BACK
                    655:                                fi
                    656:                        else
                    657:                                cp -p $file $CUR
                    658:                                chown root.wheel $CUR
                    659:                        fi
                    660:                fi
                    661:        done
                    662: fi