{"id":33607,"date":"2019-10-30T05:05:02","date_gmt":"2019-10-29T20:05:02","guid":{"rendered":"https:\/\/jirak.net\/wp\/addressing-the-php-fpm-vulnerability-cve-2019-11043-with-nginx\/"},"modified":"2019-10-30T06:34:57","modified_gmt":"2019-10-29T21:34:57","slug":"addressing-the-php-fpm-vulnerability-cve-2019-11043-with-nginx","status":"publish","type":"post","link":"https:\/\/jirak.net\/wp\/addressing-the-php-fpm-vulnerability-cve-2019-11043-with-nginx\/","title":{"rendered":"Addressing the PHP-FPM Vulnerability (CVE-2019-11043) with NGINX"},"content":{"rendered":"<p>Addressing the PHP-FPM Vulnerability (CVE-2019-11043) with NGINX<\/p>\n<p>A recently reported vulnerability, tracked as <span><a target=\"_blank\" href=\"https:\/\/cve.mitre.org\/cgi-bin\/cvename.cgi?name=CVE-2019-11043\" rel=\"noopener noreferrer\">CVE-2019-11043<\/a><\/span>, can affect websites that use PHP&#8209;FPM to execute PHP pages. PHP&#8209;FPM usage is particularly common at NGINX&#8209;powered websites because NGINX does not have an in&#8209;process PHP runtime. Instead, NGINX acts as a reverse proxy for application servers and process managers such as PHP&#8209;FPM. <\/p>\n<p>The vulnerability lies in PHP&#8209;FPM itself, not NGINX, so the only guaranteed solution is to upgrade to the patched release (or later) of your PHP version: <a target=\"_blank\" href=\"https:\/\/www.php.net\/ChangeLog-7.php#7.1.33\" rel=\"noopener noreferrer\">PHP&nbsp;7.1.33<\/a>, <a target=\"_blank\" href=\"https:\/\/www.php.net\/ChangeLog-7.php#7.2.24\" rel=\"noopener noreferrer\">PHP&nbsp;7.2.24<\/a>, or <a target=\"_blank\" href=\"https:\/\/www.php.net\/ChangeLog-7.php#7.3.11\" rel=\"noopener noreferrer\">PHP&nbsp;7.3.11<\/a>. <\/p>\n<h2>What Is the Nature of the Vulnerability?<\/h2>\n<p>NGINX communicates with PHP&#8209;FPM using the FastCGI protocol. Each FastCGI message contains a set of environment variables. One of these, <code>PATH_INFO<\/code>, is derived from other request parameters. If its value is unexpectedly empty, this can ultimately cause <a target=\"_blank\" href=\"https:\/\/bugs.php.net\/bug.php?id=78599\" rel=\"noopener noreferrer\">memory corruption in the PHP&#8209;FPM binary<\/a>. It is possible to exploit this situation and make the PHP&#8209;FPM binary run arbitrary commands on the local server.<\/p>\n<p>This vulnerability can be triggered by a common NGINX configuration, whereby NGINX uses a regular expression in the <a target=\"_blank\" href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_fastcgi_module.html#fastcgi_split_path_info\" rel=\"noopener noreferrer\"><code>fastcgi_split_path_info<\/code><\/a> directive to split the request URI into two parts. One way to trigger the vulnerability is to embed a line break (<code>%0a<\/code>) or carriage return (<code>%0d<\/code>) character into the request URI, which is then not correctly handled by the regular expression. &lt;!&#8211; For further analysis of the vulnerability, see <a target=\"_blank\" href=\"https:\/\/www.tenable.com\/blog\/cve-2019-11043-vulnerability-in-php-fpm-could-lead-to-remote-code-execution-on-nginx\" rel=\"noopener noreferrer\">Tenable blog<\/a>. &#8211;&gt;<\/p>\n<h2>Mitigating Against the Vulnerability<\/h2>\n<p>As mentioned above, the only certain way to address this vulnerability is to upgrade to the patched release (or later) of your PHP version: <a target=\"_blank\" href=\"https:\/\/www.php.net\/ChangeLog-7.php#7.1.33\" rel=\"noopener noreferrer\">PHP&nbsp;7.1.33<\/a>, <a target=\"_blank\" href=\"https:\/\/www.php.net\/ChangeLog-7.php#7.2.24\" rel=\"noopener noreferrer\">PHP&nbsp;7.2.24<\/a>, or <a target=\"_blank\" href=\"https:\/\/www.php.net\/ChangeLog-7.php#7.3.11\" rel=\"noopener noreferrer\">PHP&nbsp;7.3.11<\/a>.<\/p>\n<p>If you are not able to upgrade your PHP binary immediately, there are two partial mitigations you can make:<\/p>\n<ol>\n<li>\n<p>Add a <a target=\"_blank\" href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#try_files\" rel=\"noopener noreferrer\"><code>try_files<\/code><\/a> directive to the NGINX configuration to verify that the <a target=\"_blank\" href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_core_module.html#var_uri\" rel=\"noopener noreferrer\"><code>$uri<\/code><\/a> variable resolves to a file (the PHP script) and reject the request with code <span><code>404<\/code> <code>(Not<\/code> <code>Found)<\/code><\/span> if not:<\/p>\n<pre><code class=\"config\">location ~ [^\/].php(\/|$) {\r\n    fastcgi_split_path_info ^(.+?.php)(\/.*)$;\r\n    fastcgi_param           PATH_INFO $fastcgi_path_info;\r\n    try_files               $uri =404;\r\n    #...\r\n}<\/code><\/pre>\n<p>Note that this mitigation only works if NGINX and PHP&#8209;FPM share the same docroot on the same host.<\/p>\n<\/li>\n<li>\n<p>Add a ModSecurity rule to block requests that contain the suspicious <code>%0a<\/code> or <code>%0d<\/code> character:<\/p>\n<pre><code class=\"config\">SecRule REQUEST_URI \"@rx %0(a|A|d|D)\" \"id:1,phase:1,t:lowercase,deny\"<\/code><\/pre>\n<p>This solution is described in the <a target=\"_blank\" href=\"https:\/\/lab.wallarm.com\/php-remote-code-execution-0-day-discovered-in-real-world-ctf-exercise\/\" rel=\"noopener noreferrer\">Wallarm&#8217;s original report about the vulnerability<\/a>; it may cause false positives and an attacker might still find other ways to exploit the vulnerability.<\/p>\n<\/li>\n<\/ol>\n<h2>Using a Different PHP Process Manager<\/h2>\n<p>Rather than rely on PHP&#8209;FPM, you can use <a target=\"_blank\" href=\"https:\/\/unit.nginx.org\/\" rel=\"noopener noreferrer\">NGINX&nbsp;Unit<\/a> to run your PHP applications. NGINX&nbsp;Unit is a high&#8209;performance, open source application server and process manager that <a target=\"_blank\" href=\"https:\/\/unit.nginx.org\/#supported-app-languages\" rel=\"noopener noreferrer\">supports numerous languages and frameworks<\/a> in addition to PHP. It can auto&#8209;scale PHP applications in response to load, and concurrently run applications that use different PHP runtimes. We provide <a target=\"_blank\" href=\"https:\/\/unit.nginx.org\/installation\/\" rel=\"noopener noreferrer\">binaries, source, and Docker images<\/a> for free.<\/p>\n<p>See the <a target=\"_blank\" href=\"https:\/\/unit.nginx.org\/howto\/wordpress\/\" rel=\"noopener noreferrer\">NGINX&nbsp;Unit documentation<\/a> for instructions on configuring and operating NGINX&nbsp;Unit for WordPress, a popular, high&#8209;traffic, PHP&#8209;powered application. The deployment takes advantage of the <a href=\"https:\/\/www.nginx.com\/blog\/nginx-unit-1-11-0-now-available\/\">support for serving static files<\/a> in <span>NGINX Unit 1.11.0<\/span> and later.<\/p>\n<p>The post <a rel=\"nofollow\" href=\"https:\/\/www.nginx.com\/blog\/php-fpm-cve-2019-11043-vulnerability-nginx\/\">Addressing the PHP-FPM Vulnerability (CVE-2019-11043) with NGINX<\/a> appeared first on <a rel=\"nofollow\" href=\"https:\/\/www.nginx.com\">NGINX<\/a>.<\/p>\n<p>Source: <a href=\"https:\/\/www.nginx.com\/blog\/php-fpm-cve-2019-11043-vulnerability-nginx\/\" target=\"_blank\" rel=\"noopener noreferrer\">Addressing the PHP-FPM Vulnerability (CVE-2019-11043) with NGINX<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Addressing the PHP-FPM Vulnerability (CVE-2019-11043) with NGINX A recently reported vulnerability, tracked as CVE-2019-11043, can affect websites that use PHP&#8209;FPM to execute PHP pages. PHP&#8209;FPM usage is particularly common at NGINX&#8209;powered websites because NGINX does not have an in&#8209;process PHP runtime. Instead, NGINX acts as a reverse proxy for application servers and process managers such as PHP&#8209;FPM. The vulnerability lies in PHP&#8209;FPM itself, not NGINX, so the only guaranteed solution is to upgrade to the patched release (or later) of your PHP version: PHP&nbsp;7.1.33, PHP&nbsp;7.2.24, or PHP&nbsp;7.3.11. What Is the Nature of the Vulnerability? NGINX communicates with PHP&#8209;FPM using the FastCGI protocol. Each FastCGI message contains a set of environment variables. One of these, PATH_INFO, is derived from other request parameters. If its value is unexpectedly empty, this can ultimately cause memory corruption in the PHP&#8209;FPM binary. It is possible <a class=\"mh-excerpt-more\" href=\"https:\/\/jirak.net\/wp\/addressing-the-php-fpm-vulnerability-cve-2019-11043-with-nginx\/\" title=\"Addressing the PHP-FPM Vulnerability (CVE-2019-11043) with NGINX\">[ more&#8230; ]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[169],"tags":[652],"class_list":["post-33607","post","type-post","status-publish","format-standard","hentry","category-news","tag-nginx"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/33607","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/comments?post=33607"}],"version-history":[{"count":1,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/33607\/revisions"}],"predecessor-version":[{"id":33608,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/posts\/33607\/revisions\/33608"}],"wp:attachment":[{"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/media?parent=33607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/categories?post=33607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jirak.net\/wp\/wp-json\/wp\/v2\/tags?post=33607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}