We can leverage PHP wrappers to execute code on back-end servers through Local File Inclusion (LFI) vulnerabilities. By utilizing various PHP wrappers, we can gain control over the server and potentially execute commands remotely.
π Checking PHP Configurations
Verifying allow_url_include
Before using certain PHP wrappers, it's essential to check if the allow_url_include setting is enabled in the PHP configuration. This setting allows the inclusion of external data, which is crucial for executing remote code. The configuration file is found at (/etc/php/X.Y/apache2/php.ini) for Apache or at (/etc/php/X.Y/fpm/php.ini) for Nginx, where X.Y is your install PHP version
To check this, we can attempt to read the PHP configuration file using the base64 filter:
If the output shows allow_url_include = On, we can proceed with our attacks.
π Remote Code Execution with PHP Wrappers
Using the Data Wrapper
With allow_url_include enabled, we can use the data wrapper to include and execute PHP code. The data wrapper allows us to pass base64 encoded strings, which can be decoded and executed by the server.
Create a PHP Web Shell:
echo'<?php system($_GET["cmd"]); ?>'|base64
This will output a base64 encoded string of the PHP code.
Execute Commands: Use the encoded string in a URL: