Web Hosting Talk







View Full Version : Using the exec(); function


dbbrock1
04-15-2003, 05:47 PM
I'm trying to execute a few server side scripts but can't seem to get it working. I have it's permission level set to 777. Anyway here's the script:

<?php
$command = './edgepanel/createserver';
exec($command);
?>

It's kind of pathetic I can't get a 2 line script working isn't it? :)

Rich2k
04-15-2003, 06:15 PM
What's the message back from PHP?

Do you have safe mode turned on... if so you won't be able to use exec()

ChickenSteak
04-15-2003, 06:16 PM
is the script/binary you're trying to run not set uid, as I assume you're running this from http? If so you'll need to setuid by chmoding 4755.

chmod ./edgepanel/createserver 4755, then give it a try...

RackNine
04-15-2003, 06:17 PM
Note that some executables require that they be run through the shell. Most of Ensim's executables are like this, you'll need to either create an .sh script or exec the file through a shell.

-Matt

dbbrock1
04-15-2003, 06:30 PM
Originally posted by ChickenSteak
is the script/binary you're trying to run not set uid, as I assume you're running this from http? If so you'll need to setuid by chmoding 4755.

chmod ./edgepanel/createserver 4755, then give it a try...

I changed the permissions, still the same problem. Yes, I'm going to run this through http(trying to make a simple game server controller).

RackNine:
So there's no way to execute binaries via http? I noticed that WHM is able to execute binaries via http. How does it execute them?

Rich2k:
Yes Safemode is off. It doesn't give me any errors when I run the actual php script, it just displays a blank page.

Thanks agian,
Dan

null
04-15-2003, 08:03 PM
you need to write the full path to that file

dbbrock1
04-15-2003, 08:54 PM
Originally posted by null
you need to write the full path to that file

Doh! PHP doesn't have root privs does it?

DarktidesNET
04-15-2003, 09:39 PM
system('su pass');
exec('etc....');

dbbrock1
04-15-2003, 09:43 PM
Originally posted by DarktidesNET
system('su pass');
exec('etc....');

That looks like it should work :)

Thanks a bunch!

-Dan

DarktidesNET
04-15-2003, 09:48 PM
Aslong as no one gets the file and grabs the pass it will. I used something similar in the past. I guess if you're worried about the pass though you could buy that PHP encoding thing.

I'm not sure if you can make it any other way, but that's easist I've foud.

dbbrock1
04-15-2003, 09:52 PM
Originally posted by DarktidesNET
Aslong as no one gets the file and grabs the pass it will. I used something similar in the past. I guess if you're worried about the pass though you could buy that PHP encoding thing.

I'm not sure if you can make it any other way, but that's easist I've foud.

I won't have to worry about that. It's going to be an admin only script.

Thanks for the help :)

RackNine
04-16-2003, 01:52 AM
Originally posted by DarktidesNET
system('su pass');
exec('etc....');
Fine, do it the easy - and possibly smarter - way :D

Took 3 days on and off for me to figure out a workaround to that problem some years ago, I need to borrow that little lightbulb you've got hanging over your head.

-Matt

DarktidesNET
04-16-2003, 02:01 AM
I actually expected someone to flame me for some security purposes... I guess not. :D

RackNine
04-16-2003, 02:20 AM
That's nothing when in comes to mother-of-all-security-holes. Should see what one improperly placed .php script in an ensim server's /var/www/html folder does :)

Sincerely,

-Matt

DarktidesNET
04-16-2003, 02:26 AM
I've never used Ensim before... only Plesk & cPanel, guess I lucked out. Hehe.