[文章作者:张宴 本文版本: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服务器 | 评论(93) | 引用(0) | 阅读(131400)
Minion89
2022-5-9 17:49
This is really great addition. I have read this great article. Thanks for sharing information about it. I really like that.infected days
Lucky cola
2024-2-7 13:31
Immerse yourself in the ultimate gaming universe.
Lucky cola
seo
2024-11-7 20:30
I would say that this is a a great post of a great person, i'm pleased to see this.  mio ip
sasasa Email
2024-11-7 20:40
This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform!  https://matchshowbulletin.com/
seo
2024-11-9 18:40
ビットコインを使用してカジノゲームを楽しむことは、匿名性を保持しつつ迅速な取引を可能にします。選択したカジノがビットコインに対応しているかは、そのウェブサイトの支払い方法セクションで確認できます。入金の最小額や最大額はカジノごとに異なり、具体的な数値は利用規約で提供されています。ビットコインを使った出金は、一般に他の方法よりも迅速に処理されるため、資金の受け取りが速いです。利用可能なゲームには、スロット、テーブルゲーム、ライブディーラーゲームが含まれ、多様なエンターテイメントが提供されています。ボーナスやプロモーションはビットコイン利用者も対象であり、特典はプラットフォームによって異なります。安全性については、ライセンスを持つカジノを選ぶことで個人情報と資金の保護が強化されます。ビットコインの価値変動は、利用時の損得に影響を及ぼす可能性があるため、市場を注意深く観察することが重要です。カジノによってはビットコイン専用のゲームを提供している場合もあり、これらのゲームは特にビットコインユーザー向けにデザインされています。カスタマーサポートは、ビットコイン取引に関する疑問や問題に対応し、安心してプレイできるサポート体制が整っています。  ビットカジノ
aaa Email
2024-11-9 19:39
Decentralized betting platforms facilitate peer-to-peer wagering without a central authority by utilizing blockchain technology. Crypto casinos operate on smart contracts to ensure transparency and fairness in betting outcomes. Users typically must use cryptocurrencies, such as Bitcoin or Ethereum, to place bets on these platforms. Transaction times on decentralized betting platforms can vary but are generally faster than traditional online casinos due to blockchain efficiency. The security of decentralized betting platforms is enhanced through cryptography and decentralized ledger technology, making fraud and hacking attempts more difficult. Privacy on these platforms is higher as personal information is not centrally stored. Decentralized betting platforms often offer lower fees than their centralized counterparts due to the elimination of intermediaries. Winnings on these platforms are usually paid out in cryptocurrency, which can be subject to market volatility. Regulatory status of decentralized betting varies by jurisdiction, with some countries having clear guidelines while others remain ambiguous. To start using a decentralized betting platform, users typically need to create a digital wallet and purchase cryptocurrency. The fairness of games on decentralized betting platforms is often verifiable through transparent algorithms and smart contracts. Popular games on these platforms include sports betting, casino games like poker and slots, and event-based wagering. Liquidity on decentralized betting platforms can sometimes be lower than centralized casinos, affecting bet sizes and payouts. User experience can vary widely with some platforms offering user-friendly interfaces while others may require technical knowledge. Bonuses and promotions may be available but can differ significantly in terms of type and size from one platform to another. Decentralized betting platforms may offer staking mechanisms, where users can earn rewards by locking in their tokens. Community governance is a feature of some platforms, allowing token holders to vote on changes or improvements. The impact of network congestion, especially on platforms built on Ethereum, can lead to increased transaction fees and slower processing times. Innovations in decentralized betting include the integration of non-fungible tokens (NFTs) for unique betting experiences or rewards. Cross-chain functionality is being explored to enhance interoperability among different blockchain networks for betting activities. The scalability of decentralized betting platforms is continually improving with developments in blockchain technology. Security audits are crucial for ensuring the integrity and safety of smart contracts used in crypto casinos. Partnerships with sports leagues or teams are emerging as a way for decentralized betting platforms to increase legitimacy and attract users. The potential for decentralized autonomous organizations (DAOs) to manage some platforms introduces a new level of community-driven operation and decision-making. Environmental impact concerns related to the energy consumption of blockchain networks are prompting some platforms to consider more sustainable solutions. Market research indicates a growing interest among bettors in the autonomy and privacy offered by decentralized betting platforms. Customer support varies, with some platforms providing comprehensive assistance and others offering minimal guidance.  decentralized betting platform
seo
2024-11-10 18:53
I would say that this is a a great post of a great person, i'm pleased to see this.  All Season Tires Ottawa
seo
2024-11-10 20:00
Awesome post. Typically the put up can affect a considerable amount of instant concerns our the community. We tend to can't be uninvolved towards such concerns. This unique put up will provide good ideas not to mention strategies. Especially instructive not to mention efficient.  คาสิโน
seo
2024-11-10 21:41
This is usually a wonderful recommendations primarily so that you can all those a novice to blogosphere, limited plus genuine information… With thanks to get spreading brussels. Very important learn posting.  bukowina.org.ua
seo
2024-11-11 18:33
As comprehensive home design software, Arcadium supports designers in creating spaces that are both visually stunning and highly functional. Its versatile tools make it easier to develop plans that align with client visions while maintaining professional standards./  Bathroom design tool
seo
2024-11-12 18:37
Appraisal assert who that is the an ideal put up from a amazing someone, so i am pleased to check out this unique.  Bpi Net Empresa
seo
2024-11-14 18:56
Appraisal assert who that is the an ideal put up from a amazing someone, so i am pleased to check out this unique.  Property to Rent Nigeria
seo
2024-11-20 23:12
I just concept it will be an example to write incase everyone else was basically experiencing difficulity considering and yet I'm sure a little bit of suspicious considerably more than simply morning allowed to position manufacturers not to mention talks about concerning in this case.  iptv uk
分页: 5/5 第一页 上页 1 2 3 4 5 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]