We may find the database password in a file like config.php
.
We may check on .ssh
directory and read id_rsa
file to ssh-in to the system.
There are ways to achieve remote code execution directly through the vulnerable function without relying on data enumeration or local file privileges.
Data
If allow_url_include
setting is enabled on PHP, we can use data wrapper to include external data such as PHP code.
Let’s check whether this is enabled by reading PHP config file.
Check PHP Config
Where can we find PHP configuration file?
- On Apache -
/etc/php/X.Y/apache2/php.ini
- On Nginx -
/etc/php/X.Y/fpm/php.ini
Let’s use conver.base64-encode
filter along with cURL to read the config:
Luckily, allow_url_include
is enabled:
Since this option is enabled, we can use the data wrapper.
RCE
We will first base64 encode base PHP web shell:
Now, we can URL encode the base64 string, and then pass it to the data wrapper with data://text/plain;base64,
. Finally, we can use pass commands to the web shell with &cmd=<COMMAND>
:
Input
Similar to the data
wrapper, the input wrapper can be used to include external input and execute PHP code.
For input
wrapper, we have to pass our input as a POST request’s data. So the vulnerable parameter must accept POST request for this attack to work.
Finally, the input
wrapper also depends on the allow_url_include
setting, as mentioned earlier.
Expect
Finally, we may utilize the expect wrapper, which allows us to directly run commands through URL streams.
However, expect is an external wrapper, so it needs to be manually installed and enabled on the back-end server.
Let’s check whether it is installed by searching for keyword expect from the PHP config file:
To use the expect module, we can use the expect://
wrapper and then pass the command we want to execute, as follows: