<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[张宴的博客]]></title> 
<link>http://zyan.cc/index.php</link> 
<description><![CDATA[Web系统架构与底层研发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[张宴的博客]]></copyright>
<item>
<link>http://zyan.cc/nginx_0day/</link>
<title><![CDATA[再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>张宴 &lt;net@s135.com&gt;</author>
<category><![CDATA[Web服务器]]></category>
<pubDate>Fri, 21 May 2010 10:46:17 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/</guid> 
<description>
<![CDATA[ 
	　　[文章作者：张宴 本文版本：v1.2 最后修改：<span style="color: #FF0000;">2010.05.24</span> 转载请注明原文链接：<a href="http://blog.zyan.cc/nginx_0day/" target="_blank">http://blog.zyan.cc/nginx_0day/</a>]<br/><br/>　　注：2010年5月23日14:00前阅读本文的朋友，请按目前v1.1版本的最新配置进行设置。<br/><br/>　　昨日，80Sec 爆出Nginx具有严重的0day漏洞，详见《<a href="http://www.80sec.com/nginx-securit.html" target="_blank">Nginx文件类型错误解析漏洞</a>》。只要用户拥有上传图片权限的Nginx+PHP服务器，就有被入侵的可能。<br/><br/>　　其实此漏洞并不是Nginx的漏洞，而是PHP PATH_INFO的漏洞，详见：<a href="http://bugs.php.net/bug.php?id=50852&edit=1" target="_blank">http://bugs.php.net/bug.php?id=50852&edit=1</a><br/><br/>　　例如用户上传了一张照片，访问地址为<a href="http://www.domain.com/images/test.jpg" target="_blank">http://www.domain.com/images/test.jpg</a>，而test.jpg文件内的内容实际上是PHP代码时，通过<a href="http://www.domain.com/images/test.jpg/abc.php" target="_blank">http://www.domain.com/images/test.jpg/abc.php</a>就能够执行该文件内的PHP代码。<br/><br/>　　网上提供的临时解决方法有：<br/><br/>　　方法①、修改php.ini，设置cgi.fix_pathinfo = 0;然后重启php-cgi。此修改会影响到使用PATH_INFO伪静态的应用，例如我以前博文的URL：<a href="http://blog.zyan.cc/read.php/348.htm" target="_blank">http://blog.zyan.cc/read.php/348.htm</a> 就不能访问了。<br/><br/>　　方法②、在nginx的配置文件添加如下内容后重启：if ( $fastcgi_script_name ~ &#92;..*&#92;/.*php ) &#123;return 403;&#125;。该匹配会影响类似 <a href="http://www.domain.com/software/5.0/test.php" target="_blank">http://www.domain.com/software/5.0/test.php</a>（5.0为目录），<a href="http://www.domain.com/goto.php/phpwind" target="_blank">http://www.domain.com/goto.php/phpwind</a> 的URL访问。<br/><br/>　　方法③、对于存储图片的location&#123;...&#125;，或虚拟主机server&#123;...&#125;，只允许纯静态访问，不配置PHP访问。例如在金山逍遥网论坛、SNS上传的图片、附件，会传送到专门的图片、附件存储服务器集群上（pic.xoyo.com），这组服务器提供纯静态服务，无任何动态PHP配置。各大网站几乎全部进行了图片服务器分离，因此Nginx的此次漏洞对大型网站影响不大。<br/><br/><hr/><br/>　　本人再提供一种修改nginx.conf配置文件的临时解决方法，兼容“<a href="http://blog.zyan.cc/demo/0day/phpinfo.php/test" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.php/test</a>”的PATH_INFO伪静态，拒绝“<a href="http://blog.zyan.cc/demo/0day/phpinfo.jpg/test.php" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.jpg/test.php</a>”的漏洞攻击：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">location ~* .*&#92;.php($&#124;/)<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($request_filename ~* (.*)&#92;.php) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set $php_url $1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!-e $php_url.php) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 403;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_pass&nbsp;&nbsp;127.0.0.1:9000;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_index index.php;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;include fcgi.conf;<br/>&#125;</div><br/><br/>　　也可将以下内容写在fcgi.conf文件中，便于多个虚拟主机引用：<br/><div style="border-left: 0px dashed #D6C094; margin: 5px; padding: 3px; margin-bottom:0px; border: 1px dashed #00a0c6; background-color: #ffffff;">if ($request_filename ~* (.*)&#92;.php) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;set $php_url $1;<br/>&#125;<br/>if (!-e $php_url.php) &#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return 403;<br/>&#125;<br/><br/>fastcgi_param&nbsp;&nbsp;GATEWAY_INTERFACE&nbsp;&nbsp;CGI/1.1;<br/>fastcgi_param&nbsp;&nbsp;SERVER_SOFTWARE&nbsp;&nbsp;&nbsp;&nbsp;nginx;<br/><br/>fastcgi_param&nbsp;&nbsp;QUERY_STRING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $query_string;<br/>fastcgi_param&nbsp;&nbsp;REQUEST_METHOD&nbsp;&nbsp;&nbsp;&nbsp; $request_method;<br/>fastcgi_param&nbsp;&nbsp;CONTENT_TYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $content_type;<br/>fastcgi_param&nbsp;&nbsp;CONTENT_LENGTH&nbsp;&nbsp;&nbsp;&nbsp; $content_length;<br/><br/>fastcgi_param&nbsp;&nbsp;SCRIPT_FILENAME&nbsp;&nbsp;&nbsp;&nbsp;$document_root$fastcgi_script_name;<br/>fastcgi_param&nbsp;&nbsp;SCRIPT_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$uri;<br/>fastcgi_param&nbsp;&nbsp;REQUEST_URI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$request_uri;<br/>fastcgi_param&nbsp;&nbsp;DOCUMENT_URI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $document_uri;<br/>fastcgi_param&nbsp;&nbsp;DOCUMENT_ROOT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$document_root;<br/>fastcgi_param&nbsp;&nbsp;SERVER_PROTOCOL&nbsp;&nbsp;&nbsp;&nbsp;$server_protocol;<br/><br/>fastcgi_param&nbsp;&nbsp;REMOTE_ADDR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$remote_addr;<br/>fastcgi_param&nbsp;&nbsp;REMOTE_PORT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$remote_port;<br/>fastcgi_param&nbsp;&nbsp;SERVER_ADDR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$server_addr;<br/>fastcgi_param&nbsp;&nbsp;SERVER_PORT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$server_port;<br/>fastcgi_param&nbsp;&nbsp;SERVER_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$server_name;<br/><br/># PHP only, required if PHP was built with --enable-force-cgi-redirect<br/>fastcgi_param&nbsp;&nbsp;REDIRECT_STATUS&nbsp;&nbsp;&nbsp;&nbsp;200;</div><br/><br/><hr/><br/>　　<strong>附：文章修改历史</strong><br/><br/>　　● [2010年05月21日] [Version 1.0] 新建<br/><br/>　　● [2010年05月23日] [Version 1.1] 针对网友michael提出的“如果构造一个形如/..trojan.jpg/dummy.php/?abcd=1，似乎可以绕过防范的nginx配置”，进行了配置修改，防范了此类情况发生。提供测试的URL如下，拒绝漏洞访问：<br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.jpg" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.jpg</a> （里面是PHP代码）<br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.jpg/.php" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.jpg/.php</a><br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.jpg/dummy.php" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.jpg/dummy.php</a><br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.jpg/dummy.php/?abcd=1" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.jpg/dummy.php/?abcd=1</a><br/><br/>　　同时兼容正常的PATH_INFO伪静态请求，测试URL如下：<br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.php" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.php</a> （这是正常的PHP文件）<br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.php/test" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.php/test</a><br/>　　<a href="http://blog.zyan.cc/demo/0day/phpinfo.php/news123.html" target="_blank">http://blog.zyan.cc/demo/0day/phpinfo.php/news123.html</a><br/>　　<a href="http://blog.zyan.cc/read.php/348.htm" target="_blank">http://blog.zyan.cc/read.php/348.htm</a><br/><br/>　　● [2010年05月24日] [Version 1.2] 修正文字描述错误。<br/><br/>Tags - <a href="http://zyan.cc/tags/nginx/" rel="tag">nginx</a> , <a href="http://zyan.cc/tags/php/" rel="tag">php</a> , <a href="http://zyan.cc/tags/0day/" rel="tag">0day</a>
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5964</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>boss &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 11:24:44 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5964</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5965</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>pahud &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 11:56:39 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5965</guid> 
<description>
<![CDATA[ 
	其實就等於這樣對吧&nbsp;&nbsp; location ~ .*\.(php&#124;php5)?$&nbsp;&nbsp; &#123;&nbsp;&nbsp;&nbsp;&nbsp; if (!-f $request_filename) &#123; return 404; break; &#125;&nbsp;&nbsp; &#125;
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5966</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>啊空 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 11:59:04 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5966</guid> 
<description>
<![CDATA[ 
	向高人学习！我是陈啊空！！！
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5967</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>reus &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 12:53:47 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5967</guid> 
<description>
<![CDATA[ 
	只要把方法二放到fastcgi匹配的那个if block里面就行，像你说的那个URI，不是以php结尾，是不会被pass的
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5968</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>小陈 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 13:44:19 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5968</guid> 
<description>
<![CDATA[ 
	支持!!<br/><br/>第一时间支持了你的正版书!!!<br/><br/>要是做个序列码什么的就好了,可以为一些正版用户提供一些有价值的信息就好了~
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5969</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>爱月 &lt;aimoon16@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 14:25:53 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5969</guid> 
<description>
<![CDATA[ 
	爱月从新疆局域网回归中国广域网，向老朋友问候一下~<br/><br/>听说张大出书啦？~改天去买本儿~
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5971</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>大碗茶 &lt;kongxps@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 16:32:31 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5971</guid> 
<description>
<![CDATA[ 
	这个漏洞在 php-fpm 0.6版本中已经不存在了吧，而且php-fpm 0.6也发布了好长时间了，建议作者更新php-fpm
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5972</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>qwe &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 16:43:26 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5972</guid> 
<description>
<![CDATA[ 
	第2种方法加入后重其提示<br/>[emerg]: &quot;if&quot; directive is not allowed here in /usr/local/webserver/nginx/conf/nginx.conf:75<br/>75句也就是if ( $fastcgi_script_name ~ \..*\/.*php ) &#123;return 403;&#125;这句，<br/>你提供的方法也出现同样提示<br/><br/>location ~* .*\.php($&#124;/)<br/>&#123;<br/>这句是77句<br/><br/>[emerg]: &quot;location&quot; directive is not allowed here in /usr/local/webserver/nginx/conf/nginx.conf:77
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5973</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>暗黑游侠 &lt;anheiyouxia@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Fri, 21 May 2010 18:20:03 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5973</guid> 
<description>
<![CDATA[ 
	张老师果然是对nginx有深入的研究啊，让我自愧不如<br/>
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5974</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>bsd &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 22 May 2010 01:23:36 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5974</guid> 
<description>
<![CDATA[ 
	set $fn $fastcgi_script_name;<br/>set $cF &#039;cF&#039;;<br/><br/>if ($fn ~ &quot;^([^.]+?\.php)&quot;)<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set $cF $1;<br/>&#125;<br/><br/>if ($cF = &#039;cF&#039;)<br/>&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 444;<br/>&#125;<br/><br/>这种方式是否可行？
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5975</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>aa &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 22 May 2010 01:32:27 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5975</guid> 
<description>
<![CDATA[ 
	php-fpm的老漏洞，今年1月就有人发现了
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5976</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>吕滔 &lt;admin@lvtao.net&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 22 May 2010 02:13:18 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5976</guid> 
<description>
<![CDATA[ 
	大哥比我大一岁，在技术方面却比我高出不知道多少层，实在是佩服。<br/><br/>刚接触linux 以后还请多多指教
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5977</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>风往北吹 &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 22 May 2010 03:25:08 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5977</guid> 
<description>
<![CDATA[ 
	php-fpm-0.6没有这个漏洞
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5978</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>michael &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 22 May 2010 06:01:06 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5978</guid> 
<description>
<![CDATA[ 
	问一下，如果构造一个形如/..trojan.jpg/dummy.php/?abcd=1，似乎可以绕过防范的nginx配置。站长你觉得呢？
]]>
</description>
</item><item>
<link>http://zyan.cc/nginx_0day/#blogcomment5980</link>
<title><![CDATA[[评论] 再提供一种解决Nginx文件类型错误解析漏洞的方法]]></title> 
<author>daniel.lin &lt;daniel.lin.go@gmail.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Sat, 22 May 2010 07:44:42 +0000</pubDate> 
<guid>http://zyan.cc/nginx_0day/#blogcomment5980</guid> 
<description>
<![CDATA[ 
	楼上的说的没错，最最彻底的还是<br/><br/>location ~ \/upload_folder\/.*\.php.* &#123;<br/>return 403<br/>&#125;
]]>
</description>
</item>
</channel>
</rss>