# @(#)security 5.28 (Berkeley) %G%
PATH
=/sbin
:/usr
/sbin
:/bin
:/usr
/bin
trap 'rm -f $ERR $TMP1 $TMP2 $TMP3 $LIST $OUTPUT' 0
# Check the master password file syntax.
printf("Line %d is a blank line.\n", NR);
printf("Line %d has the wrong number of fields.\n", NR);
if ($1 !~ /^[A-Za-z0-9]*$/)
printf("Login %s has non-alphanumeric characters.\n", $1);
printf("Login %s has more than 8 characters.\n", $1);
printf("Login %s has no password.\n", $1);
if (length($2) != 13 && ($10 ~ /.*sh$/ || $10 == ""))
printf("Login %s is off but still has a valid shell.\n", $1);
if ($3 == 0 && $1 != "root" && $1 != "toor")
printf("Login %s has a user id of 0.\n", $1);
printf("Login %s has a negative user id.\n", $1);
printf("Login %s has a negative group id.\n", $1);
printf "\nChecking the $MP file:\n"
awk -F: '{ print $1 }' $MP |
sort |
uniq -d > $OUTPUT
printf "\n$MP has duplicate user names.\n"
awk -F: '{ print $1 " " $3 }' $MP |
sort -n +1 |
tee $TMP1 |
uniq -d -f 1 |
awk '{ print $2 }' > $TMP2
printf "\n$MP has duplicate user id's.\n"
# Backup the master password file; a special case, the normal backup
# mechanisms also print out file differences and we don't want to do
# that because this file has encrypted passwords in it.
CUR
=/var
/backups
/`basename $MP`.current
BACK
=/var
/backups
/`basename $MP`.backup
# Check the group file syntax.
printf("Line %d is a blank line.\n", NR);
printf("Line %d has the wrong number of fields.\n", NR);
if ($1 !~ /^[A-za-z0-9]*$/)
printf("Group %s has non-alphanumeric characters.\n", $1);
printf("Group %s has more than 8 characters.\n", $1);
printf("Login %s has a negative group id.\n", $1);
printf "\nChecking the $GRP file:\n"
awk -F: '{ print $1 }' $GRP |
sort |
uniq -d > $OUTPUT
printf "\n$GRP has duplicate group names.\n"
# Check for root paths, umask values in startup files.
# The check for the root paths is problematical -- it's likely to fail
# in other environments. Once the shells have been modified to warn
# of '.' in the path, the path tests should go away.
list
="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login"
if egrep umask $i > /dev
/null
; then
{ print "Root umask is group writeable" }
{ print "Root umask is other writeable" }' >> $OUTPUT
/bin
/csh
-f -s << end-of-csh > /dev/null 2>&1
/bin/ls -ldgT \$path > $TMP1
print "The root path includes .";
{ print "Root path directory " $10 " is group writeable." } \
{ print "Root path directory " $10 " is other writeable." }' \
if [ $umaskset = "no" -o -s $OUTPUT ] ; then
printf "\nChecking root csh paths, umask values:\n$list\n"
if [ $umaskset = "no" ] ; then
printf "\nRoot csh startup files do not set the umask.\n"
if egrep umask $i > /dev
/null
; then
{ print "Root umask is group writeable" } \
{ print "Root umask is other writeable" }' >> $OUTPUT
/bin
/sh
<< end-of-sh > /dev/null 2>&1
list=\`echo \$PATH | /usr/bin/sed -e 's/:/ /g'\`
/bin/ls -ldgT \$list > $TMP1
print "The root path includes .";
{ print "Root path directory " $10 " is group writeable." } \
{ print "Root path directory " $10 " is other writeable." }' \
if [ $umaskset = "no" -o -s $OUTPUT ] ; then
printf "\nChecking root sh paths, umask values:\n$list\n"
if [ $umaskset = "no" ] ; then
printf "\nRoot sh startup files do not set the umask.\n"
# Root and uucp should both be in /etc/ftpusers.
if egrep root
/etc
/ftpusers
> /dev
/null
; then
printf "\nRoot not listed in /etc/ftpusers file.\n"
if egrep uucp /etc
/ftpusers
> /dev
/null
; then
printf "\nUucp not listed in /etc/ftpusers file.\n"
# Uudecode should not be in the /etc/aliases file.
if egrep 'uudecode|decode' /etc
/aliases
; then
printf "\nThere is an entry for uudecode in the /etc/aliases file.\n"
# Files that should not have + signs.
list
="/etc/hosts.equiv /etc/hosts.lpd"
if egrep '\+' $f > /dev
/null
; then
printf "\nPlus sign in $f file.\n"
# Check for special users with .rhosts files. Only root and toor should
# have a .rhosts files. Also, .rhosts files should not plus signs.
awk -F: '$1 != "root" && $1 != "toor" && \
($3 < 100 || $1 == "ftp" || $1 == "uucp") \
{ print $1 " " $6 }' /etc
/passwd |
while read uid homedir
; do
if [ -f ${homedir}/.rhosts
] ; then
rhost
=`ls -ldgT ${homedir}/.rhosts`
printf "\nChecking for special users with .rhosts files.\n"
awk -F: '{ print $1 " " $6 }' /etc
/passwd | \
while read uid homedir
; do
if [ -f ${homedir}/.rhosts
] && \
egrep '\+' ${homedir}/.rhosts
> /dev
/null
; then
printf "$uid: + in .rhosts file.\n"
printf "\nChecking .rhosts files syntax.\n"
# Check home directories. Directories should not be owned by someone else
awk -F: '{ print $1 " " $6 }' /etc
/passwd | \
while read uid homedir
; do
if [ -d ${homedir}/ ] ; then
file=`ls -ldgT ${homedir}`
awk '$1 != $4 && $4 != "root" \
{ print "user " $1 " home directory is owned by " $4 }
{ print "user " $1 " home directory is group writeable" }
{ print "user " $1 " home directory is other writeable" }' > $OUTPUT
printf "\nChecking home directories.\n"
# Files that should not be owned by someone else or readable.
awk -F: '{ print $1 " " $6 }' /etc
/passwd | \
while read uid homedir
; do
printf "$uid $f `ls -ldgT $file`\n"
awk '$1 != $5 && $5 != "root" \
{ print "user " $1 " " $2 " file is owned by " $5 }
{ print "user " $1 " " $2 " file is group readable" }
{ print "user " $1 " " $2 " file is other readable" }
{ print "user " $1 " " $2 " file is group writeable" }
{ print "user " $1 " " $2 " file is other writeable" }' > $OUTPUT
# Files that should not be owned by someone else or writeable.
list
=".bashrc .cshrc .emacsrc .exrc .forward .klogin .login .logout \
awk -F: '{ print $1 " " $6 }' /etc
/passwd | \
while read uid homedir
; do
printf "$uid $f `ls -ldgT $file`\n"
awk '$1 != $5 && $5 != "root" \
{ print "user " $1 " " $2 " file is owned by " $5 }
{ print "user " $1 " " $2 " file is group writeable" }
{ print "user " $1 " " $2 " file is other writeable" }' >> $OUTPUT
printf "\nChecking dot files.\n"
# Mailboxes should be owned by user and unreadable.
ls -l /var
/mail |
sed 1d | \
{ print "user " $9 " mailbox is owned by " $3 }
{ print "user " $9 " mailbox is " $1 ", group " $4 }' > $OUTPUT
printf "\nChecking mailbox ownership.\n"
# File systems should not be globally exported.
for (i = 2; i <= NF; ++i) {
print "File system " $1 " globally exported, read-only."
print "File system " $1 " globally exported, read-write."
}' < /etc
/exports
> $OUTPUT
printf "\nChecking for globally exported file systems.\n"
# Display any changes in setuid files and devices.
printf "\nChecking setuid files and devices:\n"
(find / ! -fstype local -a -prune -o \
\
( -perm -u+s
-o -perm -g+s
-o ! -type d
-a ! -type f
-a ! -type l
-a \
sort |
sed -e 's/^/ls -ldgT /' | sh
> $LIST) 2> $OUTPUT
# Display any errors that occurred during system file walk.
printf "Setuid/device find errors:\n"
# Display any changes in the setuid file list.
egrep -v '^[bc]' $LIST > $TMP1
# Check to make sure uudecode isn't setuid.
if grep -w uudecode $TMP1 > /dev
/null
; then
printf "\nUudecode is setuid.\n"
CUR
=/var
/backups
/setuid.current
BACK
=/var
/backups
/setuid.backup
if cmp -s $CUR $TMP1 ; then
join -110 -210 -v2 $CUR $TMP1 > $OUTPUT
printf "Setuid additions:\n"
join -110 -210 -v1 $CUR $TMP1 > $OUTPUT
printf "Setuid deletions:\n"
sort +9 $TMP2 $CUR $TMP1 | \
sed -e 's/[ ][ ]*/ /g' |
uniq -u > $OUTPUT
printf "Setuid changes:\n"
printf "Setuid additions:\n"
# Check for block and character disk devices that are readable or writeable
# or not owned by root.operator.
DISKLIST
="dk fd hd hk hp jb kra ra rb rd rl rx rz sd up wd"
egrep "^b.*/${i}[0-9][0-9]*[a-h]$" $LIST >> $TMP1
egrep "^c.*/r${i}[0-9][0-9]*[a-h]$" $LIST >> $TMP1
awk '$3 != "root" || $4 != "operator" || $1 !~ /.rw-r-----/ \
{ printf("Disk %s is user %s, group %s, permissions %s.\n", \
$11, $3, $4, $1); }' < $TMP1 > $OUTPUT
printf "\nChecking disk ownership and permissions.\n"
# Display any changes in the device file list.
egrep '^[bc]' $LIST |
sort +10 > $TMP1
CUR
=/var
/backups
/device.current
BACK
=/var
/backups
/device.backup
if cmp -s $CUR $TMP1 ; then
join -111 -211 -v2 $CUR $TMP1 > $OUTPUT
printf "Device additions:\n"
join -111 -211 -v1 $CUR $TMP1 > $OUTPUT
printf "Device deletions:\n"
# Report any block device change. Ignore character
# devices, only the name is significant.
sed -e 's/[ ][ ]*/ /g' | \
printf "Block device changes:\n"
printf "Device additions:\n"
# Create the mtree tree specifications using:
# mtree -cx -pDIR -kcksum,gid,mode,nlink,size,link,time,uid > DIR.secure
# chown root.wheel DIR.SECURE
# Note, this is not complete protection against Trojan horsed binaries, as
# the hacker can modify the tree specification to match the replaced binary.
# For details on really protecting yourself against modified binaries, see
# the mtree(8) manual page.
mtree
-e -p / -f /etc
/mtree
/special
> $OUTPUT
printf "\nChecking special files and directories.\n"
tree
=`sed -n -e '3s/.* //p' -e 3q $file`
mtree
-f $file -p $tree > $TMP1
printf "\nChecking $tree:\n" >> $OUTPUT
printf "\nChecking system binaries:\n"
# List of files that get backed up and checked for any modifications. Each
# file is expected to have two backups, /var/backups/file.{current,backup}.
# Any changes cause the files to rotate.
if [ -s /etc
/changelist
] ; then
for file in `cat /etc/changelist`; do
CUR
=/var
/backups
/`basename $file`.current
BACK
=/var
/backups
/`basename $file`.backup
diff $CUR $file > $OUTPUT
printf "\n======\n%s diffs (OLD < > NEW)\n======\n" $file
chown root.wheel
$CUR $BACK