security.d/chk_rootdotfiles

Wed, 14 Jan 2009 21:12:35 +0100

author
Mercurial Repos
date
Wed, 14 Jan 2009 21:12:35 +0100
changeset 5
fe3130d22800
child 14
59e07bba67cc
permissions
-rw-r--r--

Conversion from CVS

5
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
1 #!/bin/bash
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
2 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
3 # $Id$
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
4 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
5 #############################################################################
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
6 # Copyright (C) 2005
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
7 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
8 # Michiel Broek <mbse@mbse.dds.nl>
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
9 # Beekmansbos 10
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
10 # 1971 BV IJmuiden
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
11 # the Netherlands
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
12 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
13 # This file is part of SlackSecCheckSripts.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
14 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
15 # This package is free software; you can redistribute it and/or modify it
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
16 # under the terms of the GNU General Public License as published by the
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
17 # Free Software Foundation; either version 2, or (at your option) any
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
18 # later version.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
19 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
20 # SlackSecCheckSripts is distributed in the hope that it will be useful, but
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
21 # WITHOUT ANY WARRANTY; without even the implied warranty of
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
23 # General Public License for more details.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
24 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
25 # You should have received a copy of the GNU General Public License
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
26 # along with MBSE BBS; see the file COPYING. If not, write to the Free
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
27 # Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
28 #############################################################################
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
29
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
30
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
31 PATH=/sbin:/usr/sbin:/bin:/usr/bin
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
32
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
33 umask 077
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
34 TZ=UTC; export TZ
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
35 LANG=C; export LANG
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
36
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
37 SECUREDIR=`mktemp -d /tmp/_securedir.XXXXXX` || exit 1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
38
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
39 trap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
40
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
41 if ! cd "$SECUREDIR"; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
42 echo "Can not cd to $SECUREDIR".
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
43 exit 1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
44 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
45
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
46 TMP1=secure1.$$
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
47 OUTPUT=secure2.$$
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
48
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
49
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
50 # Check for root paths, umask values in startup files.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
51 # The check for the root paths is problematical -- it's likely to fail
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
52 # in other environments. Once the shells have been modified to warn
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
53 # of '.' in the path, the path tests should go away.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
54 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
55 rhome=~root
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
56 umaskset=no
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
57
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
58 if [ -x /bin/tcsh ]; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
59 list="/etc/csh.cshrc /etc/csh.login ${rhome}/.cshrc ${rhome}/.login `/bin/ls /etc/profile.d/*.csh`"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
60
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
61 for i in $list ; do
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
62 if [ -f $i ] ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
63 if egrep '^[^#]*(umask)' $i > /dev/null ;
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
64 then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
65 umaskset=yes
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
66 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
67 # Double check the umask value itself; ensure that
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
68 # both the group and other write bits are set.
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
69 #
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
70 egrep '^[^#]*(umask)' $i |
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
71 awk '{
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
72 if ($2 ~ /^.$/ || $2 ~! /[^2367].$/) {
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
73 print "\tRoot umask is group writeable"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
74 }
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
75 if ($2 ~ /[^2367]$/) {
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
76 print "\tRoot umask is other writeable"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
77 }
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
78 }' | sort -u
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
79 SAVE_PATH=$PATH
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
80 unset PATH
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
81 /bin/csh -f -s << end-of-csh > /dev/null 2>&1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
82 source $i
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
83 /bin/ls -ldgT \$path > $TMP1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
84 end-of-csh
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
85 export PATH=$SAVE_PATH
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
86 if [ -f $TMP1 ]; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
87 awk '{
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
88 if ($10 ~ /^\.$/) {
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
89 print "\tThe root path includes .";
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
90 next;
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
91 }
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
92 }
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
93 $1 ~ /^d....w/ \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
94 { print "\tRoot path directory " $10 " is group writeable." } \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
95 $1 ~ /^d.......w/ \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
96 { print "\tRoot path directory " $10 " is other writeable." }' \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
97 < $TMP1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
98 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
99 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
100 done > $OUTPUT
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
101
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
102 if [ $umaskset = "no" -o -s $OUTPUT ] ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
103 printf "\nChecking root csh paths, umask values:\n$list\n\n"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
104 if [ -s $OUTPUT ]; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
105 cat $OUTPUT
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
106 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
107 if [ $umaskset = "no" ] ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
108 printf "\tRoot csh startup files do not set the umask.\n"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
109 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
110 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
111 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
112
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
113 umaskset=no
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
114 list="/etc/profile ${rhome}/.profile `/bin/ls /etc/profile.d/*.sh`"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
115 for i in $list; do
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
116 if [ -f $i ] ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
117 if egrep '^[^#]*(umask)' $i > /dev/null ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
118 umaskset=yes
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
119 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
120 egrep '^[^#]*(umask)' $i |
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
121 awk '$2 ~ /^.$/ || $2 ~ /[^2367].$/ \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
122 { print "\tRoot umask is group writeable" } \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
123 $2 ~ /[^2367]$/ \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
124 { print "\tRoot umask is other writeable" }'
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
125 SAVE_PATH=$PATH
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
126 unset PATH
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
127 /bin/sh << end-of-sh > /dev/null 2>&1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
128 . $i
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
129 list=\`echo \$PATH | /usr/bin/sed -e \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
130 's/^:/.:/;s/:$/:./;s/::/:.:/g;s/:/ /g'\`
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
131 /bin/ls -ldgT \$list > $TMP1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
132 end-of-sh
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
133 export PATH=$SAVE_PATH
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
134 awk '{
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
135 if ($10 ~ /^\.$/) {
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
136 print "\tThe root path includes .";
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
137 next;
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
138 }
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
139 }
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
140 $1 ~ /^d....w/ \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
141 { print "\tRoot path directory " $10 " is group writeable." } \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
142 $1 ~ /^d.......w/ \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
143 { print "\tRoot path directory " $10 " is other writeable." }' \
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
144 < $TMP1
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
145 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
146 done > $OUTPUT
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
147
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
148 if [ $umaskset = "no" -o -s $OUTPUT ] ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
149 printf "\nChecking root sh paths, umask values:\n$list\n"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
150 if [ -s $OUTPUT ]; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
151 cat $OUTPUT
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
152 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
153 if [ $umaskset = "no" ] ; then
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
154 printf "\tRoot sh startup files do not set the umask.\n"
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
155 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
156 fi
fe3130d22800 Conversion from CVS
Mercurial Repos
parents:
diff changeset
157

mercurial