Restricted shell

From Wikipedia, the free encyclopedia
Jump to navigation Jump to search

Script error: No such module "Unsubst". The restricted shell is a Unix shell that restricts some of the capabilities available to an interactive user session, or to a shell script, running within it. It is intended to provide an additional layer of security, but is insufficient to allow execution of entirely untrusted software. A restricted mode operation is found in the original Bourne shell[1] and its later counterpart Bash,[2] and in the KornShell.[3] In some cases a restricted shell is used in conjunction with a chroot jail, in a further attempt to limit access to the system as a whole.

Invocation

The restricted mode of the Bourne shell <templatestyles src="Mono/styles.css" />sh, and its POSIX workalikes, is used when the interpreter is invoked in one of the following ways:

  • <templatestyles src="Kbd/styles.css"></templatestyles>sh -r    note that this conflicts with the "read" option in some <templatestyles src="Mono/styles.css" />sh variants
  • <templatestyles src="Kbd/styles.css"></templatestyles>rsh    note that this may conflict with the remote shell command, which is also called <templatestyles src="Mono/styles.css" />rsh on some systems

The restricted mode of Bash is used when Bash is invoked in one of the following ways:

  • <templatestyles src="Kbd/styles.css"></templatestyles>rbash
  • <templatestyles src="Kbd/styles.css"></templatestyles>bash -r
  • <templatestyles src="Kbd/styles.css"></templatestyles>bash --restricted

Similarly KornShell's restricted mode is produced by invoking it thus:

  • <templatestyles src="Kbd/styles.css"></templatestyles>rksh
  • <templatestyles src="Kbd/styles.css"></templatestyles>ksh -r

Setting up rbash

For some systems (e.g., CentOS), the invocation through <templatestyles src="Mono/styles.css" />rbash is not enabled by default, and the user obtains a Template:Samp error if invoked directly, or a login failure if the /etc/passwd file indicates <templatestyles src="Mono/styles.css" />/bin/rbash as the user's shell.

It suffices to create a link named <templatestyles src="Mono/styles.css" />rbash pointing directly to <templatestyles src="Mono/styles.css" />bash. Though this invokes Bash directly, without the <templatestyles src="Kbd/styles.css"></templatestyles>-r or <templatestyles src="Kbd/styles.css"></templatestyles>--restricted options, Bash does recognize that it was invoked through <templatestyles src="Mono/styles.css" />rbash and it does come up as a restricted shell.

This can be accomplished with the following simple commands (executed as root, either logged in as user root, or using sudo):

root@host:~# cd /bin
root@host:/bin# ln bash rbash

Limited operations

The following operations are not permitted in a restricted shell:

  • changing directory
  • specifying absolute pathnames or names containing a slash
  • setting the PATH or SHELL variable
  • redirection of output

Bash adds further restrictions, including:[2]

  • limitations on function definitions
  • limitations on the use of slash-ed filenames in Bash builtins

Restrictions in the restricted KornShell are much the same as those in the restricted Bourne shell.[4]

Weaknesses of a restricted shell

The restricted shell is not secure. A user can break out of the restricted environment by running a program that features a shell function. The following is an example of the shell function in vi being used to escape from the restricted shell:

user@host:~$ vi
:set shell=/bin/sh
:shell

Or by simply starting a new unrestricted shell, if it is in the <templatestyles src="Mono/styles.css" />PATH, as demonstrated here:

user@host:~$ rbash
user@host:~$ cd /
rbash: cd: restricted
user@host:~$ bash
user@host:~$ cd /
user@host:/$

List of programs

Beyond the restricted modes of usual shells, specialized restricted shell programs include:

See also

References

<templatestyles src="Reflist/styles.css" />

  1. Script error: No such module "citation/CS1".
  2. a b GNU Bash manual
  3. ksh manual, Solaris (SunOS 5.10) manual page, Oracle Inc.
  4. ksh(1) manual page, IBM AIX documentation set
  5. Script error: No such module "citation/CS1".

Script error: No such module "Check for unknown parameters".