LinuxQuestions.org
Visit Jeremy's Blog.
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 05-04-2006, 01:26 PM   #1
maxabbr
LQ Newbie
 
Registered: May 2006
Posts: 5

Rep: Reputation: 0
Unhappy sudo don't work in php script


I take the Fedora Core 5 in place to a Fedora Core 4. No problem with the instalation but I have a problem with a php script that call the sudo command.

In that script I call the system() function of php to make a iptables insertion. In the previous FC4 it works fine with the follow:

With the visudo I take access to apache user:
apache localhost=NOPASSWD:/sbin/iptables

In the php script I just call:
system("sudo /sbin/iptables -t nat -...");

In the FC5, when I try the iptables add as root all works fine. When I try:
root@fedora# sudo -u apache /sbin/iptables -t nat -...

I got an error that I fix with (itīs not required in FC4):
chmod +s /sbin/iptables

However in the php script the iptables command fail and in the /var/log/messages I get some messages like that:
'avc: denied { create } comm="sudo" scontext=system_v:system_r:httpd_sys_script_t:s0 tcontext=system_v:system_r:httpd_sys_script_t:s0 tclass=netlink_route_socket'

I have no idea what to do. :-(
 
Old 05-04-2006, 10:37 PM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
This is SELinux denying Apache the right to use sudo. SELinux is an extra security layer for the Linux kernel partially developed by the NSA. By default Red hat ships a "targeted" policy that only interferes with a couple of commonly exploited service, Apache being one of them. You can either turn off SELinux or modify the policy to allow it to execute sudo. A quick Google search will help you figure out how to do this.

Be aware, though, that what you are doing is very dangerous and SELinux is denying it for good reason. Basically, even a small bug in your PHP script can lead to a system compromise if it can be exploited to pass unfiltered user data to thew iptables command string. I certainly hope that you are properly santizing input to your PHP script!
 
Old 05-05-2006, 11:22 AM   #3
maxabbr
LQ Newbie
 
Registered: May 2006
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks, I had found this one yesterday night after reading some docs of FC5. As I say this script is just for fun and I will never make some in a true server. But thanks the advice!

Best regards,

Max
 
  


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
Trying to execute a shell-script using php but chown does not work stormrider_may Programming 15 04-11-2006 08:59 PM
sudo does not work powah Linux - Security 1 12-06-2005 04:49 PM
Using sudo to control script exececution wimnat Linux - Software 10 11-15-2005 03:35 AM
Postfix->filter Script->sudo adduser lawtoncooper Linux - General 0 07-23-2004 01:12 AM
howto start vpnclient with php script and sudo ? cccc Programming 1 01-12-2004 11:46 AM

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

All times are GMT -5. The time now is 12:40 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