About
Community
News of the Temple
Community Bulletin Board
Chat
Art
Carnality
Entertainment
Science
Society
Technology
bbs | search | rss | faq | about | register
digg | del.icio.us | sphere | google

Go Back   Community > Technology > Everything *NIX

Everything *NIX This is a general forum about all forms of *nix. Post your ideas and thoughts on this wonderful OS family. Talk about your personal favorite flavor of *nix and why you think it's so much better than the others. Anything pertaining to *nix and *nix administration should be posted here.

Reply
 
Thread Tools Display Modes
  #1   Add Dazzle to your ignore list  
Old 2009-01-03, 04:03
Dazzle Dazzle is offline
Regular
 
Default Running root commands without sudo

I am currently writing a program for a series of system related configuration, which involves a lot of messing around with programs that require root access. However, I do not wish to use sudo in order to be able to use these commands, as simple as "shutdown -h now" to more complex package management stuff.

I want my program to be platform independent and as some distributions do not use sudo, and some users simply don't like sudo, I want to make it work without it.

I also want some commands to work without me having to su to root or use sudo.

With the example of the shutdown command - is there any way to make it useable by non root users?

Cheers
Reply With Quote
  #2   Add glitched to your ignore list  
Old 2009-01-03, 04:56
glitched glitched is offline
Regular
 
somewhere in the general area
Default Re: Running root commands without sudo

My first reaction, No. This would be a major security flaw. Keep in mind I did no research into this topic before posting. That Is just my initial thought.
Reply With Quote
  #3   Add Prometheum to your ignore list  
Old 2009-01-03, 08:03
Prometheum Prometheum is offline
Regular
 
01 Send a message via AIM to Prometheum Send a message via MSN to Prometheum
Default Re: Running root commands without sudo

What language is this in?

This might be more appropriate for Hello World, but if you're in C, I'm sure there's a library function you can call to elevate your privileges. That will require user input; if you want your program to be autonomous, you pretty much have to use the setuid bit on it and have it run as root no matter who starts it.
Reply With Quote
  #4   Add deus-redux to your ignore list  
Old 2009-01-03, 12:50
deus-redux deus-redux is offline
Moderator
 
Great Britain Send a message via AIM to deus-redux Send a message via MSN to deus-redux
Arrow Re: Running root commands without sudo

You can set the file permissions with the setuid bit (as root, chmod +s on your executable). You also need to make sure it's owned by root (chown root) and everyone else has exec permissions (chmod a+x).

Please be aware of the security implications though. If you leave the file editable by everyone, they can potentially modify it and run whatever they wish as root.

It's really far safer if you can, to prompt the user to su to root. These permission differences exist for a reason, after all.

The other thing is, as far as I can tell, setuid affects the initial file that is executed - so if it's a binary, that's fine... but running a PHP script, seems not to give the root permissions to PHP... not sure if anyone knows a workaround to this?

-deus-
__________________
My Blog (PHP, AJAX, etc)
Email Me
Reply With Quote
  #5   Add Dazzle to your ignore list  
Old 2009-01-03, 15:09
Dazzle Dazzle is offline
Regular
 
Default Re: Running root commands without sudo

Quote:
Originally Posted by glitched View Post
My first reaction, No. This would be a major security flaw. Keep in mind I did no research into this topic before posting. That Is just my initial thought.
Yeah, that's what I thought at first. The thing is, it would be set up by root so that other users can use it. So it's like root would have to agree to allow other users to use it (just like sudo, really).. not really a security flaw, just a risk any system administrator would take with sudo anyway...

I thought about changing the file permissions for the configuration files... will changing them for the executables (in /usr/(s)bin IIRC) make for example "shutdown" work?

Prom: writing it in python... recently discovered the "import subprocess" command, I'm having fun with it XD
Reply With Quote
  #6   Add Prometheum to your ignore list  
Old 2009-01-03, 19:47
Prometheum Prometheum is offline
Regular
 
01 Send a message via AIM to Prometheum Send a message via MSN to Prometheum
Default Re: Running root commands without sudo

Quote:
Originally Posted by Dazzle View Post
Yeah, that's what I thought at first. The thing is, it would be set up by root so that other users can use it. So it's like root would have to agree to allow other users to use it (just like sudo, really).. not really a security flaw, just a risk any system administrator would take with sudo anyway...

I thought about changing the file permissions for the configuration files... will changing them for the executables (in /usr/(s)bin IIRC) make for example "shutdown" work?

