Phpinfo() Memory Limit

OWASP 2013-A6 OWASP 2017-A3 CAPEC-346 CWE-213 ISO27001-A.18.1.3 WASC-13

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

        memory_limit = 512M

    

.htaccess

        php_value memory_limit 512M

    

Impact

Using this vulnerability, an attacker can perform:-

  • Denial of service attacks.
  • Illegal termination of the program to void the validity of the data.

Mitigation / Precaution

Beagle recommends the following fixes:-

Make sure the phpinfo() is disabled in the server. Change the memory limit to your desired value. php.ini

        memory_limit = 100M

    

.htaccess

        php_value memory_limit 100M

    

Latest Articles