Shell code in php program

A

Anonymous

Guest
Hi everyone, all is in the title. What i want is a web page programmed in php which allow me to execute a shell program when someone cliqued on a link. I tried to use the shell_exec and exec functions but the results aren't those expected. here is a sample i tried to see how to execute shell script in a php page:


<?php
function test() {
$path='var/html/test';
exec($path); //shell_exec($path);
//exec("exit(0)");
}
?>

<?php
echo "does it work?"
test();
?>






in the shell script test (i do chmod 755) there is

echo "yes it works"

when i access to the php page i only have "does it works?"






It's like i've found the solution with passthru :-D
 
It seems that passthru only execute the shell command "echo" :eek: , because when i use other commands nothing happen. I tried to redirect the output of a command in another file and after that open the file and display the result, but there nothing in the file:

<?php

function test()

{

$path='var/html/test';
passthru($path);

}

?>

<?php
echo "does it work?"
test();

$file = fopen("temp","r")

while(!feof($file)
{
$line = fgetss($file,255);
print("$line \n");
}
fclose($file);

?>






in the shell script test (i do chmod 755) there is

echo "yes it works" >> temp
 
the problem was i made permissions to write only for root (chmod 755), i just remember that apache's user is set as nobody in the httpd.conf, so if i want my script to write in temp, i have to tape chmod 777 temp.
i almost became crazy :shock: but now i feel ungry and sleepy :sleep: as i was working since 8:30 a.m. Hope that can help someone
 
I know what its funny but....
try change some:

<?php
echo "does it work?"
test();
?>

<?php
function test() {
$path='var/html/test';
exec($path); //shell_exec($path);
//exec("exit(0)");
}
?>
 
Back
Top