PHP+Nginx在特定环境下远程代码执行漏洞(CVE-2019-11043)

宝塔面板2字数 1851阅读模式

在9 月 14 日至 18 举办的 Real World CTF 中,国外安全研究员 Andrew Danau 在解决一道 CTF 题目时发现,向目标服务器 URL 发送 %0a 符号时,服务返回异常,疑似存在漏洞。

9 月 26 日,PHP 官方发布漏洞通告,其中指出:使用 Nginx + php-fpm 的服务器,在部分配置下,存在远程代码执行漏洞(CVE-2019-11043)。并且该配置已被广泛使用,危害较大。
漏洞 PoC 在 10 月 22 日公开。

漏洞描述

Nginx 上 fastcgi_split_path_info 在处理带有 %0a 的请求时,会因为遇到换行符 \n 导致 PATH_INFO 为空。而 php-fpm 在处理 PATH_INFO 为空的情况下,存在逻辑缺陷。攻击者通过精心的构造和利用,可以导致远程代码执行。

影响范围

Nginx + php-fpm 的服务器,在使用如下配置的情况下,都可能存在远程代码执行漏洞。

location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(/.*)$;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_pass   php:9000;
    ...
  }
}

另外,PHP 5.6版本也受此漏洞影响,但目前只能 Crash,不可以远程代码执行:

PHP 7.0 版本
PHP 7.1 版本
PHP 7.2 版本
PHP 7.3 版本

宝塔的nginx+php配置如下:

宝塔配置的nginx+php-fpm配置文件默认包含文件检查配置,不受此漏洞影响。

location ~ [^/]\.php(/|$)
{
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi-72.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include pathinfo.conf;
}

>>pathinfo.conf code:
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
    set $real_script_name $1;
    set $path_info $2;
 }
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;

0x02 漏洞影响

服务器环境为nginx php-fpm,并且nginx的配置像下面这样

location ~ [^/]\.php(/|$) {
  ...
 fastcgi_split_path_info ^(. ?\.php)(/.*)$;
 fastcgi_param PATH_INFO      $fastcgi_path_info;
 fastcgi_pass   php:9000;
  ...
}

解决方案

(宝塔配置的nginx+php-fpm不受此漏洞影响)在nginx中增加一行文件检查配置:

try_files $uri =404;

所以正确的配置就是这样的;

location ~ [^/]\.php(/|$)
{
    try_files $uri =404;
    fastcgi_pass  unix:/tmp/php-cgi-72.sock;
    fastcgi_index index.php;
    include fastcgi.conf;
    include pathinfo.conf;
}

如果不知道代码放在什么地方,我们看图:

PHP+Nginx在特定环境下远程代码执行漏洞(CVE-2019-11043)

宝塔配置的nginx+php-fpm配置文件默认包含文件检查配置,不受此漏洞影响,如果你是lnmp,oneinstack可以看看自己配置这个环境的时候有没有增加检查配置文件的代码。

参考资料

  1. https://bugs.php.net/bug.php?id=78599
  2. https://lab.wallarm.com/php-remo ... world-ctf-exercise/
  3. https://github.com/neex/phuip-fpizdam
  4. https://blog.csdn.net/qq_18501087/article/details/102762421
  5. https://www.bt.cn/bbs/thread-38951-1-1.html

weinxin
我的微信
微信公众号
关注大鸟博客公众号
 
大鸟
  • CVE-2019-11043
评论  2  访客  1  作者  1
    • 张波博客
      张波博客 6

      这个得要注意了,安全无小事呀

        • 大鸟
          大鸟

          @ 张波博客 我看了下自己的配置,发现早已经放了检查代码了。

      匿名

      发表评论

      匿名网友

      :?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

      确定