* Cannot Set Owner & User-ID bit to Root via script
@ 1996-08-15 4:00 John G. Bury
1996-08-15 4:00 ` Phil Farrell
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: John G. Bury @ 1996-08-15 4:00 UTC (permalink / raw)
Cc: jbury
I'm sure this is an age old problem with a simple solution, but I can't
figure it out...I have a need to provide several users with a way to
change the ownership of their executables to root:system and to set the
user-id bit on the executables.
I'm having problems with a Korn shell script I originally wrote on a
Sun Solaris box and ported to Digital UNIX v3.2. Yes, the script does
work on Sun Solaris with path changes to the execuables chmod and chown,
but the script will not work on Digital UNIX. The script itself is
owned by root:system with the user-id bit set, and does the following:
-rwsr-xr-x 1 root system script_name
1) Checks the usage/syntax
Usage: script_name <filename1> <filename2> ...
2) Checks if the user running the script has permissions to use it
via a list of authorized users.
3) Changes the owner and permissions on the files passed to the
script to owner root, group system, and sets the user-id bit.
/sbin/chmod 4755 filename1 filename2...
/sbin/chown root:system filename1 filename2...
When I excute this script as an authorized user, I receive the
following error from the /sbin/chown command:
$ script_name filename1
Changing ownership and permission on filename1...
chown: filename1: Not owner
done
$
filename1 before executing the script:
-rwxr-xr-x 1 name1 users filename1
filename1 after executing the script:
-rwsr-xr-x 1 name1 users filename1
For some reason (I am at a loss), the script will not change the owner
of the file (file1) to root, but it will set the user-id bit. I have
provided the source for trouble shooting or anyone to use... If you
have any ideas why this is occurring, PLEASE FEEL FREE TO ENLIGHTEN ME!
ALSO, IF ANYONE HAS ANOTHER WAY OF DOING THIS PLEASE LET ME KNOW!!!
THANKS FOR YOUR TIME AND KNOWLEDGE...
#!/bin/ksh
#
########################################################################
#
# This script allows the AUTHORIZED_USER to change the owner of files
# to root:system and sets the user-id bit on the files.
#
########################################################################
#
set_sticky () {
for FILES in "$@"
do
echo "Changing ownership and permission on ${FILES} ..."
/sbin/chmod 4755 ${FILES}
/sbin/chown root:system ${FILES}
done
}
#
# Variable Definitions
#
set -A LIST_OF_AUTHORIZED_USERS name1 name2 # Load array of Auth-Users
DEBUG=0 # Debug flag; 0-off 1-on
#
# First check the usage of the command
#
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <filename1> <filename2> ..."
exit
fi
#
# Next ensure that no one can execute this program except the AUTHORIZED
# _USERS
#
PARENT=`ps -af | awk '{ if ($2 == PID) print $3 }' PID=$$`
if [[ ${DEBUG} -eq 1 ]]; then
echo "The PARENT process id is ${PARENT}"
fi
USER_NAME=`ps -af | awk '{ if ($3 == PPID) print $1 }' PPID=${PARENT}`
if [[ ${DEBUG} -eq 1 ]]; then
echo "The users name is ${USER_NAME}"
fi
#
# The USAGE and AUTHORIZED_USER tests passed - Change the permissions
#
for AUTHORIZED_USER in "${LIST_OF_AUTHORIZED_USERS[@]}"
do
if [[ ${USER_NAME} = ${AUTHORIZED_USER} ]]; then
set_sticky $*
echo "done"
exit
fi
done
#
echo "Sorry - Unauthorized User. Permission Denied..."
--
* John G. Bury *
* Globalstar Satellite Operations Control Center *
* Lockheed Martin Corporation Voice: (301) 805-0580 *
* 7375 Executive Place FAX: (301) 805-0371 *
* Seabrook, MD 20706 E-Mail: jbury@DS01.sms.lmco.com *
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cannot Set Owner & User-ID bit to Root via script
1996-08-15 4:00 Cannot Set Owner & User-ID bit to Root via script John G. Bury
@ 1996-08-15 4:00 ` Phil Farrell
1996-08-16 4:00 ` Brian S Hiles
1996-08-16 4:00 ` Casper H.S. Dik - Network Security Engineer
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Phil Farrell @ 1996-08-15 4:00 UTC (permalink / raw)
To: John G. Bury
Setuid shell scripts are inherently insecure and are a convenient
way for hackers to get root access. Because of this, I do believe
that there is some kernel parameter in Digital UNIX that prevents
shell scripts from running setuid, and that this parameter is
turned on by default.
You should try to rewrite your script in C or some other compiled
language which can more safely be made into a setuid program.
--
Phil Farrell, Computer Systems Manager
Stanford University School of Earth Sciences
farrell@pangea.stanford.edu
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cannot Set Owner & User-ID bit to Root via script
1996-08-16 4:00 ` Brian S Hiles
@ 1996-08-16 4:00 ` Christopher M. Conway
0 siblings, 0 replies; 7+ messages in thread
From: Christopher M. Conway @ 1996-08-16 4:00 UTC (permalink / raw)
Probably to best solution would be to get sudo and get that
running. You can configure it to allow certain users to do certain
commands. It's a lot more general, and a lot safer than using your
script.
Check cs.colorado.edu. That's where the bug list is, at least.
I don't remember for sure where it's officially homed, but that would
be a good place to start.
--
Christopher M. Conway Systems and Network Administrator
wombat@aquilagroup.com Don't Tread on Me
We must all hang together, or, most assuredly, we will all hang separately.
I'll be post-feminist in the post-patriarchy.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cannot Set Owner & User-ID bit to Root via script
1996-08-15 4:00 ` Phil Farrell
@ 1996-08-16 4:00 ` Brian S Hiles
1996-08-16 4:00 ` Christopher M. Conway
0 siblings, 1 reply; 7+ messages in thread
From: Brian S Hiles @ 1996-08-16 4:00 UTC (permalink / raw)
Phil Farrell (farrell@pangea.stanford.edu) wrote:
: Setuid shell scripts are inherently insecure and are a convenient
: way for hackers to get root access. Because of this, I do believe
: that there is some kernel parameter in Digital UNIX that prevents
: shell scripts from running setuid, and that this parameter is
: turned on by default.
: You should try to rewrite your script in C or some other compiled
: language which can more safely be made into a setuid program.
I have to guess at the query because the previous responder deleted it.
(Don't do that!)
You have a few options:
I. Turn the shell program into a binary with the "shc" program which
I have mentioned in a previous thread.
II. Use the "-p" option in ksh, with or without the "set_uid" front-end
that comes with the ksh93 distribution archive at:
http://www.research.att.com/orgs/ssr/book/reuse/ #ksh93
III. Download and compile "indir", a set_uid front-end that is designed
to eliminate the well-known security holes of setuid shell scripts.
ftp ftp.uu.net/archive/comp.sources.unix/volume21/indir
indir Safe way to run setuid shell scripts
ftp ftp.uu.net/archive/comp.sources.unix/volume22/indir.pch
indir.pch Patch -- safely execute (set[ug]id) scripts
-Brian
--
,---. ,---. ,---. ,---. ,---. ,---. ,---.
/ _ \ / _ \ / _ \ / _ \ / _ \ / _ \ / _ \
.' / \ `.' / mailto:bsh20858@challenger.atc.fhda.edu \ `.' / \ `.
__,' `.___,' `.___,' `.___,' `.___,' `.___,' `.___,' `.__
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cannot Set Owner & User-ID bit to Root via script
1996-08-15 4:00 Cannot Set Owner & User-ID bit to Root via script John G. Bury
1996-08-15 4:00 ` Phil Farrell
@ 1996-08-16 4:00 ` Casper H.S. Dik - Network Security Engineer
1996-08-16 4:00 ` Dave Plonka
1996-09-05 4:00 ` J. Anderson
3 siblings, 0 replies; 7+ messages in thread
From: Casper H.S. Dik - Network Security Engineer @ 1996-08-16 4:00 UTC (permalink / raw)
"John G. Bury" <jbury@sms.lmco.com> writes:
>I'm sure this is an age old problem with a simple solution, but I can't
>figure it out...I have a need to provide several users with a way to
>change the ownership of their executables to root:system and to set the
>user-id bit on the executables.
>I'm having problems with a Korn shell script I originally wrote on a
>Sun Solaris box and ported to Digital UNIX v3.2. Yes, the script does
>work on Sun Solaris with path changes to the execuables chmod and chown,
>but the script will not work on Digital UNIX. The script itself is
>owned by root:system with the user-id bit set, and does the following:
It is possible that Digital Unix doesn't like set-uid scripts and
disabes them by default.
It's a good thing, as set-yuid scripts are hard to get right.
Your script, e.g., can easily be exploited by chagning $PATH.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Unsolicited e-mail advertisements send to my address will be proofread
for a $250 flat fee.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cannot Set Owner & User-ID bit to Root via script
1996-08-15 4:00 Cannot Set Owner & User-ID bit to Root via script John G. Bury
1996-08-15 4:00 ` Phil Farrell
1996-08-16 4:00 ` Casper H.S. Dik - Network Security Engineer
@ 1996-08-16 4:00 ` Dave Plonka
1996-09-05 4:00 ` J. Anderson
3 siblings, 0 replies; 7+ messages in thread
From: Dave Plonka @ 1996-08-16 4:00 UTC (permalink / raw)
John G. Bury (jbury@sms.lmco.com) wrote:
> I'm sure this is an age old problem with a simple solution, but I can't
> figure it out...I have a need to provide several users with a way to
> change the ownership of their executables to root:system and to set the
> user-id bit on the executables.
First, an observation:
If you give anyone the ability to turn on set-uid root on something that
they authored, you are essentially giving them complete root privileges.
The reason this is the case is that something that is running effectively
as root, can set its real user id to root and can run any executable and
alter any file. If this is your intent, just give them a root account,
and let them do the chown(1), chgrp(1), chmod(1) themself.
> I'm having problems with a Korn shell script I originally wrote on a
> Sun Solaris box and ported to Digital UNIX v3.2. Yes, the script does
> work on Sun Solaris with path changes to the execuables chmod and chown,
> but the script will not work on Digital UNIX.
The issue is that chown(1) works differently under Digital Unix...
From the man page for chown(2) (this is the system call on which the
chown(1) command is based):
DESCRIPTION
A process can change the value of the owner ID of a file only if the pro-
cess has superuser privilege.
It doesn't want non-root users to be able to obtain root privilege by
capitalizing on your compromising system security by leaving such a
set-uid root executable laying around.
> For some reason (I am at a loss), the script will not change the owner
> of the file (file1) to root, but it will set the user-id bit. I have
> provided the source for trouble shooting or anyone to use... If you
> have any ideas why this is occurring, PLEASE FEEL FREE TO ENLIGHTEN ME!
Systems such as this don't allow you to "give away" files... ie. change the
owner to someone else. Since chmod "knows" that you're really not root
(only your effective id is root), it seems not to allow you to change the
owner to someone else.
> ALSO, IF ANYONE HAS ANOTHER WAY OF DOING THIS PLEASE LET ME KNOW!!!
You could get around the problem by setting your real user-id to root
(using setuid(2))... of course you can't do that in ksh, but you could
in C or perl. (I won't elaborate because it's the wrong thing to do...
people will be able to "steal" root on your machine if you implement
the script as you described.)
> set_sticky () {
BTW, "set_sticky" is a misnomer. The sticky bit (a.k.a. save-text-bit)
is not what you're turning on here. That high order octal digit (as
an argument to chmod) works like this:
421
^^^
||saved-text
|set-gid
set-uid
So, "chmod 4755" doesn't set the "sticky" bit, nor do you want to.
Dave
--
Dave.Plonka@mfa.com http://www.cc.edu/~plonka ARS:N9HZF Waukesha, WI
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Cannot Set Owner & User-ID bit to Root via script
1996-08-15 4:00 Cannot Set Owner & User-ID bit to Root via script John G. Bury
` (2 preceding siblings ...)
1996-08-16 4:00 ` Dave Plonka
@ 1996-09-05 4:00 ` J. Anderson
3 siblings, 0 replies; 7+ messages in thread
From: J. Anderson @ 1996-09-05 4:00 UTC (permalink / raw)
John G. Bury (jbury@sms.lmco.com) wrote:
: ... the script will not work on Digital UNIX. The script itself is
: owned by root:system with the user-id bit set, and does the following:
: -rwsr-xr-x 1 root system script_name
There's your problem. DEC Unix is _so_ clever, that it won't allow
us to do a setuid on a shell script. You have 2 options:
1) write it in C.
2) install sudo.
I highly recommend installing sudo--it does exactly what we need, and
has much better security than the old setuid bit does.
Hope this helps!
Jeremy Anderson
janderson@globalmt.com
patowic@jurai.net
http://www.jurai.net/~patowic
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1996-09-05 4:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-08-15 4:00 Cannot Set Owner & User-ID bit to Root via script John G. Bury
1996-08-15 4:00 ` Phil Farrell
1996-08-16 4:00 ` Brian S Hiles
1996-08-16 4:00 ` Christopher M. Conway
1996-08-16 4:00 ` Casper H.S. Dik - Network Security Engineer
1996-08-16 4:00 ` Dave Plonka
1996-09-05 4:00 ` J. Anderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox