LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-03-2006, 06:45 PM   #1
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Rep: Reputation: 31
How to run a program as root.


When a form is submitted from the web, I want to run a program on my linux server to process the submitted data.

Unfortunately, that program must be run as root, but my web server only runs under the user apache.

How do I temporarily switch to root just to run the program in question?

Thx.

Last edited by fw12; 10-04-2006 at 06:10 PM.
 
Old 10-03-2006, 06:54 PM   #2
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Code:
su -c "program"
Or maybe you have sudo setup, in which case you can just do "sudo program" instead.
 
Old 10-04-2006, 01:09 PM   #3
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Rep: Reputation: 18
You should be aware that processing web forms with a program that has root privileges is very insecure. There's probably a better way to accomplish what you want. If you'd explain what you want to do, I'm sure someone would find a more secure way to set things up.

Regards,

Lotharster
 
Old 10-04-2006, 04:33 PM   #4
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Lotharster
You should be aware that processing web forms with a program that has root privileges is very insecure. There's probably a better way to accomplish what you want. If you'd explain what you want to do, I'm sure someone would find a more secure way to set things up.

Regards,

Lotharster
What I'm trying to do is create the ability on my website for users to signup for their own email accounts online. That process requires root privileges.
 
Old 10-04-2006, 04:35 PM   #5
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Vgui
Code:
su -c "program"
Or maybe you have sudo setup, in which case you can just do "sudo program" instead.
Wouldn't su -c "program" require a password?

I guess I can just test it out and see what happens.
 
Old 10-04-2006, 04:56 PM   #6
Vgui
Member
 
Registered: Apr 2005
Location: Canada
Distribution: Slackware
Posts: 496

Rep: Reputation: 31
Yes, it does require a password.
No, you didn't specify that passwordless login was required.

The idea that an anonymous web user has access to a root account any point is just asking for ownage, sorry.
 
Old 10-04-2006, 06:08 PM   #7
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by Vgui
Yes, it does require a password.
No, you didn't specify that passwordless login was required.

The idea that an anonymous web user has access to a root account any point is just asking for ownage, sorry.
It's not as gloomy as you paint it. As long as the submitted data is sanitized before being used on a command, I don't see the danger.

Let's say the command to add a new email address is:

{mail server home}/bin/vadduser web_data

where web_data is the email address submitted from the web.

What's the worse that could happen?
 
Old 10-05-2006, 06:36 AM   #8
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Rep: Reputation: 18
Quote:
Originally Posted by fw12
It's not as gloomy as you paint it. As long as the submitted data is sanitized before being used on a command, I don't see the danger.

Let's say the command to add a new email address is:

{mail server home}/bin/vadduser web_data

where web_data is the email address submitted from the web.

What's the worse that could happen?
The user could submit a login name like "newaccount ; /usr/bin/rm -rf /". Of course, it's easy to defend against this when you're aware of it. But sanitizing the submitted data against every possible attack (especially the ones you don't know about) is really hard.
 
Old 10-05-2006, 06:37 AM   #9
Lotharster
Member
 
Registered: Nov 2005
Posts: 144

Rep: Reputation: 18
What I#d do is set up sudo. You can specify that the apache user may only execute certain commands as root, and can even configure passwordless access.
 
Old 10-05-2006, 08:43 AM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
I would suggest not trying to reinvent a (flawed from the start) wheel but look into existing SW. It saves you headaches and prolly a server and in return you also get a (hopefully) tried and tested tool, support, etc, etc. There must be packages for just doing that on Freshmeat and Sourceforge.
 
Old 10-05-2006, 11:57 AM   #11
TylerD75
Member
 
Registered: Aug 2004
Location: Norway
Distribution: Gentoo
Posts: 96

Rep: Reputation: 18
What about chrooting the apache environment, and let apache run as root.
Or even better setup your mail system to run as the apache user (or some other non privileged user)?
I have no idea of what mail system you're using, but that's probably the way I would have tried to solve it...
 
Old 10-05-2006, 11:59 AM   #12
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
I see your point here. However, newaccount ; /usr/bin/rm -rf / clearly won't be acceptable as an email address. An email address has a narrow definition of acceptable characters.

So, while your point is good in general, in my particular case, it doesn't apply.

So, once again, I ask:

If I run as root

{mail server home}/bin/vadduser web_data

where web_data is the email address submitted from the web. What's the worse that could happen?

Last edited by fw12; 10-05-2006 at 12:04 PM.
 
Old 10-05-2006, 12:01 PM   #13
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by unSpawn
I would suggest not trying to reinvent a (flawed from the start) wheel but look into existing SW. It saves you headaches and prolly a server and in return you also get a (hopefully) tried and tested tool, support, etc, etc. There must be packages for just doing that on Freshmeat and Sourceforge.
I have looked with no success.
 
Old 10-05-2006, 12:04 PM   #14
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by TylerD75
What about chrooting the apache environment, and let apache run as root.
Or even better setup your mail system to run as the apache user (or some other non privileged user)?
I have no idea of what mail system you're using, but that's probably the way I would have tried to solve it...
I'm looking into this idea. I'm not formally trained in Linux, so everybody's input is a major help. Thanks to you all.
 
Old 10-05-2006, 06:04 PM   #15
fw12
Member
 
Registered: Mar 2006
Distribution: Fedora core, Ubuntu
Posts: 175

Original Poster
Rep: Reputation: 31
Here is what I did finally:

I edited /etc/sudoers file

# visudo

and added the line:

apache ALL=(root) NOPASSWD: {mail server home}/bin/vadduser

So now in my PHP script, I can do:

sudo -u root {mail server home}/bin/vadduser web_data

At least now only the program vadduser can be run as root by apache. Is this still risky? Better ideas welcome.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to run GUI program as root shadkong Slackware 8 09-20-2005 02:24 PM
Run program as root at logon? scottjwoodford Linux - Software 7 06-13-2005 04:30 AM
My Knoppix 3.7 need root password when I run program AskMe Linux - Software 5 04-15-2005 05:35 AM
run program as root / password prompt acidjuice Linux - Software 6 03-15-2005 10:33 PM
Automatically run root program. Hammett Linux - Software 4 05-16-2004 12:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:41 PM.

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