[文章作者:张宴 本文版本:v1.2 最后修改:2010.05.24 转载请注明原文链接:http://blog.zyan.cc/nginx_0day/]

  注:2010年5月23日14:00前阅读本文的朋友,请按目前v1.1版本的最新配置进行设置。

  昨日,80Sec 爆出Nginx具有严重的0day漏洞,详见《Nginx文件类型错误解析漏洞》。只要用户拥有上传图片权限的Nginx+PHP服务器,就有被入侵的可能。

  其实此漏洞并不是Nginx的漏洞,而是PHP PATH_INFO的漏洞,详见:http://bugs.php.net/bug.php?id=50852&edit=1

  例如用户上传了一张照片,访问地址为http://www.domain.com/images/test.jpg,而test.jpg文件内的内容实际上是PHP代码时,通过http://www.domain.com/images/test.jpg/abc.php就能够执行该文件内的PHP代码。

  网上提供的临时解决方法有:

  方法①、修改php.ini,设置cgi.fix_pathinfo = 0;然后重启php-cgi。此修改会影响到使用PATH_INFO伪静态的应用,例如我以前博文的URL:http://blog.zyan.cc/read.php/348.htm 就不能访问了。

  方法②、在nginx的配置文件添加如下内容后重启:if ( $fastcgi_script_name ~ \..*\/.*php ) {return 403;}。该匹配会影响类似 http://www.domain.com/software/5.0/test.php(5.0为目录),http://www.domain.com/goto.php/phpwind 的URL访问。

  方法③、对于存储图片的location{...},或虚拟主机server{...},只允许纯静态访问,不配置PHP访问。例如在金山逍遥网论坛、SNS上传的图片、附件,会传送到专门的图片、附件存储服务器集群上(pic.xoyo.com),这组服务器提供纯静态服务,无任何动态PHP配置。各大网站几乎全部进行了图片服务器分离,因此Nginx的此次漏洞对大型网站影响不大。



  本人再提供一种修改nginx.conf配置文件的临时解决方法,兼容“http://blog.zyan.cc/demo/0day/phpinfo.php/test”的PATH_INFO伪静态,拒绝“http://blog.zyan.cc/demo/0day/phpinfo.jpg/test.php”的漏洞攻击:
location ~* .*\.php($|/)
{
      if ($request_filename ~* (.*)\.php) {
            set $php_url $1;
      }
      if (!-e $php_url.php) {
            return 403;
      }

      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
}


  也可将以下内容写在fcgi.conf文件中,便于多个虚拟主机引用:
if ($request_filename ~* (.*)\.php) {
    set $php_url $1;
}
if (!-e $php_url.php) {
    return 403;
}

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $uri;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;




  附:文章修改历史

  ● [2010年05月21日] [Version 1.0] 新建

  ● [2010年05月23日] [Version 1.1] 针对网友michael提出的“如果构造一个形如/..trojan.jpg/dummy.php/?abcd=1,似乎可以绕过防范的nginx配置”,进行了配置修改,防范了此类情况发生。提供测试的URL如下,拒绝漏洞访问:
  http://blog.zyan.cc/demo/0day/phpinfo.jpg (里面是PHP代码)
  http://blog.zyan.cc/demo/0day/phpinfo.jpg/.php
  http://blog.zyan.cc/demo/0day/phpinfo.jpg/dummy.php
  http://blog.zyan.cc/demo/0day/phpinfo.jpg/dummy.php/?abcd=1

  同时兼容正常的PATH_INFO伪静态请求,测试URL如下:
  http://blog.zyan.cc/demo/0day/phpinfo.php (这是正常的PHP文件)
  http://blog.zyan.cc/demo/0day/phpinfo.php/test
  http://blog.zyan.cc/demo/0day/phpinfo.php/news123.html
  http://blog.zyan.cc/read.php/348.htm

  ● [2010年05月24日] [Version 1.2] 修正文字描述错误。


Tags: , ,



技术大类 » Web服务器 | 评论(659) | 引用(0) | 阅读(151582)
seo Email Homepage
2026-4-29 21:15
You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers.  camino gummies
seo Email Homepage
2026-4-30 14:46
I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.  dax69 login
SEO Email Homepage
2026-4-30 19:51
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info.  dagotogel
도박꾼커뮤니티 Email Homepage
2026-5-1 15:59
플레이 엔터테인먼트는 콘텐츠가 풍부하고 접근성이 좋아 누구나 쉽게 즐길 수 있어요. 특히 이벤트 참여 시 다양한 보상과 재미를 동시에 경험할 수 있어서 반복적으로 방문하게 되는 매력이 있습니다. https://www.safenori1.com/safeplay
seo Email Homepage
2026-5-2 17:52
I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.  dax69 login
Hunter Email
2026-5-3 13:56
Attractive section of content. I just stumbled upon your website and in accession capital to assert that I acquire actually enjoyed account your blog posts. Anyway I will be subscribing to your augment and even I achievement you access consistently fast.
new lsm99
SEO Email Homepage
2026-5-3 19:27
I found so many interesting stuff in your blog especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the enjoyment here! keep up the good work...  kudahoki
seo Email Homepage
2026-5-4 16:21
Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that.  fujiwin88
seo Email Homepage
2026-5-4 18:54
I wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post.  Organic Modern Sleeper Sofa
도박꾼커뮤니티 Email Homepage
2026-5-5 11:50
온라인슬롯, 슬롯사이트, 먹튀검증, 온라인카지노, 토토사이트, 카지노 커뮤니티, 슬롯커뮤니티, 무료슬롯체험, 온라인바카라, 에볼루션카지노, 프라그마틱슬롯 https://www.safenori1.com/safeplay
SEO Email Homepage
2026-5-5 18:07
I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.  dagotogel
bimanoma
2026-5-5 20:51
这篇笔记对当年 Nginx + PHP 环境下的安全问题梳理得很清晰,尤其是把问题根源指出在 PHP 的 PATH_INFO 解析上,而不是简单归咎于 Nginx,这一点很有价值 insurance
SEIG Email
2026-5-7 19:10
Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post.  toto
SEI Email
2026-5-7 20:48
I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here.  エアコンクリーニング 大阪市
SEI Email
2026-5-7 20:57
Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our.  bandar slot gacor
thsdhrhd Email Homepage
2026-5-8 21:14
It is an honor to visit this excellent site. I found my time here truly rewarding, thanks to its user-friendly structure and the abundance of resources that many people need and can relate to. I hope more people will visit this site and have the opportunity to receive positive energy just like I did.If you happen to experience muscle pain in your shoulders and neck due to long hours of computer work, I recommend visiting the Massage Info site. They share various massage-related information, self-massage techniques, and job openings for professional massage therapists, so I highly recommend giving it a try. 마사지알바
thsdhrhd Email Homepage
2026-5-8 21:16
Your site is truly full of useful information. Not only is there a wealth of content, but it is also well-organized, making it easy for users to view and acquire, so I was able to gain a lot of information in a short amount of time. My time on this site was truly beneficial and enjoyable. Thank you.If you happen to be experiencing shoulder or back pain due to long hours of work, I would like to introduce a site that shares self-massage techniques to loosen tight muscles with simple movements at home, as well as general knowledge about massage and information regarding professional massage therapists. 스웨디시구인
GSRGS Email
2026-5-9 16:51
Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our.  situs togel online
seo Email Homepage
2026-5-9 17:53
I am impressed. I don't think Ive met anyone who knows as much about this subject as you do. You are truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. Really, great blog you have got here.  wop slot
SEO Email Homepage
2026-5-9 18:50
I like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed...  แทงวอลเลย์
分页: 32/33 第一页 上页 27 28 29 30 31 32 33 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]