Prom: writing it in python... recently discovered the "import subprocess" command, I'm having fun with it XD
Sounds like you want to use setuid. Note that you'll only be able to take advantage of it if you execute the script directly with something like /path/to/script, you will not get root with something like python /path/to/script.
Reply With Quote
  #7   Add deus-redux to your ignore list  
Old 2009-01-03, 19:52
deus-redux deus-redux is offline
Moderator
 
Great Britain Send a message via AIM to deus-redux Send a message via MSN to deus-redux
Arrow Re: Running root commands without sudo

Quote:
Originally Posted by Dazzle View Post
I thought about changing the file permissions for the configuration files... will changing them for the executables (in /usr/(s)bin IIRC) make for example "shutdown" work?
To be honest, I would really avoid changing the permissions on config files and system binaries unless you really know what you're doing.

Quote:
Originally Posted by Dazzle View Post
Prom: writing it in python... recently discovered the "import subprocess" command, I'm having fun with it XD
You're gonna fall foul of not being able to use setuid properly with scripting, then.

You could potentially write a setuid'd binary as a wrapper to execute the script. Do you know enough C to do this?

-deus-
__________________
My Blog (PHP, AJAX, etc)
Email Me

Last edited by deus-redux; 2009-01-03 at 20:03.
Reply With Quote
  #8   Add deus-redux to your ignore list  
Old 2009-01-03, 19:55
deus-redux deus-redux is offline
Moderator
 
Great Britain Send a message via AIM to deus-redux Send a message via MSN to deus-redux
Question Re: Running root commands without sudo

Quote:
Originally Posted by Prometheum View Post
Sounds like you want to use setuid. Note that you'll only be able to take advantage of it if you execute the script directly with something like /path/to/script, you will not get root with something like python /path/to/script.
I don't think most systems honor setuid for scripting, even if it's done with a shebang line. At least mine won't. It would make sense, since the binary that gets run is still Python, which isn't setuid'd.

edit:

Apparently Perl does have some kind of workaround for this. No idea if Python has something similar.

http://www.dwheeler.com/secure-progr...id-setuid.html

-deus-
__________________
My Blog (PHP, AJAX, etc)
Email Me

Last edited by deus-redux; 2009-01-03 at 20:05.
Reply With Quote
  #9   Add Prometheum to your ignore list  
Old 2009-01-03, 22:53
Prometheum Prometheum is offline
Regular
 
01 Send a message via AIM to Prometheum Send a message via MSN to Prometheum
Default Re: Running root commands without sudo

Quote:
Originally Posted by deus-redux View Post
I don't think most systems honor setuid for scripting, even if it's done with a shebang line. At least mine won't. It would make sense, since the binary that gets run is still Python, which isn't setuid'd.

edit:

Apparently Perl does have some kind of workaround for this. No idea if Python has something similar.

http://www.dwheeler.com/secure-progr...id-setuid.html

-deus-
It's always worked for me, but I guess that's because I only use perl and shell scripts. You could just have a shell script running as suid and have that call the python script.
Reply With Quote
  #10   Add Dazzle to your ignore list  
Old 2009-01-04, 12:18
Dazzle Dazzle is offline
Regular
 
Default Re: Running root commands without sudo

So one of the ways around it would be to use C or perl, neither of which I am at all familiar with...

The more I read about programming, the more I think I should learn C... it seems the be the fastest, most versatile language out there, albeit definitely not the simplest...

Slightly off topic, but in general (not just for this task): Do you think C (or maybe C++) would be more valuable than perl?

About the shell script: wouldn't you have to run the shell script as root in the first place? or just create it as root?

Last edited by Dazzle; 2009-01-04 at 12:41.
Reply With Quote
Reply


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
Forum Jump


All times are GMT. The time now is 14:09.


 

 

totse.com certificate signatures
 
 
About | Advertise | Art | Carnality | Community | Contact Us | Copyright Policy | Entertainment | FAQ
Link to totse.com | Science | Search | Society | Submissions | Technology
Hot Topics
Littering Is Awsome
Eradicating Feral Species
International Hanky Movement
Toilet paper down the toilet
Ecovillage project
The world is not going to flood!
Where is safe from climate change?
Global warming
 
Sponsored Links
 
Ads presented by the
AdBrite Ad Network

 

 

TSHIRT HELL T-SHIRTS