ksh93 and Privileged Mode
The Korn shell's privileged mode was
designed to protect against setuid shell scripts. This is a set -o
option (set -o privileged or set -p), but the shell enters it automatically
whenever it executes a script whose setuid bit is set; i.e., when the
effective user ID is different from the real user ID.
In privileged mode, when a setuid Korn shell script is
invoked, the shell runs the file /etc/suid_profile. This file should be written
to restrict setuid shell scripts in much the same way as the restricted
shell does. At a minimum, it should make PATH read-only (typeset -r PATH or readonly PATH) and set it to one or more
"safe" directories. Once again, this prevents any decoys from being
invoked.
Since privileged mode is an option, it is possible to turn it off
with the command set +o privileged (or set
+p). However, this doesn't help the potential system cracker:
the shell automatically changes its effective user ID to be the same as
the real user ID—i.e., if you turn off privileged mode, you also turn
off setuid.
In addition to privileged mode, ksh provides a special "agent" program,
/etc/suid_exec, that runs setuid
shell scripts (or shell scripts that are executable but not
readable).
For this to work, the script should not start
with #! /bin/ksh. When the program is
invoked, ksh attempts to run the program as a regular binary executable. When the operating system fails to run the script (because it isn't binary, and because it doesn't have the name of an ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access