在PHP中使用FastCGI解析漏洞及修复方案
Jun 06, 2016 pm 07:37 PM这篇文章主要介绍了在PHP中使用FastCGI解析漏洞及修复方案的相关资料,需要的朋友可以参考下
Nginx默认是以CGI的方式支持PHP解析的,普遍的做法是在Nginx配置文件中通过正则匹配设置SCRIPT_FILENAME。当访问这个URL时,$fastcgi_script_name会被设置为“phpinfo.jpg/1.php”,然后构造成SCRIPT_FILENAME传递给PHP CGI。如果PHP中开启了fix_pathinfo这个选项,PHP会认为SCRIPT_FILENAME是phpinfo.jpg,而1.php是PATH_INFO,所以就会将phpinfo.jpg作为PHP文件来解析了。
漏洞危害:
WebServer Fastcgi配置不当,会造成其他文件(例如css,js,jpg等静态文件)被当成php脚本解析执行。当用户将恶意脚本webshell改为静态文件上传到webserver传递给后端php解析执行后,会让攻击者获得服务器的操作权限。
修复方案:
(Nginx用户可以选择方案一或方案二,IIS用户请使用方案一)
方案一,修改php.ini文件,将cgi.fix_pathinfo的值设置为0。完成后请重启PHP和NGINX(IIS)。
方案二,在Nginx配置文件中添加以下代码:
复制代码 代码如下:
if ( $fastcgi_script_name ~ \..*\/.*php ) {
return 403;
}
这行代码的意思是当匹配到类似test.jpg/a.php的URL时,将返回403错误代码。修改完成后请重启Nginx。

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Jailbreak any large model in 20 steps! More 'grandma loopholes' are discovered automatically

How to solve common file upload vulnerabilities in PHP language development?

Buffer overflow vulnerability in Java and its harm

The OpenAI DALL-E 3 model has a vulnerability that generates 'inappropriate content.' A Microsoft employee reported it and was slapped with a 'gag order.'

Comma operator vulnerabilities and protective measures in Java

How to configure and optimize FastCGI in Nginx

Very comprehensive! Summary of common PHP vulnerability codes!

Lenovo has issued a patch in May, Phoenix UEFI firmware vulnerability disclosed: affecting hundreds of Intel PC CPU models
