About
Community
Bad Ideas
Drugs
Ego
Erotica
Fringe
Society
Technology
register | bbs | search | rss | faq | about
meet up | add to del.icio.us | digg it
Go Back   Community > Technology > Everything *NIX
Register FAQ Members List Calendar Today's Posts

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
  #11   Add deus-redux to your ignore list  
Old 2009-01-04, 17: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
Smile Re: Running root commands without sudo

Quote:
Originally Posted by Dazzle View Post
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?
C is one of my favorite languages, and it's pretty much the backbone of *nix.

That said, Perl can also be very valuable.

I would really try and learn C now if you have the time. It's well worth it. Try and pick up Perl later if you get the chance. Once you know C, learning Perl should come easily.

Quote:
Originally Posted by Dazzle View Post
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?
Try it on your system. Create a shell script that tries to do something only root can (create a file in root's home directory, for example).

su to root, chown the file to root:root. chmod a+x it, so all users can run it. chmod +s it, to set setuid. Return to your normal user, and execute.

setuid should mean the script runs with the permissions of root.

Now for me, this works fine for a binary executable, but not a shell script. I've looked into it, and the consensus seems to follow this:

http://rob.sun3.org/misc/setgid-and-...shell-scripts/

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

Last edited by deus-redux; 2009-01-04 at 18:02.
Reply With Quote
  #12   Add beatmeofficer to your ignore list  
Old 2009-01-05, 06:12
beatmeofficer beatmeofficer is offline
Regular
 
The First World
Default Re: Running root commands without sudo

Could this be solved by creating a new group, adding the users, and giving execute permission to members of the group?
Reply With Quote
  #13   Add coroner to your ignore list  
Old 2009-01-05, 18:06
coroner coroner is offline
Moderator
 
Sierra Vista. Arizona
Default Re: Running root commands without sudo

Quote:
Originally Posted by beatmeofficer View Post
Could this be solved by creating a new group, adding the users, and giving execute permission to members of the group?
You would think you could manipulate something using the wheel group, since wheel is in root's group. Unfortunately since Linux kernel does not let you use setuid or setgid on shell scripts as you would an ELF executable, then you simply cannot do this. What he should do is create a specialized group and put his users in that group, for example, autopsy and coroner on my laptop are in the "users" group. All I have to do is put the "users" group in the sudoers file, and require no password for any command, or I can specify which commands specifically with the full file path. No need to specify each user since sudoers allows specification by group and specific commands.

That is what he should do if using BASH.
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

 
To the best of our knowledge, the text on this page may be freely reproduced and distributed.
 

totse.com certificate signatures
 
 
About | Community | Bad Ideas | Drugs | Ego | Erotica | Fringe | Society | Technology
Hot Topics