Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Security
Reload this Page php function
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Security Discussion about keeping your machines secure, and the crackers out.

Reply
 
Thread Tools Display Modes
Old 04-29-2008   #1 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
php function

what is the function in php that used to execute files in linux. i want to execute script file that contains iptables rules
shyma is offline   Reply With Quote
Old 04-29-2008   #2 (permalink)
HROAdmin26
Linux User
 
Join Date: Nov 2007
Posts: 390
PHP.Net - Exec References
HROAdmin26 is offline   Reply With Quote
Old 04-29-2008   #3 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
php function 2

how i can use exec function in php to execute iptables command
shyma is offline   Reply With Quote
Old 04-29-2008   #4 (permalink)
HROAdmin26
Linux User
 
Join Date: Nov 2007
Posts: 390
Wow...just wow...

Exec Function - PHP Manual

Copy/paste from the PHP function manual:
Code:
<?php
// outputs the username that owns the running php/httpd process
// (on a system with the "whoami" executable in the path)
echo exec('whoami');
?>
HROAdmin26 is offline   Reply With Quote
Old 05-15-2008   #5 (permalink)
secondmouse
Just Joined!
 
Join Date: May 2008
Posts: 21
use php to run iptables command

With iptables, things are a bit more complicated than the command whoami due to the fact that only root can execute iptables command. But we can get around this with sudoers. You need to add the web server user (for example, apache) to /etc/sudoers like this

apache ALL=NOPASSWD:/sbin/iptables

then in your php script you put your command something like

$cmd="sudo /sbin/iptables Blah Blah Blah";
exec($cmd);

if you don't see /etc/sudoers, you need to get it installed first.
secondmouse is offline   Reply With Quote
Old 05-20-2008   #6 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
iptables2

i add this line to sudoers
apache ALL=NOPASSWD:/sbin/iptables
then i write php script like this
<?php
$cmd="sudo /sbin/iptables -A INPUT -p tcp -s 172.16.58.10 -j REJECT";
exec($cmd);
?>
but i didn't get the result.
thanks for help.
shyma is offline   Reply With Quote
Old 05-21-2008   #7 (permalink)
secondmouse
Just Joined!
 
Join Date: May 2008
Posts: 21
shyma,
You need to find out the what the www user is first. If you are using apache, look under /etc/apache/uid.conf. Replace "apache" in "apache ALL=NOPASSWD:/sbin/iptables" with the User setting in uid.conf and try again. Also if you can post the error message returned by php if you need further help.
secondmouse is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 06:02 AM.

Powered by vBulletin 3.6.8 ©2000 - 2007, content relevant URLs by vBSEO, Property of Core Root.

Content Relevant URLs by vBSEO 3.0.0