LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2006, 07:35 AM   #1
Richtown
Member
 
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49

Rep: Reputation: 15
Question Executing shell commands through PHP!!!


Hi chaps,

I am trying to generate a script that will execute terminal commands through Apache(PHP).When i got to execute commands i don't have any root permissions to do so. even tho i am logged in as root.

Could someone help me out?

i think there is some sort of command you have to enter into php but i am not sure. . .


Many Thanx
Rich.
 
Old 04-10-2006, 11:10 AM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
I'll put the usual warnings about running a web script which can do things as root here...be very, very careful!

Check the PHP shell_exec manual http://us2.php.net/shell_exec - some of the comments at the bottom are regarding script root access, and may help you out a bit.
 
Old 04-10-2006, 01:15 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by Richtown
Hi chaps,

I am trying to generate a script that will execute terminal commands through Apache(PHP).When i got to execute commands i don't have any root permissions to do so. even tho i am logged in as root.

Could someone help me out?

i think there is some sort of command you have to enter into php but i am not sure. . .


Many Thanx
Rich.
Hi, and welcome to LQ!

What are you trying to achieve, what command are you
invoking, what is the error message you're getting?


Cheers,
Tink

P.S.: I'd suggest that you let me move this to our
programming forum, better exposure there.
 
Old 04-11-2006, 08:48 AM   #4
Richtown
Member
 
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49

Original Poster
Rep: Reputation: 15
HI, i am at university we have a project to build a firewall in linux using iptables, basically all i wanted to do was execute bash commands in php. But i dont have the correct permissions?

WOuld you know how to do this?


Regards
Rich
 
Old 04-11-2006, 01:06 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
If I knew which commands you're trying to execute from which
environment, maybe? And you told me what the exact error message
was ... maybe we could assess what the problem is. But with
the things you keep repeating: no.

Are you using PHP from the command-line or from within Apache?
If it's Apache: as what user is the service being run?
...

Do yourself a favour, and take ESRs advice


Cheers,
Tink
 
Old 04-12-2006, 04:00 AM   #6
fouldsy
Senior Member
 
Registered: Jan 2002
Location: St Louis, MO
Distribution: Ubuntu
Posts: 1,284

Rep: Reputation: 47
Look at using sudo. This will you specify the user Apache runs as, often www-data, to access various commands normally only accesible to the root user. As mentioned before, be careful what commands you allow, and ensure there's some kind of syntax validation within your PHP so that naughty code can't get passed to the shell. There's a host of debates as to what's the right way to do it from a security point of view! Otherwise, pretty easy to execute iptable commands. If you're wanting to do more, then again as mentioned before, tell us a bit more info.
 
Old 04-12-2006, 02:57 PM   #7
Richtown
Member
 
Registered: Apr 2006
Location: Portsmouth
Distribution: CentOS & Ubuntu
Posts: 49

Original Poster
Rep: Reputation: 15
ok,
I'm Running apache 2.0/ logged in as root

Apachectl start

I have a HTML page that will input a variable allow_ip = e.g 19.168.1.1
I have a submit button, when pressed directs to a php page.

which has the following lines:
<?php
echo exec('iptables -A INPUT -s &allow_ip -j DROP')
?>

when i run this on apache it doesnt seem to work?,when i run the command terminal it doenst block the ip.

Kind Regards
Rich
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running shell commands thru PHP JonathonReinhart Linux - Software 1 12-23-2005 02:05 AM
[PHP] Sending shell commands from PHP pEeDy Programming 4 11-04-2005 08:06 PM
executing shell commands in c++ true_atlantis Programming 2 10-01-2004 04:53 PM
PHP to run Shell commands Gear_freak2000 Linux - Software 4 06-04-2003 05:39 AM
Executing commands on startup viciousfish Linux - General 5 06-28-2002 02:15 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:54 AM.

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