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 exec 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-30-2008   #1 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
exec function

i know that exec function in php used to execute commands , i have a problem:i try to use exec function to execute iptables command but i failed.please help me.
this is the code
<?php
$output = shell_exec('iptables -L ');
echo "<pre>$output</pre>";
?>
shyma is offline   Reply With Quote
Old 04-30-2008   #2 (permalink)
Lakshmipathi
Linux User
 
Lakshmipathi's Avatar
 
Join Date: Sep 2006
Location: 3rd rock from sun
Posts: 492
Smile

Quote:
Originally Posted by shyma View Post
<?php
$output = shell_exec('iptables -L ');
echo "<pre>$output</pre>";
?>
your code is working from command line.
If you are trying execute this code using browser then check with absolute path name

replace this line
Quote:
$output = shell_exec('iptables -L ');
with this
Quote:
$output = shell_exec('/sbin/iptables -L ');
Let me know the results
__________________
- LakshmiPathi.G
------------------------------
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
------------------------------
My OpenSource Projects:
giis
exthide
ext3crave
Lakshmipathi is offline   Reply With Quote
Old 04-30-2008   #3 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
exec function 2

i try this code but i failed also
<?php
$output = shell_exec('/sbin/iptables -L');
echo "<pre>$output</pre>";
?>
thanks for help.
shyma is offline   Reply With Quote
Old 04-30-2008   #4 (permalink)
Lakshmipathi
Linux User
 
Lakshmipathi's Avatar
 
Join Date: Sep 2006
Location: 3rd rock from sun
Posts: 492
Smile

Hi shyma,
You can reply this thread - Don't need to create new thread like you did here.
http://www.linuxforums.org/forum/lin...ction-2-a.html
[quote]
i try this code but i failed also
<?php
$output = shell_exec('/sbin/iptables -L');
echo "<pre>$output</pre>";
?>
thanks for help.
[\quote]

Are you trying to run php from web browser?
anyway first check that code runs from command line or not.
if it's not running from command line post it's output as well as post the output of command
whereis iptables
__________________
- LakshmiPathi.G
------------------------------
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
------------------------------
My OpenSource Projects:
giis
exthide
ext3crave
Lakshmipathi is offline   Reply With Quote
Old 04-30-2008   #5 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
yes i try to run php from web browser and the command run in command line, but i didn't know what is the problem.
thanks.
shyma is offline   Reply With Quote
Old 04-30-2008   #6 (permalink)
Lakshmipathi
Linux User
 
Lakshmipathi's Avatar
 
Join Date: Sep 2006
Location: 3rd rock from sun
Posts: 492
Exclamation

You are logged in as root -- right? and
you are getting desired output from command line-right?
And you are not getting result from browser - right?

Then try and replace the command iptables with simple command like ls

/bin/ls

If 'ls' command gives you output then i think problem lies with permissions.

Try with ls command and let me know the results
__________________
- LakshmiPathi.G
------------------------------
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
------------------------------
My OpenSource Projects:
giis
exthide
ext3crave
Lakshmipathi is offline   Reply With Quote
Old 04-30-2008   #7 (permalink)
shyma
Just Joined!
 
Join Date: Apr 2008
Posts: 38
simple commands can be executed. and iptables commands can not.
how i can get permissions to execute iptables commands through php interface?
please help me.
shyma is offline   Reply With Quote
Old 05-05-2008   #8 (permalink)
Lakshmipathi
Linux User
 
Lakshmipathi's Avatar
 
Join Date: Sep 2006
Location: 3rd rock from sun
Posts: 492
Exclamation

Quote:
Originally Posted by shyma View Post
simple commands can be executed. and iptables commands can not.
how i can get permissions to execute iptables commands through php interface?
please help me.
So root user commands are not executed.
If i'm not wrong - i think you need to give permission in /etc/sudoers -you can give sudo privileges to apache's user, and then use it on php [also check out httpd.conf if ur server is apache & php.ini ]

Try google from here on about "executing root commands under php using browser"

All the best
__________________
- LakshmiPathi.G
------------------------------
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
------------------------------
My OpenSource Projects:
giis
exthide
ext3crave
Lakshmipathi 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 12:01 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