22.5 PermissionsOne technique that attackers use to gain root privilege is to first become a semiprivileged user like bin or sys . Such semiprivileged users often own the directories in which root -owned files live. By way of example, consider the following:
drwxr-sr-x 11 bin 2560 Sep 22 18:18 /etc -rw-r-r- 1 root 8199 Aug 25 07:54 /etc/sendmail.cf Here, the /etc/sendmail.cf configuration file is correctly writable only by root . But the directory in which that file lives is owned by bin and writable by bin . Having write permission on that directory means that bin can rename and create files. An individual who gains bin permission on this machine can create a bogus sendmail.cf file by issuing only two simple commands:
%
The original
sendmail.cf
is renamed
drwxr-sr-x 11 bin 2560 Sep 22 18:18 /etc -rw-r-r- 1 bin 4032 Nov 16 00:32 /etc/sendmail.cf UNIX pays less attention to semiprivileged users than it does root . The user root , for example, is mapped to nobody over NFS, whereas the user bin remains bin . Consequently, the following rules must be observed to prevent malicious access to root -owned files:
22.5.1 Dangerous Write PermissionsThe sendmail program, of necessity, needs to trust its configuration file. To aid in the detection of risks, it checks the permissions of its configuration file when first reading that file. If the file is writable by group or world, sendmail logs the following message: [13]
configfile : WARNING: dangerous write permissions If sendmail is being started as a daemon or is being used to initialize the aliases database, it will print the same message to its standard error output. 22.5.2 Permissions for :include:
The
sendmail
program doesn't always run as
root
. When delivering
mail, it often changes its identity into that of a nonprivileged
user. When delivering to a
newprogs: :include:/usr/local/lists/proglist
Here, notification of new programs are mailed to the alias
-rw-rw-r- 2 bin prog 704 Sep 21 14:46 /usr/local/lists/proglist Because this file is owned by bin , sendmail changes its identity to bin when delivering to the list of recipients. Unfortunately, the file is also writable by the group prog . Anyone in the group prog can add a recipient to that list, including one of the form
|/tmp/x.sh This tells sendmail to deliver a copy of the message by running the program (a shell script) /tmp/x.sh . The sendmail program (which is still running as bin ) executes that program as bin . Further, suppose the program /tmp/x.sh contains the following:
#!/bin/sh cp /bin/sh /tmp/sh chmod u+s /tmp/sh cat - > /dev/null exit 0
This causes
bin
first to make a copy of the Bourne shell in
/tmp
(a copy that will be owned by
bin
), then to
set the
suid
bit on that copy (the
-rwsr-xr-x 1 bin 64668 Sep 22 07:38 /tmp/sh The script then throws away the incoming mail message and exits with a zero value to keep sendmail unsuspecting. Through this process, an ordinary user in the group prog has created an suid shell that allows anyone to become the semiprivileged user bin . From the preceding discussion (see Section 22.5, "Permissions" ) you can see the trouble that can cause!
22.5.3 Permissions for ~/.forward Files
The
~/.forward
file can pose a security
risk to individual users. There is
a higher degree of risk if the user is
root
or one of the semiprivileged
users (such as
bin
).
Because the
~/.forward
file is like an individual mailing
list (
drwxr-xr-x 50 george guest 3072 Sep 27 09:19 /home/george/ -rw-rw-r- 1 george guest 62 Sep 17 09:49 /home/george/.forward
Here, the user
\george |"cp /bin/sh /home/george/.x; chmod u+s /home/george/.x"
Now all the attacker has to do is send
Some users, such as the pseudo-user uucp , have home directories that must be world-writable for software to work properly. If that software is not needed (if a machine, for example, doesn't run UUCP software), that home directory should be removed. If the directory must exist and must be world-writable, you should create a protected ~/.forward file there before someone else does. The best protection is to create a nonempty directory called ~/.forward , owned by root , and set its permissions to 000:
#
Even though the
~uucp
directory is world-writable (so anyone
can remove anything from it), no one but
root
can remove
the
~/.forward
directory because it is not empty. The mode
of 000 protects the file
.forward/uucp
from being removed.
The mode of
Note that all critical dot files in a world-writable home directory
must be protected from creation by others. Each of
.forward
,
.rhosts
,
.login
,
.cshrc
,
.profile
, and
.logout
should be a nonempty,
root
-owned directory
with mode 000. World-writable home directories must be owned by
root
instead of by the user, and they must have the
When processing a user's
~/.forward
file,
sendmail
requires that the file be owned by the user or by
root
.
If ownership is correct, it then examines the
~/.forward
file's
permissions. If that file is world-writable,
sendmail
ignores
(and logs) attempts to run programs and to write directly to files.
If the 22.5.4 Recommended PermissionsTable 22.1 shows the recommended ownerships and permissions for all the files and directories in the sendmail system. The path components will vary depending on the vendor version of sendmail you are running. For example, where we show the /usr/lib/sendmail directory, your site may use /usr/etc/sendmail , or even /usr/lib/mail/sendmail .
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|