xref: /freebsd/contrib/sendmail/smrsh/README (revision d39bd2c1388b520fcba9abed1932acacead60fba)
1c2aa98e2SPeter Wemm
2c2aa98e2SPeter WemmREADME  smrsh - sendmail restricted shell.
3c2aa98e2SPeter Wemm
4c2aa98e2SPeter WemmThis README file is provided as a courtesy of the CERT Coordination Center,
5c2aa98e2SPeter WemmSoftware Engineering Institute, Carnegie Mellon University.  This file is
6c2aa98e2SPeter Wemmintended as a supplement to the CERT advisory CA-93:16.sendmail.vulnerability,
7c2aa98e2SPeter Wemmand to the software, smrsh.c, written by Eric Allman.
8c2aa98e2SPeter Wemm
9c2aa98e2SPeter Wemm
10c2aa98e2SPeter Wemm
11c2aa98e2SPeter WemmThe smrsh(8) program is intended as a replacement for /bin/sh in the
12c2aa98e2SPeter Wemmprogram mailer definition of sendmail(8).  This README file describes
13c2aa98e2SPeter Wemmthe steps needed to compile and install smrsh.
14c2aa98e2SPeter Wemm
15c2aa98e2SPeter Wemmsmrsh is a restricted shell utility that provides the ability to
16c2aa98e2SPeter Wemmspecify, through a configuration, an explicit list of executable
17c2aa98e2SPeter Wemmprograms.  When used in conjunction with sendmail, smrsh effectively
18c2aa98e2SPeter Wemmlimits sendmail's scope of program execution to only those programs
19c2aa98e2SPeter Wemmspecified in smrsh's configuration.
20c2aa98e2SPeter Wemm
21c2aa98e2SPeter Wemmsmrsh has been written with portability in mind, and uses traditional
22c2aa98e2SPeter WemmUnix library utilities.  As such, smrsh should compile on most
23c2aa98e2SPeter WemmUnix C compilers.
24c2aa98e2SPeter Wemm
2506f25ae9SGregory Neil Shapirosmrsh should build on most systems with the enclosed Build script:
26c2aa98e2SPeter Wemm
27e3793f76SGregory Neil Shapiro	host.domain% sh ./Build
28c2aa98e2SPeter Wemm
2906f25ae9SGregory Neil ShapiroTo compile smrsh.c by hand, use the following command:
30c2aa98e2SPeter Wemm
31c2aa98e2SPeter Wemm	host.domain% cc -o smrsh smrsh.c
32c2aa98e2SPeter Wemm
33c2aa98e2SPeter WemmFor machines that provide dynamic linking, it is advisable to compile
34c2aa98e2SPeter Wemmsmrsh without dynamic linking.  As an example with the Sun Microsystems
35c2aa98e2SPeter Wemmcompiler, you should compile with the -Bstatic option.
36c2aa98e2SPeter Wemm
37c2aa98e2SPeter Wemm	host.domain% cc -Bstatic -o smrsh smrsh.c
3806f25ae9SGregory Neil Shapiro		or
39e3793f76SGregory Neil Shapiro	host.domain% sh ./Build LDOPTS=-Bstatic
4006f25ae9SGregory Neil Shapiro
4106f25ae9SGregory Neil ShapiroWith gcc, the GNU C compiler, use the -static option.
4206f25ae9SGregory Neil Shapiro
4306f25ae9SGregory Neil Shapiro	host.domain% cc -static -o smrsh smrsh.c
4406f25ae9SGregory Neil Shapiro		or
45e3793f76SGregory Neil Shapiro	host.domain% sh ./Build LDOPTS=-static
46c2aa98e2SPeter Wemm
47a7ec597cSGregory Neil ShapiroThe following C defines can be set defined to change the search path and
48a7ec597cSGregory Neil Shapirothe bin directory used by smrsh.
49c2aa98e2SPeter Wemm
50a7ec597cSGregory Neil Shapiro-DSMRSH_PATH=\"path\"	\"/bin:/usr/bin:/usr/ucb\"	The default search
51a7ec597cSGregory Neil Shapiro							path.
52a7ec597cSGregory Neil Shapiro-DSMRSH_CMDDIR=\"dir\"	\"/usr/adm/sm.bin\"		The default smrsh
53a7ec597cSGregory Neil Shapiro							program directory
54a7ec597cSGregory Neil Shapiro
55a7ec597cSGregory Neil ShapiroThese can be added to the devtools/Site/site.config.m4 file using the
56a7ec597cSGregory Neil Shapiroglobal M4 macro confENVDEF or the smrsh specific M4 macro
57a7ec597cSGregory Neil Shapiroconf_smrsh_ENVDEF.
58c2aa98e2SPeter Wemm
5906f25ae9SGregory Neil ShapiroAs root, install smrsh in /usr/libexec.  Using the Build script:
60c2aa98e2SPeter Wemm
61e3793f76SGregory Neil Shapiro	host.domain# sh ./Build install
6206f25ae9SGregory Neil Shapiro
6306f25ae9SGregory Neil ShapiroFor manual installation: install smrsh in the /usr/libexec
6406f25ae9SGregory Neil Shapirodirectory, with mode 511.
6506f25ae9SGregory Neil Shapiro
6606f25ae9SGregory Neil Shapiro	host.domain# mv smrsh /usr/libexec
6706f25ae9SGregory Neil Shapiro	host.domain# chmod 511 /usr/libexec/smrsh
68c2aa98e2SPeter Wemm
69c2aa98e2SPeter Wemm
70c2aa98e2SPeter Wemm
71c2aa98e2SPeter WemmNext, determine the list of commands that smrsh should allow sendmail
72c2aa98e2SPeter Wemmto run.  This list of allowable commands can be determined by:
73c2aa98e2SPeter Wemm
7406f25ae9SGregory Neil Shapiro   1.  examining your /etc/mail/aliases file, to indicate what commands
75c2aa98e2SPeter Wemm       are being used by the system.
76c2aa98e2SPeter Wemm
77c2aa98e2SPeter Wemm   2.  surveying your host's .forward files, to determine what
78c2aa98e2SPeter Wemm       commands users have specified.
79c2aa98e2SPeter Wemm
80c2aa98e2SPeter WemmSee the man page for aliases(5) if you are unfamiliar with the format of
81c2aa98e2SPeter Wemmthese specifications. Additionally, you should include in the list,
82c2aa98e2SPeter Wemmpopular commands such as /usr/ucb/vacation.
83c2aa98e2SPeter Wemm
84c2aa98e2SPeter WemmYou should NOT include interpreter programs such as sh(1), csh(1),
85c2aa98e2SPeter Wemmperl(1), uudecode(1) or the stream editor sed(1) in your list of
86c2aa98e2SPeter Wemmacceptable commands.
87c2aa98e2SPeter Wemm
8840266059SGregory Neil ShapiroIf your platform doesn't have a default SMRSH_CMDDIR setting, you will
89193538b7SGregory Neil Shapironext need to create the directory /usr/adm/sm.bin and populate
90c2aa98e2SPeter Wemmit with the programs that your site feels are allowable for sendmail
91c2aa98e2SPeter Wemmto execute.   This directory is explicitly specified in the source
92c2aa98e2SPeter Wemmcode for smrsh, so changing this directory must be accompanied with
93c2aa98e2SPeter Wemma change in smrsh.c.
94c2aa98e2SPeter Wemm
95c2aa98e2SPeter Wemm
96c2aa98e2SPeter WemmYou will have to be root to make these modifications.
97c2aa98e2SPeter Wemm
98c2aa98e2SPeter WemmAfter creating the /usr/adm/sm.bin directory, either copy the programs
99c2aa98e2SPeter Wemmto the directory, or establish links to the allowable programs from
100c2aa98e2SPeter Wemm/usr/adm/sm.bin.  Change the file permissions, so that these programs
101c2aa98e2SPeter Wemmcan not be modified by non-root users.  If you use links, you should
102c2aa98e2SPeter Wemmensure that the target programs are not modifiable.
103c2aa98e2SPeter Wemm
104c2aa98e2SPeter WemmTo allow the popular vacation(1) program by creating a link in the
105c2aa98e2SPeter Wemm/usr/adm/sm.bin directory, you should:
106c2aa98e2SPeter Wemm
107c2aa98e2SPeter Wemm	host.domain# cd /usr/adm/sm.bin
108c2aa98e2SPeter Wemm	host.domain# ln -s /usr/ucb/vacation vacation
109c2aa98e2SPeter Wemm
110c2aa98e2SPeter Wemm
111c2aa98e2SPeter Wemm
112c2aa98e2SPeter Wemm
113c2aa98e2SPeter WemmAfter populating the /usr/adm/sm.bin directory, you can now configure
114c2aa98e2SPeter Wemmsendmail to use the restricted shell.  Save the current sendmail.cf
115c2aa98e2SPeter Wemmfile prior to modifying it, as a prudent precaution.
116c2aa98e2SPeter Wemm
117c2aa98e2SPeter WemmTypically, the program mailer is defined by a single line in the
118c2aa98e2SPeter Wemmsendmail configuration file, sendmail.cf.  This file is traditionally
119c2aa98e2SPeter Wemmfound in the /etc, /usr/lib or /etc/mail directories, depending on
120c2aa98e2SPeter Wemmthe UNIX vendor.
121c2aa98e2SPeter Wemm
122c2aa98e2SPeter WemmIf you are unsure of the location of the actual sendmail configuration
123c2aa98e2SPeter Wemmfile, a search of the strings(1) output of the sendmail binary, will
124c2aa98e2SPeter Wemmhelp to locate it.
125c2aa98e2SPeter Wemm
126c2aa98e2SPeter WemmIn order to configure sendmail to use smrsh, you must modify the Mprog
127c2aa98e2SPeter Wemmdefinition in the sendmail.cf file, by replacing the /bin/sh specification
12806f25ae9SGregory Neil Shapirowith /usr/libexec/smrsh.
129c2aa98e2SPeter Wemm
130c2aa98e2SPeter WemmAs an example:
131c2aa98e2SPeter Wemm
132c2aa98e2SPeter WemmIn most Sun Microsystems' sendmail.cf files, the line is:
133c2aa98e2SPeter WemmMprog,	P=/bin/sh,   F=lsDFMeuP,  S=10, R=20, A=sh -c $u
134c2aa98e2SPeter Wemm
135c2aa98e2SPeter Wemmwhich should be changed to:
13606f25ae9SGregory Neil ShapiroMprog,	P=/usr/libexec/smrsh,   F=lsDFMeuP,  S=10, R=20, A=sh -c $u
13706f25ae9SGregory Neil Shapiro          ^^^^^^^^^^^^^^^^^^
138c2aa98e2SPeter Wemm
139c2aa98e2SPeter WemmA more generic line may be:
140c2aa98e2SPeter WemmMprog,		P=/bin/sh, F=lsDFM, A=sh -c $u
141c2aa98e2SPeter Wemm
142c2aa98e2SPeter Wemmand should be changed to;
14306f25ae9SGregory Neil ShapiroMprog,		P=/usr/libexec/smrsh, F=lsDFM, A=sh -c $u
144c2aa98e2SPeter Wemm
145c2aa98e2SPeter Wemm
146c2aa98e2SPeter WemmAfter modifying the Mprog definition in the sendmail.cf file, if a frozen
147c2aa98e2SPeter Wemmconfiguration file is being used, it is essential to create a new one.
148c2aa98e2SPeter WemmYou can determine if you need a frozen configuration by discovering
149c2aa98e2SPeter Wemmif a sendmail.fc file currently exists in either the /etc/, /usr/lib,
150c2aa98e2SPeter Wemmor /etc/mail directories.  The specific location can be determined using
151c2aa98e2SPeter Wemma search of the strings(1) output of the sendmail binary.
152c2aa98e2SPeter Wemm
153c2aa98e2SPeter WemmIn order to create a new frozen configuration, if it is required:
154c2aa98e2SPeter Wemm	host.domain# /usr/lib/sendmail -bz
155c2aa98e2SPeter Wemm
156c2aa98e2SPeter WemmNow re-start the sendmail process.  An example of how to do this on
157c2aa98e2SPeter Wemma typical system follows:
158c2aa98e2SPeter Wemm
15906f25ae9SGregory Neil Shapiro	host.domain# cat /var/run/sendmail.pid
16006f25ae9SGregory Neil Shapiro	130
16106f25ae9SGregory Neil Shapiro	/usr/sbin/sendmail -bd -q30m
16206f25ae9SGregory Neil Shapiro	host.domain# /bin/kill -15 130
16306f25ae9SGregory Neil Shapiro	host.domain# /usr/sbin/sendmail -bd -q30m
16406f25ae9SGregory Neil Shapiro
16506f25ae9SGregory Neil Shapiro
166*4313cc83SGregory Neil Shapiro$Revision: 8.10 $, Last updated $Date: 2008-02-12 16:40:06 $
167