Annotation of src/etc/security, Revision 1.33
1.1 deraadt 1: #!/bin/sh -
2: #
1.33 ! millert 3: # $OpenBSD: security,v 1.32 1999/06/19 17:14:31 espie 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
20: printf "tmp directory %s already exists, looks like:\n" $DIR
21: ls -alF $DIR
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)
51: printf("Login %s if off but still has valid shell and home directory is unreadable\n\t by root; cannot check for existance of alternate access files.\n", $1);
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.1 deraadt 56: printf("Login %s has a user id of 0.\n", $1);
57: if ($3 < 0)
58: printf("Login %s has a negative user id.\n", $1);
59: if ($4 < 0)
60: printf("Login %s has a negative group id.\n", $1);
61: }' < $MP > $OUTPUT
62: if [ -s $OUTPUT ] ; then
63: printf "\nChecking the $MP file:\n"
64: cat $OUTPUT
65: fi
66:
67: awk -F: '{ print $1 }' $MP | sort | uniq -d > $OUTPUT
68: if [ -s $OUTPUT ] ; then
69: printf "\n$MP has duplicate user names.\n"
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
76: printf "\n$MP has duplicate user id's.\n"
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]*/)
120: printf("Login %s has a negative group id.\n", $1);
121: }' < $GRP > $OUTPUT
122: if [ -s $OUTPUT ] ; then
123: printf "\nChecking the $GRP file:\n"
124: cat $OUTPUT
125: fi
126:
127: awk -F: '{ print $1 }' $GRP | sort | uniq -d > $OUTPUT
128: if [ -s $OUTPUT ] ; then
129: printf "\n$GRP has duplicate group names.\n"
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
176: printf "\nChecking root csh paths, umask values:\n$list\n"
1.13 millert 177: if [ -s $OUTPUT ] ; then
1.1 deraadt 178: cat $OUTPUT
179: fi
180: if [ $umaskset = "no" ] ; then
181: printf "\nRoot csh startup files do not set the umask.\n"
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
230: printf "\nChecking root sh paths, umask values:\n$list\n"
1.13 millert 231: if [ -s $OUTPUT ] ; then
1.1 deraadt 232: cat $OUTPUT
233: fi
234: if [ $umaskset = "no" ] ; then
235: printf "\nRoot sh startup files do not set the umask.\n"
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
282: printf "\nChecking root ksh paths, umask values:\n$list\n"
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
290: printf "\nRoot not listed in /etc/ftpusers file.\n"
291: fi
292: if egrep uucp /etc/ftpusers > /dev/null ; then
293: :
294: else
295: printf "\nUucp not listed in /etc/ftpusers file.\n"
296: fi
297:
298: # Uudecode should not be in the /etc/aliases file.
299: if egrep 'uudecode|decode' /etc/aliases; then
300: printf "\nThere is an entry for uudecode in the /etc/aliases file.\n"
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`
327: printf "$uid: $rhost\n"
328: fi
329: done
1.1 deraadt 330: done > $OUTPUT
331: if [ -s $OUTPUT ] ; then
1.2 deraadt 332: printf "\nChecking for special users with .rhosts/.shosts files.\n"
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.2 deraadt 351: printf "\nChecking .rhosts/.shosts files syntax.\n"
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}`
361: printf "$uid $file\n"
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
371: printf "\nChecking home directories.\n"
372: cat $OUTPUT
373: fi
374:
375: # Files that should not be owned by someone else or readable.
1.28 todd 376: list=".netrc .rhosts .pgp/secring.pgp .shosts .ssh/identity .ssh/random_seed"
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
382: printf "$uid $f `ls -ldgT $file`\n"
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/ \
393: { print "user " $1 " " $2 " file is group writeable" }
394: $3 ~ /^-.......w/ \
395: { print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
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 \
401: .ssh/authorized_keys .ssh/environment .ssh/known_hosts .ssh/rc \
402: .tcshrc .twmrc .xsession .xinitrc .Xdefaults .Xauthority"
1.14 millert 403: awk -F: '/^[^+-]/ { print $1 " " $6 }' /etc/passwd | \
1.1 deraadt 404: while read uid homedir; do
405: for f in $list ; do
406: file=${homedir}/${f}
407: if [ -f $file ] ; then
408: printf "$uid $f `ls -ldgT $file`\n"
409: fi
410: done
411: done |
412: awk '$1 != $5 && $5 != "root" \
413: { print "user " $1 " " $2 " file is owned by " $5 }
414: $3 ~ /^-....w/ \
415: { print "user " $1 " " $2 " file is group writeable" }
416: $3 ~ /^-.......w/ \
417: { print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
418: if [ -s $OUTPUT ] ; then
419: printf "\nChecking dot files.\n"
420: cat $OUTPUT
421: fi
422:
423: # Mailboxes should be owned by user and unreadable.
424: ls -l /var/mail | sed 1d | \
425: awk '$3 != $9 \
426: { print "user " $9 " mailbox is owned by " $3 }
427: $1 != "-rw-------" \
428: { print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT
429: if [ -s $OUTPUT ] ; then
430: printf "\nChecking mailbox ownership.\n"
431: cat $OUTPUT
432: fi
433:
1.13 millert 434: # File systems should not be globally exported.
435: if [ -s /etc/exports ] ; then
436: awk '{
1.19 flipk 437: if (($1 ~ /^#/) || ($1 ~ /^$/))
1.1 deraadt 438: next;
1.13 millert 439: readonly = 0;
440: for (i = 2; i <= NF; ++i) {
1.19 flipk 441: if ($i ~ /^-ro$/)
1.13 millert 442: readonly = 1;
443: else if ($i !~ /^-/)
444: next;
445: }
446: if (readonly)
447: print "File system " $1 " globally exported, read-only."
448: else
449: print "File system " $1 " globally exported, read-write."
450: }' < /etc/exports > $OUTPUT
451: if [ -s $OUTPUT ] ; then
452: printf "\nChecking for globally exported file systems.\n"
453: cat $OUTPUT
454: fi
1.1 deraadt 455: fi
456:
1.5 deraadt 457: # Display any changes in setuid/setgid files and devices.
458: pending="\nChecking setuid/setgid files and devices:\n"
1.1 deraadt 459: (find / \( ! -fstype local -o -fstype fdesc -o -fstype kernfs \
1.13 millert 460: -o -fstype procfs \) -a -prune -o \
461: -type f -a \( -perm -u+s -o -perm -g+s \) -print0 -o \
1.30 millert 462: ! -type d -a ! -type f -a ! -type l -a ! -type s -a ! -type p \
463: -print0 | xargs -0 ls -ldgT | sort +9 > $LIST) 2> $OUTPUT
1.1 deraadt 464:
465: # Display any errors that occurred during system file walk.
466: if [ -s $OUTPUT ] ; then
1.2 deraadt 467: printf "${pending}Setuid/device find errors:\n"
468: pending=
1.1 deraadt 469: cat $OUTPUT
470: printf "\n"
471: fi
472:
1.12 millert 473: # Display any changes in the setuid/setgid file list.
1.13 millert 474: egrep -v '^[bc]' $LIST > $TMP1
1.1 deraadt 475: if [ -s $TMP1 ] ; then
476: # Check to make sure uudecode isn't setuid.
477: if grep -w uudecode $TMP1 > /dev/null ; then
1.2 deraadt 478: printf "${pending}\nUudecode is setuid.\n"
479: pending=
1.1 deraadt 480: fi
481:
482: CUR=/var/backups/setuid.current
483: BACK=/var/backups/setuid.backup
484:
485: if [ -s $CUR ] ; then
486: if cmp -s $CUR $TMP1 ; then
487: :
488: else
489: > $TMP2
1.13 millert 490: join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
1.1 deraadt 491: if [ -s $OUTPUT ] ; then
1.2 deraadt 492: printf "${pending}Setuid additions:\n"
493: pending=
1.1 deraadt 494: tee -a $TMP2 < $OUTPUT
495: printf "\n"
496: fi
497:
1.13 millert 498: join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
1.1 deraadt 499: if [ -s $OUTPUT ] ; then
1.2 deraadt 500: printf "${pending}Setuid deletions:\n"
501: pending=
1.1 deraadt 502: tee -a $TMP2 < $OUTPUT
503: printf "\n"
504: fi
505:
1.13 millert 506: sort +9 $TMP2 $CUR $TMP1 | \
1.1 deraadt 507: sed -e 's/[ ][ ]*/ /g' | uniq -u > $OUTPUT
508: if [ -s $OUTPUT ] ; then
1.2 deraadt 509: printf "${pending}Setuid changes:\n"
510: pending=
1.1 deraadt 511: column -t $OUTPUT
512: printf "\n"
513: fi
514:
515: cp $CUR $BACK
516: cp $TMP1 $CUR
517: fi
518: else
1.2 deraadt 519: printf "${pending}Setuid additions:\n"
520: pending=
1.1 deraadt 521: column -t $TMP1
522: printf "\n"
523: cp $TMP1 $CUR
524: fi
525: fi
526:
527: # Check for block and character disk devices that are readable or writeable
528: # or not owned by root.operator.
529: >$TMP1
1.13 millert 530: DISKLIST="ccd dk fd hd hk hp jb kra ra rb rd rl rx rz sd up vnd wd xd"
1.1 deraadt 531: for i in $DISKLIST; do
1.33 ! millert 532: egrep "^b.*/${i}[0-9][0-9]*[B-H]?[a-p]$" $LIST >> $TMP1
! 533: egrep "^c.*/r${i}[0-9][0-9]*[B-H]?[a-p]$" $LIST >> $TMP1
1.1 deraadt 534: done
535:
536: awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
537: { printf("Disk %s is user %s, group %s, permissions %s.\n", \
538: $11, $3, $4, $1); }' < $TMP1 > $OUTPUT
539: if [ -s $OUTPUT ] ; then
540: printf "\nChecking disk ownership and permissions.\n"
541: cat $OUTPUT
542: printf "\n"
543: fi
544:
545: # Display any changes in the device file list.
546: egrep '^[bc]' $LIST | sort +10 > $TMP1
547: if [ -s $TMP1 ] ; then
548: CUR=/var/backups/device.current
549: BACK=/var/backups/device.backup
550:
551: if [ -s $CUR ] ; then
552: if cmp -s $CUR $TMP1 ; then
553: :
554: else
555: > $TMP2
556: join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
557: if [ -s $OUTPUT ] ; then
558: printf "Device additions:\n"
559: tee -a $TMP2 < $OUTPUT
560: printf "\n"
561: fi
562:
563: join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
564: if [ -s $OUTPUT ] ; then
565: printf "Device deletions:\n"
566: tee -a $TMP2 < $OUTPUT
567: printf "\n"
568: fi
569:
570: # Report any block device change. Ignore character
571: # devices, only the name is significant.
572: cat $TMP2 $CUR $TMP1 | \
573: sed -e '/^c/d' | \
574: sort +10 | \
575: sed -e 's/[ ][ ]*/ /g' | \
576: uniq -u > $OUTPUT
577: if [ -s $OUTPUT ] ; then
578: printf "Block device changes:\n"
579: column -t $OUTPUT
580: printf "\n"
581: fi
582:
583: cp $CUR $BACK
584: cp $TMP1 $CUR
585: fi
586: else
587: printf "Device additions:\n"
588: column -t $TMP1
589: printf "\n"
590: cp $TMP1 $CUR
591: fi
592: fi
593:
594: # Check special files.
595: # Check system binaries.
596: #
597: # Create the mtree tree specifications using:
598: #
599: # mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
1.2 deraadt 600: # chown root.wheel DIR.secure
601: # chmod 600 DIR.secure
1.1 deraadt 602: #
603: # Note, this is not complete protection against Trojan horsed binaries, as
604: # the hacker can modify the tree specification to match the replaced binary.
605: # For details on really protecting yourself against modified binaries, see
606: # the mtree(8) manual page.
1.13 millert 607: if [ -d /etc/mtree ] ; then
1.2 deraadt 608: cd /etc/mtree
1.1 deraadt 609: mtree -e -p / -f /etc/mtree/special > $OUTPUT
610: if [ -s $OUTPUT ] ; then
611: printf "\nChecking special files and directories.\n"
612: cat $OUTPUT
613: fi
614:
615: > $OUTPUT
616: for file in *.secure; do
1.2 deraadt 617: [ $file = '*.secure' ] && continue
1.1 deraadt 618: tree=`sed -n -e '3s/.* //p' -e 3q $file`
619: mtree -f $file -p $tree > $TMP1
1.13 millert 620: if [ -s $TMP1 ] ; then
1.1 deraadt 621: printf "\nChecking $tree:\n" >> $OUTPUT
622: cat $TMP1 >> $OUTPUT
623: fi
624: done
625: if [ -s $OUTPUT ] ; then
626: printf "\nChecking system binaries:\n"
627: cat $OUTPUT
628: fi
1.2 deraadt 629: else
630: echo /etc/mtree is missing
1.1 deraadt 631: fi
632:
633: # List of files that get backed up and checked for any modifications. Each
634: # file is expected to have two backups, /var/backups/file.{current,backup}.
635: # Any changes cause the files to rotate.
636: if [ -s /etc/changelist ] ; then
1.24 deraadt 637: for file in `egrep -v "^#|$MP" /etc/changelist`; do
1.1 deraadt 638: CUR=/var/backups/`basename $file`.current
639: BACK=/var/backups/`basename $file`.backup
1.13 millert 640: if [ -s $file ] ; then
1.1 deraadt 641: if [ -s $CUR ] ; then
642: diff $CUR $file > $OUTPUT
643: if [ -s $OUTPUT ] ; then
644: printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file
645: cat $OUTPUT
646: cp -p $CUR $BACK
647: cp -p $file $CUR
648: chown root.wheel $CUR $BACK
649: fi
650: else
651: cp -p $file $CUR
652: chown root.wheel $CUR
653: fi
654: fi
655: done
656: fi