Annotation of src/etc/security, Revision 1.63
1.1 deraadt 1: #!/bin/sh -
2: #
1.63 ! millert 3: # $OpenBSD: security,v 1.62 2003/07/01 22:12:50 millert Exp $
1.13 millert 4: # from: @(#)security 8.1 (Berkeley) 6/9/93
1.1 deraadt 5: #
1.13 millert 6:
1.55 millert 7: PATH=/bin:/usr/bin:/sbin:/usr/sbin
1.1 deraadt 8:
9: umask 077
10:
1.60 avsm 11: DIR=`mktemp -d /tmp/_secure.XXXXXXXXXX` || exit 1
1.7 deraadt 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.8 deraadt 18:
1.25 deraadt 19: trap 'rm -rf $DIR; exit 1' 0 1 2 3 13 15
1.1 deraadt 20:
21: # Check the master password file syntax.
22: MP=/etc/master.passwd
23: awk -F: '{
24: if ($0 ~ /^[ ]*$/) {
25: printf("Line %d is a blank line.\n", NR);
26: next;
27: }
28: if (NF != 10)
1.32 espie 29: printf("Line %d has the wrong number of fields:\n%s\n", NR, $0);
1.15 millert 30: if ($1 ~ /^[+-]/)
1.2 deraadt 31: next;
32: if ($1 == "")
1.32 espie 33: printf("Line %d has an empty login field:\n%s\n", NR, $0);
1.59 grange 34: else if ($1 !~ /^[A-Za-z0-9_][A-Za-z0-9_\-\.]*\$?$/)
1.1 deraadt 35: printf("Login %s has non-alphanumeric characters.\n", $1);
1.48 brad 36: if (length($1) > 31)
37: printf("Login %s has more than 31 characters.\n", $1);
1.1 deraadt 38: if ($2 == "")
39: printf("Login %s has no password.\n", $1);
1.23 deraadt 40: if ($2 != "" && length($2) != 13 && ($10 ~ /.*sh$/ || $10 == "") &&
41: ($2 !~ /^\$[0-9a-f]+\$/) && ($2 != "skey")) {
1.51 millert 42: if (system("test -s /etc/skey/"$1"") == 0)
43: printf("Login %s is off but still has a valid shell and an entry in /etc/skey.\n", $1);
1.23 deraadt 44: if (system("test -d "$9" -a ! -r "$9"") == 0)
1.40 hugh 45: 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 46: 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"))
47: 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);
48: }
1.9 deraadt 49: if ($3 == 0 && $1 != "root")
1.36 aaron 50: printf("Login %s has a user ID of 0.\n", $1);
1.1 deraadt 51: if ($3 < 0)
1.36 aaron 52: printf("Login %s has a negative user ID.\n", $1);
1.1 deraadt 53: if ($4 < 0)
1.36 aaron 54: printf("Login %s has a negative group ID.\n", $1);
1.53 pvalchev 55: if ($7 != 0 && system("test "$7" -lt `date +%s`") == 0)
56: printf("Login %s has expired.\n", $1);
1.1 deraadt 57: }' < $MP > $OUTPUT
58: if [ -s $OUTPUT ] ; then
1.41 millert 59: echo "\nChecking the ${MP} file:"
1.1 deraadt 60: cat $OUTPUT
61: fi
62:
63: awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
64: if [ -s $OUTPUT ] ; then
1.41 millert 65: echo "\n${MP} has duplicate user names."
1.1 deraadt 66: column $OUTPUT
67: fi
68:
1.47 millert 69: awk -F: '/^[^\+]/ { print $1 " " $3 }' $MP | sort -n +1 | tee $TMP1 |
1.1 deraadt 70: uniq -d -f 1 | awk '{ print $2 }' > $TMP2
71: if [ -s $TMP2 ] ; then
1.41 millert 72: echo "\n${MP} has duplicate user ID's."
1.1 deraadt 73: while read uid; do
74: grep -w $uid $TMP1
75: done < $TMP2 | column
76: fi
77:
78: # Backup the master password file; a special case, the normal backup
79: # mechanisms also print out file differences and we don't want to do
80: # that because this file has encrypted passwords in it.
1.2 deraadt 81: if [ ! -d /var/backups ] ; then
82: mkdir /var/backups
1.31 deraadt 83: chmod 700 /var/backups
1.2 deraadt 84: fi
1.1 deraadt 85: CUR=/var/backups/`basename $MP`.current
86: BACK=/var/backups/`basename $MP`.backup
87: if [ -s $CUR ] ; then
88: if cmp -s $CUR $MP; then
89: :
90: else
91: cp -p $CUR $BACK
92: cp -p $MP $CUR
1.56 millert 93: chown root:wheel $CUR
1.1 deraadt 94: fi
95: else
96: cp -p $MP $CUR
1.56 millert 97: chown root:wheel $CUR
1.1 deraadt 98: fi
99:
100: # Check the group file syntax.
101: GRP=/etc/group
102: awk -F: '{
103: if ($0 ~ /^[ ]*$/) {
104: printf("Line %d is a blank line.\n", NR);
105: next;
106: }
1.2 deraadt 107: if ($1 ~ /^[+-].*$/)
108: next;
1.1 deraadt 109: if (NF != 4)
1.32 espie 110: printf("Line %d has the wrong number of fields:\n%s\n", NR, $0);
1.13 millert 111: if ($1 !~ /^[A-za-z0-9][A-za-z0-9_-]*$/)
1.1 deraadt 112: printf("Group %s has non-alphanumeric characters.\n", $1);
1.48 brad 113: if (length($1) > 31)
114: printf("Group %s has more than 31 characters.\n", $1);
1.1 deraadt 115: if ($3 !~ /[0-9]*/)
1.36 aaron 116: printf("Login %s has a negative group ID.\n", $1);
1.1 deraadt 117: }' < $GRP > $OUTPUT
118: if [ -s $OUTPUT ] ; then
1.41 millert 119: echo "\nChecking the ${GRP} file:"
1.1 deraadt 120: cat $OUTPUT
121: fi
122:
123: awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
124: if [ -s $OUTPUT ] ; then
1.41 millert 125: echo "\n${GRP} has duplicate group names."
1.1 deraadt 126: column $OUTPUT
127: fi
128:
129: # Check for root paths, umask values in startup files.
130: # The check for the root paths is problematical -- it's likely to fail
131: # in other environments. Once the shells have been modified to warn
132: # of '.' in the path, the path tests should go away.
133: > $OUTPUT
134: rhome=/root
135: umaskset=no
136: list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
137: for i in $list ; do
1.15 millert 138: if [ -s $i ] ; then
1.63 ! millert 139: if egrep -q '[[:space:]]*umask[[:space:]]' $i ; then
! 140: umaskset=yes
! 141: fi
1.61 millert 142: awk '{
143: if ($1 == "umask") {
1.62 millert 144: if ($2 % 100 / 10 ~ /^[0145]/)
1.61 millert 145: print "Root umask is group writable";
146: if ($2 % 10 ~ /^[0145]/)
147: print "Root umask is other writable";
148: }
1.63 ! millert 149: }' < $i >> $OUTPUT
1.21 deraadt 150: SAVE_PATH=$PATH
151: unset PATH
1.1 deraadt 152: /bin/csh -f -s << end-of-csh > /dev/null 2>&1
153: source $i
1.29 marc 154: if (\$?path) then
155: /bin/ls -ldgT \$path > $TMP1
156: else
157: cat /dev/null > $TMP1
158: endif
1.1 deraadt 159: end-of-csh
1.21 deraadt 160: PATH=$SAVE_PATH
1.1 deraadt 161: awk '{
162: if ($10 ~ /^\.$/) {
163: print "The root path includes .";
164: next;
165: }
166: }
167: $1 ~ /^d....w/ \
1.54 henning 168: { print "Root path directory " $10 " is group writable." } \
1.1 deraadt 169: $1 ~ /^d.......w/ \
1.54 henning 170: { print "Root path directory " $10 " is other writable." }' \
1.1 deraadt 171: < $TMP1 >> $OUTPUT
172: fi
173: done
174: if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1.41 millert 175: echo "\nChecking root csh paths, umask values:\n${list}"
1.13 millert 176: if [ -s $OUTPUT ] ; then
1.1 deraadt 177: cat $OUTPUT
178: fi
179: if [ $umaskset = "no" ] ; then
1.41 millert 180: echo "\nRoot csh startup files do not set the umask."
1.1 deraadt 181: fi
182: fi
183:
184: > $OUTPUT
1.29 marc 185: > $TMP2
1.1 deraadt 186: rhome=/root
187: umaskset=no
1.20 millert 188: list="/etc/profile ${rhome}/.profile"
1.1 deraadt 189: for i in $list; do
1.15 millert 190: if [ -s $i ] ; then
1.1 deraadt 191: if egrep umask $i > /dev/null ; then
192: umaskset=yes
193: fi
194: egrep umask $i |
195: awk '$2 % 100 < 20 \
1.54 henning 196: { print "Root umask is group writable" } \
1.1 deraadt 197: $2 % 10 < 2 \
1.54 henning 198: { print "Root umask is other writable" }' >> $OUTPUT
1.21 deraadt 199: SAVE_PATH=$PATH
1.29 marc 200: SAVE_ENV=$ENV
201: unset PATH ENV
1.1 deraadt 202: /bin/sh << end-of-sh > /dev/null 2>&1
203: . $i
1.29 marc 204: if [ X"\$PATH" != "X" ]; then
205: list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
206: /bin/ls -ldgT \$list > $TMP1
207: else
208: > $TMP1
209: fi
210: echo \$ENV >> $TMP2
1.1 deraadt 211: end-of-sh
1.21 deraadt 212: PATH=$SAVE_PATH
1.29 marc 213: ENV=$SAVE_ENV
1.1 deraadt 214: awk '{
215: if ($10 ~ /^\.$/) {
216: print "The root path includes .";
217: next;
218: }
219: }
220: $1 ~ /^d....w/ \
1.54 henning 221: { print "Root path directory " $10 " is group writable." } \
1.1 deraadt 222: $1 ~ /^d.......w/ \
1.54 henning 223: { print "Root path directory " $10 " is other writable." }' \
1.1 deraadt 224: < $TMP1 >> $OUTPUT
225:
226: fi
227: done
228: if [ $umaskset = "no" -o -s $OUTPUT ] ; then
1.41 millert 229: echo "\nChecking root sh paths, umask values:\n${list}"
1.13 millert 230: if [ -s $OUTPUT ] ; then
1.1 deraadt 231: cat $OUTPUT
232: fi
233: if [ $umaskset = "no" ] ; then
1.41 millert 234: echo "\nRoot sh startup files do not set the umask."
1.1 deraadt 235: fi
236: fi
237:
1.27 marc 238: # A good .kshrc will not have a umask or path, that being set in .profile
239: # check anyway.
240: > $OUTPUT
241: rhome=/root
1.29 marc 242: list="/etc/ksh.kshrc `cat $TMP2`"
243: (cd $rhome
244: for i in $list; do
1.27 marc 245: if [ -s $i ] ; then
246: egrep umask $i |
247: awk '$2 % 100 < 20 \
1.54 henning 248: { print "Root umask is group writable" } \
1.27 marc 249: $2 % 10 < 2 \
1.54 henning 250: { print "Root umask is other writable" }' >> $OUTPUT
1.27 marc 251: if egrep PATH= $i > /dev/null ; then
252: SAVE_PATH=$PATH
253: unset PATH
254: /bin/ksh << end-of-sh > /dev/null 2>&1
255: . $i
1.29 marc 256: if [ X"\$PATH" != "X" ]; then
257: list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
258: /bin/ls -ldgT \$list > $TMP1
259: else
260: > $TMP1
261: fi
1.27 marc 262: end-of-sh
263: PATH=$SAVE_PATH
264: awk '{
265: if ($10 ~ /^\.$/) {
266: print "The root path includes .";
267: next;
268: }
269: }
270: $1 ~ /^d....w/ \
1.54 henning 271: { print "Root path directory " $10 " is group writable." } \
1.27 marc 272: $1 ~ /^d.......w/ \
1.54 henning 273: { print "Root path directory " $10 " is other writable." }' \
1.27 marc 274: < $TMP1 >> $OUTPUT
275: fi
276:
277: fi
1.29 marc 278: done
279: )
1.27 marc 280: if [ -s $OUTPUT ] ; then
1.41 millert 281: echo "\nChecking root ksh paths, umask values:\n${list}"
1.27 marc 282: cat $OUTPUT
283: fi
284:
1.1 deraadt 285: # Root and uucp should both be in /etc/ftpusers.
286: if egrep root /etc/ftpusers > /dev/null ; then
287: :
288: else
1.41 millert 289: echo "\nRoot not listed in /etc/ftpusers file."
1.1 deraadt 290: fi
291: if egrep uucp /etc/ftpusers > /dev/null ; then
292: :
293: else
1.41 millert 294: echo "\nUucp not listed in /etc/ftpusers file."
1.1 deraadt 295: fi
296:
1.35 millert 297: # Uudecode should not be in the /etc/mail/aliases file.
298: if egrep 'uudecode|decode' /etc/mail/aliases; then
1.41 millert 299: echo "\nThere is an entry for uudecode in the /etc/mail/aliases file."
1.1 deraadt 300: fi
301:
302: # Files that should not have + signs.
1.2 deraadt 303: list="/etc/hosts.equiv /etc/shosts.equiv /etc/hosts.lpd"
1.1 deraadt 304: for f in $list ; do
1.6 millert 305: if [ -s $f ] ; then
1.2 deraadt 306: awk '{
1.13 millert 307: if ($0 ~ /^\+@.*$/)
1.2 deraadt 308: next;
1.13 millert 309: if ($0 ~ /^\+.*$/)
1.2 deraadt 310: printf("\nPlus sign in %s file.\n", FILENAME);
311: }' $f
1.1 deraadt 312: fi
313: done
314:
1.13 millert 315: # Check for special users with .rhosts/.shosts files. Only root
316: # should have .rhosts/.shosts files. Also, .rhosts/.shosts
317: # files should not have plus signs.
1.14 millert 318: awk -F: '$1 != "root" && $1 !~ /^[+-]/ && \
1.1 deraadt 319: ($3 < 100 || $1 == "ftp" || $1 == "uucp") \
320: { print $1 " " $6 }' /etc/passwd |
321: while read uid homedir; do
1.2 deraadt 322: for j in .rhosts .shosts; do
1.14 millert 323: # Root owned .rhosts/.shosts files are ok.
1.15 millert 324: if [ -s ${homedir}/$j -a ! -O ${homedir}/$j ] ; then
1.2 deraadt 325: rhost=`ls -ldgT ${homedir}/$j`
1.41 millert 326: echo "${uid}: ${rhost}"
1.2 deraadt 327: fi
328: done
1.1 deraadt 329: done > $OUTPUT
330: if [ -s $OUTPUT ] ; then
1.41 millert 331: echo "\nChecking for special users with .rhosts/.shosts files."
1.1 deraadt 332: cat $OUTPUT
333: fi
334:
1.14 millert 335: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1 deraadt 336: while read uid homedir; do
1.2 deraadt 337: for j in .rhosts .shosts; do
1.13 millert 338: if [ -s ${homedir}/$j ] ; then
1.2 deraadt 339: awk '{
340: if ($0 ~ /^+@.*$/ )
341: next;
1.4 deraadt 342: if ($0 ~ /^\+[ ]*$/ )
1.2 deraadt 343: printf("%s has + sign in it.\n",
1.13 millert 344: FILENAME);
1.2 deraadt 345: }' ${homedir}/$j
346: fi
347: done
1.1 deraadt 348: done > $OUTPUT
349: if [ -s $OUTPUT ] ; then
1.41 millert 350: echo "\nChecking .rhosts/.shosts files syntax."
1.1 deraadt 351: cat $OUTPUT
352: fi
353:
354: # Check home directories. Directories should not be owned by someone else
355: # or writeable.
1.14 millert 356: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1 deraadt 357: while read uid homedir; do
358: if [ -d ${homedir}/ ] ; then
359: file=`ls -ldgT ${homedir}`
1.41 millert 360: echo "${uid} ${file}"
1.1 deraadt 361: fi
362: done |
363: awk '$1 != $4 && $4 != "root" \
364: { print "user " $1 " home directory is owned by " $4 }
365: $2 ~ /^-....w/ \
1.54 henning 366: { print "user " $1 " home directory is group writable" }
1.1 deraadt 367: $2 ~ /^-.......w/ \
1.54 henning 368: { print "user " $1 " home directory is other writable" }' > $OUTPUT
1.1 deraadt 369: if [ -s $OUTPUT ] ; then
1.41 millert 370: echo "\nChecking home directories."
1.1 deraadt 371: cat $OUTPUT
372: fi
373:
374: # Files that should not be owned by someone else or readable.
1.43 todd 375: list=".netrc .rhosts .gnupg/secring.gpg .gnupg/random_seed \
1.45 millert 376: .pgp/secring.pgp .shosts .ssh/identity .ssh/id_dsa .ssh/id_rsa"
1.14 millert 377: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1 deraadt 378: while read uid homedir; do
379: for f in $list ; do
380: file=${homedir}/${f}
381: if [ -f $file ] ; then
1.41 millert 382: echo "${uid} ${f} `ls -ldgT ${file}`"
1.1 deraadt 383: fi
384: done
385: done |
386: awk '$1 != $5 && $5 != "root" \
387: { print "user " $1 " " $2 " file is owned by " $5 }
1.13 millert 388: $3 ~ /^-...r/ \
389: { print "user " $1 " " $2 " file is group readable" }
1.1 deraadt 390: $3 ~ /^-......r/ \
391: { print "user " $1 " " $2 " file is other readable" }
392: $3 ~ /^-....w/ \
1.54 henning 393: { print "user " $1 " " $2 " file is group writable" }
1.1 deraadt 394: $3 ~ /^-.......w/ \
1.54 henning 395: { print "user " $1 " " $2 " file is other writable" }' > $OUTPUT
1.1 deraadt 396:
397: # Files that should not be owned by someone else or writeable.
1.28 todd 398: list=".bashrc .bash_profile .bash_login .bash_logout .cshrc \
399: .emacs .exrc .forward .fvwmrc .inputrc .klogin .kshrc .login \
400: .logout .nexrc .profile .screenrc .ssh .ssh/config \
1.45 millert 401: .ssh/authorized_keys .ssh/authorized_keys2 .ssh/environment \
402: .ssh/known_hosts .ssh/rc .tcshrc .twmrc .xsession .xinitrc \
403: .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/ \
1.54 henning 416: { print "user " $1 " " $2 " file is group writable" }
1.1 deraadt 417: $3 ~ /^-.......w/ \
1.54 henning 418: { print "user " $1 " " $2 " file is other writable" }' >> $OUTPUT
1.1 deraadt 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.56 millert 601: # chown root:wheel DIR.secure
1.2 deraadt 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.49 jakob 610: mtree -e -l -p / -f /etc/mtree/special > $OUTPUT
1.1 deraadt 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.46 millert 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
1.56 millert 654: chown root:wheel $CUR $BACK
1.1 deraadt 655: fi
656: else
657: cp -p $file $CUR
1.56 millert 658: chown root:wheel $CUR
1.46 millert 659: fi
660: fi
661: done
662: for file in `egrep "^\+" /etc/changelist`; do
663: file="${file#+}"
664: CUR=/var/backups/$(_fnchg "$file").current.md5
665: BACK=/var/backups/$(_fnchg "$file").backup.md5
666: if [ -s $file -a ! -d $file ] ; then
667: MD5_NEW=`md5 $file | sed 's/^.* //'`
668: if [ -s $CUR ] ; then
669: MD5_OLD="`cat $CUR`"
670: if [ "$MD5_NEW" != "$MD5_OLD" ]; then
671: echo "\n======\n${file} MD5 checksums\n======"
672: echo "OLD: $MD5_OLD"
673: echo "NEW: $MD5_NEW"
674: cp -p $CUR $BACK
675: echo $MD5_NEW > $CUR
1.56 millert 676: chown root:wheel $CUR $BACK
1.46 millert 677: chmod 600 $CUR
678: fi
679: else
680: echo $MD5_NEW > $CUR
1.56 millert 681: chown root:wheel $CUR
1.46 millert 682: chmod 600 $CUR
1.1 deraadt 683: fi
684: fi
685: done
686: fi