LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2009, 04:42 AM   #1
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
perl script set uid


I have a script that start the http deamon. This script has got owner and group as root and I have put a setuid on it.

That scripts executes from normal user fine. Now suddenly this script has stopped functioning.

I want to know:

1. The effective uid get propogated to other script called by this script.

2. Is there any way to stop this propogation, If yes how this can be done.

My distro is RHEL.
 
Old 08-11-2009, 08:51 AM   #2
bhaslinux
Member
 
Registered: Oct 2003
Location: UnitedKingdom
Distribution: Debian Bullseye
Posts: 357

Rep: Reputation: 49
AFAIK
Setuid is for binary programs. The #! in the scripts just tell the shell what program to use to run this script.
Now since you might have given something like #!/usr/bin/perl, what effectively gets translated is that shell
executes this as

/usr/bin/perl <program name>
so eventhough the program script is setuid, it will not get executed as per the setuid principle.
If this were a compiled self-executable, then the setuid will work.

so the answers are
1. the effect uid is the uid of the user who is running the script
2. ???
 
Old 08-11-2009, 09:23 AM   #3
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Original Poster
Rep: Reputation: 58
Well setuid in perl is possible.
 
Old 09-11-2011, 10:35 PM   #4
mrdvt92
LQ Newbie
 
Registered: Apr 2006
Posts: 7

Rep: Reputation: 0
Quote:
Well setuid in perl is possible.
This took me a while to figure this out too. But, on Fedora.

Code:
sudo yum install perl-suidperl
Then the script will launch /usr/bin/suidperl not /usr/bin/perl even when the shabang is still #!/usr/bin/perl.

Try this little script.

Code:
#!/usr/bin/perl
print "$> => $<\n";
I saved as suid.pl and then

Code:
sudo chown root suid.pl
sudo chmod u+sx suid.pl
Then run it!

Code:
$ ./suid.pl
0 => 500
 
Old 09-11-2011, 11:13 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by mrdvt92 View Post
This took me a while to figure this out too. But, on Fedora.

Code:
sudo yum install perl-suidperl
Then the script will launch /usr/bin/suidperl not /usr/bin/perl even when the shabang is still #!/usr/bin/perl.

Try this little script.

Code:
#!/usr/bin/perl
print "$> => $<\n";
I saved as suid.pl and then

Code:
sudo chown root suid.pl
sudo chmod u+sx suid.pl
Then run it!

Code:
$ ./suid.pl
0 => 500
I'm assuming this requires perl to be suid-root, which sounds like a horrible idea. The only way you can suid a script is if the interpreter is suid (or it's otherwise run as root) and it supports such uid changes.
Kevin Barry

PS The only exception to "don't make an interpreter suid" might be a wrapper program (i.e. < 100 lines or so) that does the following:
  1. Checks the ownership of the script.
  2. Checks the suid flag of the script and the "nosuid"/"noexec" flags of the mount containing the script.
  3. If suid execution is acceptable, set the real and effective uids to the owner of the script. Otherwise, set the effective uid to the real uid.
  4. execve the actual interpreter, which isn't suid.
This, of course, means the script isn't actually suid; it just makes the wrapper change uids before executing the interpreter. The difference is that the interpreter isn't capable of changing to another uid unless it's running as root already. I'd make sure all of the above were true before installing any suid interpreter.

Last edited by ta0kira; 09-12-2011 at 08:45 AM.
 
Old 09-12-2011, 09:00 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Given
Quote:
This script has got owner and group as root
it sees to me that setuid is redundant; its already root.
If you want to run it as root from another user, sudo would be safer.
As per ta0kira, try to minimise the number of setuid programs on the system.
 
  


Reply

Tags
permission, setuid



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Set a Perl script as an unix service (start with system) onlymed Linux - Newbie 2 04-01-2009 02:59 PM
How to execute a Perl script in ~/.procmailrc with SELinux set to Enforcing? thomasz Linux - Security 1 03-14-2008 05:25 AM
Using Set UID to run script as root robo555 Linux - Software 3 11-23-2007 12:05 AM
Set UID hinetvenkat Linux - Security 4 06-08-2005 03:50 AM
set content-type to 'text/html' in sendmail, using perl script brokenfeet Programming 3 08-05-2003 02:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration