Debian Codegraph @

HTML/restricted-sh.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Restricted Shells</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
9 "><LINK
10 REL="HOME"
11 TITLE="Advanced Bash-Scripting Guide"
12 HREF="index.html"><LINK
13 REL="UP"
14 TITLE="Advanced Topics"
15 HREF="part5.html"><LINK
16 REL="PREVIOUS"
17 TITLE="Subshells"
18 HREF="subshells.html"><LINK
19 REL="NEXT"
20 TITLE="Process Substitution"
21 HREF="process-sub.html"><META
22 HTTP-EQUIV="Content-Style-Type"
23 CONTENT="text/css"><LINK
24 REL="stylesheet"
25 HREF="common/kde-common.css"
26 TYPE="text/css"><META
27 HTTP-EQUIV="Content-Type"
28 CONTENT="text/html; charset=iso-8859-1"><META
29 HTTP-EQUIV="Content-Language"
30 CONTENT="en"><LINK
31 REL="stylesheet"
32 HREF="common/kde-localised.css"
33 TYPE="text/css"
34 TITLE="KDE-English"><LINK
35 REL="stylesheet"
36 HREF="common/kde-default.css"
37 TYPE="text/css"
38 TITLE="KDE-Default"></HEAD
39 ><BODY
40 CLASS="CHAPTER"
41 BGCOLOR="#FFFFFF"
42 TEXT="#000000"
43 LINK="#AA0000"
44 VLINK="#AA0055"
45 ALINK="#AA0000"
46 STYLE="font-family: sans-serif;"
47 ><DIV
48 CLASS="NAVHEADER"
49 ><TABLE
50 SUMMARY="Header navigation table"
51 WIDTH="100%"
52 BORDER="0"
53 CELLPADDING="0"
54 CELLSPACING="0"
55 ><TR
56 ><TH
57 COLSPAN="3"
58 ALIGN="center"
59 >Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
60 ></TR
61 ><TR
62 ><TD
63 WIDTH="10%"
64 ALIGN="left"
65 VALIGN="bottom"
66 ><A
67 HREF="subshells.html"
68 ACCESSKEY="P"
69 >Prev</A
70 ></TD
71 ><TD
72 WIDTH="80%"
73 ALIGN="center"
74 VALIGN="bottom"
75 ></TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="bottom"
80 ><A
81 HREF="process-sub.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="CHAPTER"
92 ><H1
93 ><A
94 NAME="RESTRICTED-SH"
95 ></A
96 >Chapter 22. Restricted Shells</H1
97 ><P
98 ><A
99 NAME="RESTRICTEDSHREF"
100 ></A
101 ></P
102 ><DIV
103 CLASS="VARIABLELIST"
104 ><P
105 ><B
106 ><A
107 NAME="DISABLEDCOMMREF"
108 ></A
109 >Disabled commands in restricted
110 shells</B
111 ></P
112 ><DL
113 ><DT
114 ></DT
115 ><DD
116 ><DIV
117 CLASS="FORMALPARA"
118 ><P
119 ><B
120 > . </B
121 >Running a script or portion of a script in
122 <I
123 CLASS="FIRSTTERM"
124 >restricted mode</I
125 > disables certain commands
126 that would otherwise be available. This is a security measure
127 intended to limit the privileges of the script user and to
128 minimize possible damage from running the script.</P
129 ></DIV
130 ></DD
131 ></DL
132 ></DIV
133 ><P
134 >The following commands and actions are disabled:</P
135 ><UL
136 ><LI
137 ><P
138 >Using <TT
139 CLASS="REPLACEABLE"
140 ><I
141 >cd</I
142 ></TT
143 > to change the working
144 directory.</P
145 ></LI
146 ><LI
147 ><P
148 >Changing the values of the
149 <TT
150 CLASS="REPLACEABLE"
151 ><I
152 >$PATH</I
153 ></TT
154 >,
155 <TT
156 CLASS="REPLACEABLE"
157 ><I
158 >$SHELL</I
159 ></TT
160 >,
161 <TT
162 CLASS="REPLACEABLE"
163 ><I
164 >$BASH_ENV</I
165 ></TT
166 >,
167 or <TT
168 CLASS="REPLACEABLE"
169 ><I
170 >$ENV</I
171 ></TT
172 > <A
173 HREF="othertypesv.html#ENVREF"
174 >environmental variables</A
175 >.</P
176 ></LI
177 ><LI
178 ><P
179 >Reading or changing the <TT
180 CLASS="REPLACEABLE"
181 ><I
182 >$SHELLOPTS</I
183 ></TT
184 >,
185 shell environmental options.</P
186 ></LI
187 ><LI
188 ><P
189 >Output redirection.</P
190 ></LI
191 ><LI
192 ><P
193 >Invoking commands containing one or more
194 <SPAN
195 CLASS="TOKEN"
196 >/</SPAN
197 >'s.</P
198 ></LI
199 ><LI
200 ><P
201 >Invoking <A
202 HREF="internal.html#EXECREF"
203 >exec</A
204 > to substitute
205 a different process for the shell.</P
206 ></LI
207 ><LI
208 ><P
209 >Various other commands that would enable monkeying
210 with or attempting to subvert the script for an unintended
211 purpose.</P
212 ></LI
213 ><LI
214 ><P
215 >Getting out of restricted mode within the script.</P
216 ></LI
217 ></UL
218 ><DIV
219 CLASS="EXAMPLE"
220 ><HR><A
221 NAME="RESTRICTED"
222 ></A
223 ><P
224 ><B
225 >Example 22-1. Running a script in restricted mode</B
226 ></P
227 ><TABLE
228 BORDER="0"
229 BGCOLOR="#E0E0E0"
230 WIDTH="100%"
231 ><TR
232 ><TD
233 ><PRE
234 CLASS="PROGRAMLISTING"
235 > 1&nbsp;#!/bin/bash
236 2&nbsp;
237 3&nbsp;# Starting the script with "#!/bin/bash -r"
238 4&nbsp;#+ runs entire script in restricted mode.
239 5&nbsp;
240 6&nbsp;echo
241 7&nbsp;
242 8&nbsp;echo "Changing directory."
243 9&nbsp;cd /usr/local
244 10&nbsp;echo "Now in `pwd`"
245 11&nbsp;echo "Coming back home."
246 12&nbsp;cd
247 13&nbsp;echo "Now in `pwd`"
248 14&nbsp;echo
249 15&nbsp;
250 16&nbsp;# Everything up to here in normal, unrestricted mode.
251 17&nbsp;
252 18&nbsp;set -r
253 19&nbsp;# set --restricted has same effect.
254 20&nbsp;echo "==&#62; Now in restricted mode. &#60;=="
255 21&nbsp;
256 22&nbsp;echo
257 23&nbsp;echo
258 24&nbsp;
259 25&nbsp;echo "Attempting directory change in restricted mode."
260 26&nbsp;cd ..
261 27&nbsp;echo "Still in `pwd`"
262 28&nbsp;
263 29&nbsp;echo
264 30&nbsp;echo
265 31&nbsp;
266 32&nbsp;echo "\$SHELL = $SHELL"
267 33&nbsp;echo "Attempting to change shell in restricted mode."
268 34&nbsp;SHELL="/bin/ash"
269 35&nbsp;echo
270 36&nbsp;echo "\$SHELL= $SHELL"
271 37&nbsp;
272 38&nbsp;echo
273 39&nbsp;echo
274 40&nbsp;
275 41&nbsp;echo "Attempting to redirect output in restricted mode."
276 42&nbsp;ls -l /usr/bin &#62; bin.files
277 43&nbsp;ls -l bin.files # Try to list attempted file creation effort.
278 44&nbsp;
279 45&nbsp;echo
280 46&nbsp;
281 47&nbsp;exit 0</PRE
282 ></TD
283 ></TR
284 ></TABLE
285 ><HR></DIV
286 ></DIV
287 ><DIV
288 CLASS="NAVFOOTER"
289 ><HR
290 ALIGN="LEFT"
291 WIDTH="100%"><TABLE
292 SUMMARY="Footer navigation table"
293 WIDTH="100%"
294 BORDER="0"
295 CELLPADDING="0"
296 CELLSPACING="0"
297 ><TR
298 ><TD
299 WIDTH="33%"
300 ALIGN="left"
301 VALIGN="top"
302 ><A
303 HREF="subshells.html"
304 ACCESSKEY="P"
305 >Prev</A
306 ></TD
307 ><TD
308 WIDTH="34%"
309 ALIGN="center"
310 VALIGN="top"
311 ><A
312 HREF="index.html"
313 ACCESSKEY="H"
314 >Home</A
315 ></TD
316 ><TD
317 WIDTH="33%"
318 ALIGN="right"
319 VALIGN="top"
320 ><A
321 HREF="process-sub.html"
322 ACCESSKEY="N"
323 >Next</A
324 ></TD
325 ></TR
326 ><TR
327 ><TD
328 WIDTH="33%"
329 ALIGN="left"
330 VALIGN="top"
331 >Subshells</TD
332 ><TD
333 WIDTH="34%"
334 ALIGN="center"
335 VALIGN="top"
336 ><A
337 HREF="part5.html"
338 ACCESSKEY="U"
339 >Up</A
340 ></TD
341 ><TD
342 WIDTH="33%"
343 ALIGN="right"
344 VALIGN="top"
345 >Process Substitution</TD
346 ></TR
347 ></TABLE
348 ></DIV
349 ></BODY
350 ></HTML
351 >