Running php index.php as shell in webpage


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running php index.php as shell in webpage
# 1  
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:

Code:
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
# 2  
Without seeing the code, we can only speculate why it doesn't work.
# 3  
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?

Code:
<?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.
# 4  
Kindly refer you to post 2.
# 5  
You may try something like this

Test script
PHP Code:
[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
PHP Code:
[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
PHP Code:
[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
This User Gave Thanks to Akshay Hegde For This Post:
# 6  
Quote:
Originally Posted by Akshay Hegde
You may try something like this

Test script
PHP Code:
[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
PHP Code:
[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
PHP Code:
[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
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?

Last edited by SkySmart; 10-06-2016 at 03:37 PM..
# 7  
PHP Code:
<?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 Code:
<?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.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #796
Difficulty: Medium
Fractions in binary arithmetic terminate only if 2 is the only prime factor in the denominator.
True or False?

10 More Discussions You Might Find Interesting

1. Web Development

Display received sms on webpage - php

Hello, Scenario: Send sms from putty and display it on webpage. I have rented an short message service from a company and set callback url to my vps. PHP is installed in my vps . my mobile phone is: ********85** receipent mobile phone is: 49********* callback url is redirected to... (0 Replies)
Discussion started by: baris35
0 Replies

2. Shell Programming and Scripting

Executing Shell Script from PHP Webpage

Hello , I am trying to execute a small shell script from a PHP Webpage. Below is the shell script : 1.sh $ cat /home/oracle/rahul/1.sh #!/bin/ksh echo "`date` : Report generation in progress" > /home/oracle/rahul/report.txt echo "Run successfully script"; Below is the PHP... (1 Reply)
Discussion started by: rahul2662
1 Replies

3. UNIX for Dummies Questions & Answers

How to submit form on an php webpage from command line?

Hello, i have page domain.com/form.php the form fields on form.php are named: name=ipaddress name=port and submit button is named: submit i want to ask how the linux command will look like to submit the form filled with: ipaddress: 127.0.0.1 port: 80 I tried various curl and... (5 Replies)
Discussion started by: postcd
5 Replies

4. UNIX for Advanced & Expert Users

Running multiple php scripts into one php only, cron mail alert problem...

hi, while separated they produce the usual mail alert and i can see the output... if i write into the php script: <?php system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script1.php'); system('php -f /var/www/vhosts/domain.com/httpdocs/folder/script2.php'); system('php -f... (0 Replies)
Discussion started by: 7stars
0 Replies

5. Web Development

[php] webpage with login & mysql-db

Hi all, What I was looking for before was a multi-user password manager, web-based! The offer of free or cheap tools of this kind is very pover. Or they are too complex (or too expensive) I'm not a web programmer but I now decided to set up a (php) website with login and based on this login... (1 Reply)
Discussion started by: thibautp
1 Replies

6. Web Development

I can't open my index.php page after insert php code

Hello guys, Does anyone can help me? I've just made my simple index.php without any code, but after insert session code to check if any user is authenticated, my index.php doesn't work anymore. Any fresh eyes could help me to see what and where the code is wrong? <? if... (6 Replies)
Discussion started by: metalfreakbr
6 Replies

7. Web Development

php script + not displaying webpage

Hi guys Im in the process of designing a website for my company which does the following 1) Daily execution a perl script. The perl script's output is diverted to a .html file. 2) The .html file generated from 1) sets up a centralised webpage showing options as radio buttons (the radio... (1 Reply)
Discussion started by: JamesGoh
1 Replies

8. Shell Programming and Scripting

Calling an Expect script from a Webpage using PHP

I have a webpage that is in HTML and PHP. In PHP I have tried using exec, system, shell_exec and passthru functions to call an Expect Script file (temp.exp). This Expect file spawns a telnet session that uses "expect/send" commands to retrieve information from an environmental unit (not a normal... (0 Replies)
Discussion started by: CCUSmith
0 Replies

9. UNIX for Advanced & Expert Users

which access right should set in my webpage index.html ?

I have a webpage, http://my.dns.com/~zp523/index.html, I want all people to have read and execute privileges. I want to extend it with execute privilege. Which command should be used in chmod? is it only give read(r) & execute(x) parameter in 'chmod ??? index.html' thk a lot!! (1 Reply)
Discussion started by: zp523444
1 Replies

10. Shell Programming and Scripting

PHP: problem with index.php

iam geting a error with this index script. heres the error Parse error: parse error in c:\phpdev\www\dev\compulearn\in work\index.php on line 39 Whats wrong?? ------------------------ <?php //display header and left bars include ('header.php'); include ('left.php'); //connect... (13 Replies)
Discussion started by: perleo
13 Replies

Featured Tech Videos