Running php index.php as shell in webpage

so i have a bit of a unique situation.

i have an encrypted index.php file that that can't be run the normal way that a web browser would run it. if it is run the normal way, the php script will show only gibberish on the web browser, instead of the actual php code.

when run from the command line, the php code works as it should:

root@jbow-VirtualBox:~# time php $(./index.php)
PHP Warning:  require(/home/jbow/../bootstrap/autoload.php): failed to open stream: No such file or directory in - on line 22
PHP Fatal error:  require(): Failed opening required '/home/jbow/../bootstrap/autoload.php' (include_path='.:/usr/share/php:/usr/share/pear') in - on line 22

my question is, is there a way to get web browsers to run the index.php through a shell, as im doing in the preceding example? is there a php setting i can modify that'll let web browsers know how to run php scripts for a particular web page/site?

Thank you

Without seeing the code, we can only speculate why it doesn't work.

This seems to get rid of the encrypted data from being shown on the webpage. however, it still doesn't show the content of the executed command.

so in other words, how do i get php to show on the web page the output of a command?

<?php exec('/var/encrypted/banana.php'); ?>

i have a php page that only has the above code in it. what i want to do is, when the banana.php script is executed, i want the output shown on the php page.

Kindly refer you to post 2.

You may try something like this

Test script

[akshay@localhost tmp]$ cat test.php 
<?php
    for ($h = 0; $h < 10; $h++) 
    {
	echo "<p>Line Number $h</p>".PHP_EOL;
    }
?>

This is what you execute on your browser

[akshay@localhost tmp]$ cat index.php 
<?php

// execute like this
exec("php /tmp/test.php 2>&1", $out, $return);

// Show content on browser
echo implode(PHP_EOL, $out ).PHP_EOL;

exec("ps aux | head -10 2>&1", $out1, $return);

// Show content on browser
echo '<pre>'.implode(PHP_EOL, $out1 ).'</pre>';
?>

Output

[akshay@localhost tmp]$ php index.php 
<p>Line Number 0</p>
<p>Line Number 1</p>
<p>Line Number 2</p>
<p>Line Number 3</p>
<p>Line Number 4</p>
<p>Line Number 5</p>
<p>Line Number 6</p>
<p>Line Number 7</p>
<p>Line Number 8</p>
<p>Line Number 9</p>
<pre>USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0  19352  1360 ?        Ss   09:22   0:00 /sbin/init
root         2  0.0  0.0      0     0 ?        S    09:22   0:00 [kthreadd]
root         3  0.0  0.0      0     0 ?        S    09:22   0:00 [migration/0]
root         4  0.0  0.0      0     0 ?        S    09:22   0:00 [ksoftirqd/0]
root         5  0.0  0.0      0     0 ?        S    09:22   0:00 [migration/0]
root         6  0.0  0.0      0     0 ?        S    09:22   0:00 [watchdog/0]
root         7  0.0  0.0      0     0 ?        S    09:22   0:00 [migration/1]
root         8  0.0  0.0      0     0 ?        S    09:22   0:00 [migration/1]
root         9  0.0  0.0      0     0 ?        S    09:22   0:00 [ksoftirqd/1]</pre>

Screenshot-2.png - Google Drive

1 Like

Thanks a million!! This works!

Suppose the "testscript" in your example is a form that accepts input from a user. how does the php script which the browser reads interpret that?

<?php
// in your index.php

$get=escapeshellarg(serialize($_GET));
$post=escapeshellarg(serialize($_POST));

// execute like this
exec("php /tmp/test.php  '$get'  '$post' 2>&1", $out, $return);


?>
<?php
// In your script

$get_array = unserialize($argv[1]);

$post_array = unserialize($argv[2]);
?>

---------- Post updated at 03:36 AM ---------- Previous update was at 03:13 AM ----------

It may be difficult for you to rewrite code for form and user management for example file upload,session,cookie etc, if you can explain your aim, there can be some simple solution for the same.

i'm going to try my best to give as much information as i can.

i have a plain php file called index.php. The content of this php file doesn't matter because the solution im looking for should work on any or at least most PHP files.

now, back to index.php. index.php has been encrypted. which means, it no longer is a regular php file that a typical web browser can read.

if i run the encrypted version of this index.php file from the command line, it works. however, from the webpage, i need to be able to run it as I do on the command line. which is where the solutions you provided works.

then i noticed a problem.

the php scripts i've tested so far have values hard-coded in them, which is why they worked. Then i began to wonder, what if i needed to get input from the user. how would that work.

currently, here is how i'm getting my encrypted php script to show up on the web:

<?php 

$mydata = shell_exec("/home/www-data/PlotLog.php");
print "$mydata";

?>

Okay.

That didn't last very long. Of course it matters.

Since you are unwilling and unable to provide any of the information required to help you, we literally cannot help you. Thread closed.