The memory limit is a setting that allocates a fixed memory size for executing a script. This setting protects the server from poorly coded scripts that allocate unnecessary space, in return saving the server’s memory during large-scale usage of the application. An attacker can view the memory limit set by executing phpinfo() function to see the memory limit and plan an attack according to the value. A server administrator can set memory limit from -1 (No memory allocation) to any size. The memory limit was first introduced as a setting in php.ini after PHP version 5.2.0. For PHP versions before 5.2.0, the memory limit was implemented during compile time. The memory limit was implemented as a per-script setting.
If an attacker knows the maximum size a PHP script allocated by the server, he will be able to execute malicious scripts with maximum size from different clients. This malicious move by the attacker can hang the server to perform a denial of service attack. The attacker can also perform other attacks after this attack to completely shut down the server.
Example The following code is an example of PHP memory_limit:-
php.ini
.htaccess
Using this vulnerability, an attacker can perform:-
Beagle recommends the following fixes:-
Make sure the phpinfo() is disabled in the server. Change the memory limit to your desired value. php.ini
.htaccess