During the installation of MediaWiki, I had to download a file called LocalSettings.php
. When I download it by clicking on the download link (which happens to be http://localhost/mymediawiki/mw-config/index.php?localsettings=1
), it downloads a php file, but when I download it by "copy link address" and using
$ wget URL -O output
it downloads a html file.
The following is the content of the index.php
:
The following is the content I get with wget
:
Basically the page that offers the download link (which is http://localhost/mymediawiki/mw-config/index.php?page=Complete
), it seems.
The following are some of researches I had:
But I don't understand how clicking on the "download the file" link DOES download the php file. This makes me wonder ther must be a way to download the php file with some bash commands like wget
or curl
.
Please tell me how the browser is doing it, and any other way to do it through the termianl.
your browser has cookies, wget doesn't, it's almost certainly a file protected by cookies, only those with the correct (authentication?) cookies can access the file, wget can not. in chrome open the developer console, navigate to the Network tab, download the file in chrome, find the request in the network tab, right click on the tab and press "copy as curl", and you'll see what the request looks like with cookies, it'll look more like:
curl 'https://stackoverflow.com/posts/validate-body' -H 'cookie: prov=5fad00f3-5ed3-bd3b-3a8a; _ga=GA1.2.20207544.1508821; sgt=id=e366-9d13-4df2-84de-2042; _gid=GA1.2.129666.1538138077; acct=t=Jyl74nJBTyCIYQq5mc2sf&s=StN3CVV2B5Opj051ywy7' -H 'origin: https://stackoverflow.com' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: en-US,en;q=0.9' -H 'user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36' -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' -H 'accept: /' -H 'referer: https://stackoverflow.com/' -H 'authority: stackoverflow.com' -H 'x-requested-with: XMLHttpRequest' --data $'body=your+browser+has+cookies%2C+wge&oldBody=&isQuestion=false' --compressed
As you've seen in related questions, you can't download PHP source code just by requesting the file, at least as long as the HTTP Server has PHP extension enabled.
But that by no means imply you can't download a PHP script given the right circumstances.
You can have in the server a PHP script working as proxy to bypass PHP parsing and send you source code of any PHP file in the server. It just has to set up some headers and hand it to you with a simple readfile(filename)
. Of course, that is usually done after making sure that you are authorized.
Also, the address of a link isn't always the address you are actually accessing when you click the link. It may contain a onclick
action that overrides the href
, and it can be placed there dynamically so you won't know about it even if you check the HTML source code.
One easy way to figure out what the link is actually doing is to press Ctrl+Shift+C in Firefox or Chrome, go to the Network tab, and click the link to see what it really is accessing.
I bet it is not accessing the file directly like you think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With