No -e allowed in setuid scripts 
Author Message
 No -e allowed in setuid scripts

Hello,

   The following code fragment extracts a user's group id and verifies
whether the user belongs to an authorized group to run the program.

-----------------------------------------------------------
($UserName)  = getpwuid($<);

$Counter = 0;
$Is_Authorized = 0;
while ($Array_Of_GroupIDs[$Counter] ne "") {
        if ($Array_Of_GroupIDs[$Counter] eq "55") {
                $Is_Authorized = 1;
        }
        $Counter++;

Quote:
}

if ($Is_Authorized == 0) {
        print ("You are not authorized to run this program.\n");
        print ("This incident will be reported!\n");
Quote:
}

-----------------------------------------------------------

Now when I compile the above (using "perlcc"), i get the following:

-----------------------------------------------------------
% perlcc usergroup.p

--------------------------------------------------------------------------------
Compiling usergroup.p:
--------------------------------------------------------------------------------
Making C(usergroup.p.c) for usergroup.p!
/usr/bin/perl -I/opt/local/lib/perl5/5.00502/sun4-solaris-thread
-I/opt/local/lib/perl5/5.00502
-I/opt/local/lib/perl5/site_perl/5.005/sun4-solaris-thread
-I/opt/local/lib/perl5/site_perl/5.005 -I. -MO=CC,-ousergroup.p.c usergroup.p
usergroup.p syntax OK
Compiling C(usergroup) for usergroup.p!
/usr/bin/perl -I/opt/local/lib/perl5/5.00502/sun4-solaris-thread
-I/opt/local/lib/perl5/5.00502
-I/opt/local/lib/perl5/site_perl/5.005/sun4-solaris-thread
-I/opt/local/lib/perl5/site_perl/5.005 -I. /tmp/usergroup.p.tst
cc -D_REENTRANT -I/opt/local/include -I/opt/gnu/include -O
-I/opt/local/lib/perl5/5.00502/sun4-solaris-thread/CORE
/opt/local/lib/perl5/5.00502/sun4-solaris-thread/auto/Fcntl/Fcntl.so -o
usergroup usergroup.p.c  -L/opt/local/lib -L/opt/gnu/lib
-L/opt/local/lib/perl5/5.00502/sun4-solaris-thread/CORE -lperl -lsocket
-lnsl -ldl -lm -lposix4 -lpthread -lc -lcrypt
%
-----------------------------------------------------------

The compilation seems to have gone fine.  However, when I "chown" the
binary to "root", then "chmod" it to "4755" (or -rwsr-xr-x), and try to
run it I get the following:

-----------------------------------------------------------
% uname -rs
SunOS 5.6

% id
uid=1519(obeidm) gid=55(controls)

% ls -ls ./usergroup
1632 -rwsr-xr-x   1 root     controls  837616 Sep 30 14:46 ./usergroup

% file ./usergroup
./usergroup:    ELF 32-bit MSB executable SPARC Version 1, dynamically
                linked, not stripped

% ./usergroup
No -e allowed in setuid scripts.
-----------------------------------------------------------

But then, I get the following when I run the same binary as root:
-----------------------------------------------------------
# id
uid=0(root) gid=1(other)

# ./usergroup
You are not authorized to run this program.
This incident will be reported!
-----------------------------------------------------------
which is fine since user root does not belong to group "55".

In the first instance, effective user id (euid) of the program had to be
changed to root since the binary is suid root and the user who launched
the binary was not root.  For some reason, that resulted in the
"No -e allowed in setuid scripts" error message.

In the second instance, euid didn't need to change since it was already
set to root.  That resulted in having the program run as designed.
Further tests proved my theory.

Now the question is why is that happening?  the file appears to be a
binary, not a script, as shown by the output of the command "file".
Still, the error message says it's a script :)  Any workarounds or
suggestions to get this puppy going?

Thanks!
-Mustapha



Wed, 18 Jun 1902 08:00:00 GMT  
 No -e allowed in setuid scripts

Quote:
> % ./usergroup
> No -e allowed in setuid scripts.

Looks like a bug. Try running it as a true set-id script (instead of
compiling it) and see what happens.

Of course, if that works, you'll have to ask yourself what you're gaining
by compiling. :-)

Cheers!

--
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. No -e allowed in setuid scripts?

2. no -e allowed in setuid scripts?

3. Setuid shell scripts not allowed

4. Only allow once instance of a script?

5. how to only allow calls to perl or cgi script from certain page

6. setuid *within* Perl script

7. Problem: setuid script calling program that forks (I think :)

8. setuid perl script questions

9. Problem with setuid scripts.

10. Need help with setuid scripts which use usersub.o

11. Help with setuid scripts on SysV UNIX

12. setuid scripts and dynamically loaded libraries

 

 
Powered by phpBB® Forum Software