Php-fpm Remote Code Execution Vulnerability (CVE-2019-11043) Threat Alert

Php-fpm Remote Code Execution Vulnerability (CVE-2019-11043) Threat Alert

October 29, 2019 | Mina Hao
phpfpm

Overview

Recently, security researchers have published a vulnerability in php-fpm (CVE-2019-11043) that could lead to remote code execution in certain Nginx configurations.

The vulnerability exists in the file sapi/fpm/fpm/fpm_main.c (https://github.com/php/php-src/blob/master/sapi/fpm/fpm/fpm_main.c#L1140), which assumes the prefix of env_path_info Equal to the path of the php script, but in fact the code does not check if this assumption is met, and the lack of this check will invalidate the pointer in the “path_info” variable. In some Nginx configurations, an attacker can use a line break (encoded at %0a) to destroy the regexp in the `fastcgi_split_path_info` directive, which can cause a null PATH_INFO, which triggers the vulnerability.

It is understood that the vulnerability was discovered by researcher Andrew Danau during a CTF game. When he sent %0a to the server URL, the server returned an exception and discovered the vulnerability after further research.

References:

https://lab.wallarm.com/php-remote-code-execution-0-day-discovered-in-real-world-ctf-exercise/

Affected Versions 

In the Nginx + php-fpm environment, all of the PHP 7+ versions are affected (PHP 7.0, PHP 7.1, PHP 7.2, PHP 7.3) using the following Nginx configuration, and currently crash on PHP 5.6.

The specific Nginx configuration is as follows:

   location ~ [^/]\.php(/|$) {

fastcgi_split_path_info ^(.+?\.php)(/.*)$;

fastcgi_param PATH_INFO       $fastcgi_path_info;

fastcgi_pass   php:9000;

}

}

Security Recommendations

  • PHP has released a patch on October 12 (see the reference below) It is recommended that affected users should upgrade your system to prevent against this vulnerability.
  • Check the Nginx configuration. If the above vulnerable configuration exists, it is recommended to delete:

fastcgi_split_path_info ^(.+?\.php)(/.*)$;

fastcgi_param PATH_INFO       $fastcgi_path_info;

Reference:

https://bugs.php.net/patch-display.php?bug_id=78599&patch=0001-Fix-bug-78599-env_path_info-underflow-can-lead-to-RC.patch&revision=latest

Statement

This advisory is only used to describe a potential risk. NSFOCUS does not provide any commitment or promise on this advisory. NSFOCUS and the author will not bear any liability for any direct and/or indirect consequences and losses caused by transmitting and/or using this advisory. NSFOCUS reserves all the rights to modify and interpret this advisory. Please include this statement paragraph when reproducing or transferring this advisory. Do not modify this advisory, add/delete any information to/from it, or use this advisory for commercial purposes without permission from NSFOCUS.

About NSFOCUS

NSFOCUS, Inc., a global network and cyber security leader, protects enterprises and carriers from advanced cyber attacks. The company’s Intelligent Hybrid Security strategy utilizes both cloud and on-premises security platforms, built on a foundation of real-time global threat intelligence, to provide multi-layered, unified and dynamic protection against advanced cyber attacks.

NSFOCUS works with Fortune Global 500 companies, including four of the world’s five largest financial institutions, organizations in insurance, retail, healthcare, critical infrastructure industries as well as government agencies. NSFOCUS has technology and channel partners in more than 60 countries, is a member of both the Microsoft Active Protections Program (MAPP), and the Cloud Security Alliance (CSA).

A wholly owned subsidiary of NSFOCUS Information Technology Co. Ltd., the company has operations in the Americas, Europe, the Middle East and Asia Pacific.