Home php教程 php手册 在PHP中使用FastCGI解析漏洞及修复方案

在PHP中使用FastCGI解析漏洞及修复方案

Jun 06, 2016 pm 07:37 PM
fastcgi loopholes

这篇文章主要介绍了在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。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Jailbreak any large model in 20 steps! More 'grandma loopholes' are discovered automatically Jailbreak any large model in 20 steps! More 'grandma loopholes' are discovered automatically Nov 05, 2023 pm 08:13 PM

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

How to solve common file upload vulnerabilities in PHP language development? How to solve common file upload vulnerabilities in PHP language development? Jun 10, 2023 am 11:10 AM

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

Buffer overflow vulnerability in Java and its harm Buffer overflow vulnerability in Java and its harm Aug 09, 2023 pm 05:57 PM

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.' 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.' Feb 04, 2024 pm 02:40 PM

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 Comma operator vulnerabilities and protective measures in Java Aug 10, 2023 pm 02:21 PM

Comma operator vulnerabilities and protective measures in Java

How to configure and optimize FastCGI in Nginx How to configure and optimize FastCGI in Nginx May 21, 2023 am 08:16 AM

How to configure and optimize FastCGI in Nginx

Very comprehensive! Summary of common PHP vulnerability codes! Very comprehensive! Summary of common PHP vulnerability codes! Jan 20, 2023 pm 02:22 PM

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 Lenovo has issued a patch in May, Phoenix UEFI firmware vulnerability disclosed: affecting hundreds of Intel PC CPU models Jun 22, 2024 am 10:27 AM

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

See all articles