35

php-fpm在nginx特定环境下的任意代码执行漏洞(CVE-2019-11043)

 4 years ago
source link: https://www.tuicool.com/articles/QNjuyuU
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

目录

0x01 漏洞介绍

0x02 漏洞影响

0x03 漏洞复现

0x01 漏洞介绍

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

在nginx上, fastcgi_split_path_info处 理带有 %0a 的请求时,会因为遇到换行符 \n ,导致 PATH_INFO 为空,而在php-fpm对 PATH_INFO 进行处理时,对其值为空时的处理存在逻辑问题,从而导致远程代码执行漏洞

在fpm_main.c文件的第1150行代码可以很明显的看出来,问题的所在

https://github.com/php/php-src/blob/master/sapi/fpm/fpm/fpm_main.c#L1150
nmqyyaB.jpg!web

file

0x02 漏洞影响

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

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 版本
BjymAnF.jpg!web

file

如果使用了nginx官方提供的默认配置,将会收到影响

https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
NRva6jR.jpg!web

file

M7VJ3qJ.jpg!web

file

0x03 漏洞复现

在vulhub上已经有了可以利用的漏洞环境,直接pull下来进行复现即可

使用的exp是国外研究员的go版本的

https://github.com/neex/phuip-fpizdam

自己去pull环境就可以了

RVRju2Y.jpg!web

file

完后就是复现操作

访问 http://your-ip:8080/index.php

7nmiAjU.jpg!web

file

然后我们使用vulhub中使用的go版本的exp

先安装 golang 环境

Bb2ARjv.jpg!web

file

然后将exp部署到本地并利用

bQvyEvv.jpg!web

file

eIzMZbi.jpg!web

file

成功利用

b26vI3Q.jpg!web

file

ZzAnq2q.jpg!web

file

这里还需要注意一下,由于只有部分php-fpm子进程受到了污染,所以请多执行几次命令

文章首发公众号:无心的梦呓(wuxinmengyi)

这是一个记录红队学习、信安笔记,个人成长的公众号

扫码关注即可

BBVZZbe.jpg!web

file


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK