tags:

views:

96

answers:

7

Is there any way to get the source file of PHP like you would for HTML file or javascript from web browser alone? If so how? If not why?

A: 

Only if the web server happens to fail. Otherwise no, because all code is executed on server and only it's result are being send to browser.

Mchl
+2  A: 

No, this is not possible. Server-side languages are meant to be interpreted and run before the output is sent to the browser.

Jacob Relkin
It is possible, just not easy.
Rook
Right... when the server fails, the entire text will be printed on the web browser correct? So how does PHP script get interpreted?
denniss
Yeah, but this is dependent on bad server-side code, not the actions of the client. It's impossible to retrieve the server-side code on demand.
Jacob Relkin
@Jacob Relkin you can if you are running an old version of IIS or tomcat.
Rook
+2  A: 

Of course. But only if the web server is configured to return just the file and not interpret it first. Most web servers hosting PHP files aren't configured this way.

David
+1  A: 

You need to find a remote file disclosure vulnerability like this one. These most often occur in the application its self and can be detected by using a web application vulnerability scanner like w3af.

MySQL based sql injection can be used to read files using the load_file() function as described here.

It is possilbe that the httpd can be vulnerable to a source code disclosure attack, such as this one in IIS.

Rook
A: 

No, it would pose a massive security risk with MySQL passwords and other sensitive data.

esqew
yea... that's why I am worried.
denniss
You put the passwords *in* your code? That in itself is a massive security risk. Put it/them in a config file, put the file *outside* the web space so there's *no way* the server can send it. Lock the file down with very restrictive permissions. Don't check the file into version control.
Stephen P
+1  A: 

There is a way to do this - but you have the web server needs to be setup to serve ".phps" as text/plain as I've done to demonstrate code examples from my web server. However, if you're trying to poach code from a website running php it's really not possible. Not from the web browser.

Marco Ceppi
A: 
<?printf($f='<?printf($f=%c%s%c,39,$f,39);?>',39,$f,39);?>

so, yes.

mvds
whaaat?? what the heck is `$f` and what is this script supposed to accomplish, and how are you supposed to execute it on a server that isnt yours?
Mark
Mark, this code prints itself.
iandisme