cvs: phpdoc-zh /chapters security.xml

From: Date: Fri, 03 Jan 2003 11:58:04 +0000
Subject: cvs: phpdoc-zh /chapters security.xml
Groups: php.doc.zh 
Request: Send a blank email to doc-zh+get-959@lists.php.net to get a copy of this message
gregory Fri Jan 3 06:58:04 2003 EDT Modified files: /phpdoc-zh/chapters security.xml Log: Partially Translated!

Index: phpdoc-zh/chapters/security.xml diff -u phpdoc-zh/chapters/security.xml:1.1 phpdoc-zh/chapters/security.xml:1.2 --- phpdoc-zh/chapters/security.xml:1.1 Sat Dec 28 03:02:14 2002 +++ phpdoc-zh/chapters/security.xml Fri Jan 3 06:58:04 2003 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.1 $ --> +<!-- $Revision: 1.2 $ --> <!-- $Author: gregory $ --> <!-- EN-Revision: 1.49 Maintainer: Gregory Status: ready --> <chapter id="security"> @@ -158,64 +158,37 @@ <sect1 id="security.apache"> <title>°²×°Îª Apache Ä£¿é</title> <simpara> - µ± PHP ±»ÓÃ×÷ Apache µÄÄ£¿éʱ£¬Ëü½«¼Ì³Ð Apache µÄÓû§È¨ÏÞ£¨µäÐÍÇé¿öΪÓû§¡°nobody¡±£©¡£Õâ¶Ô°²È«ºÍÊÚȨ»áÓÐһЩ³å»÷¡£ÀýÈ磬Èç¹ûÄúʹÓà PHP À´·ÃÎÊÊý¾Ý¿â£¬³ý·ÇÊý¾Ý¿â±¾ÉíÓÐÄÚ½¨µÄ·ÃÎÊ¿ØÖÆ£¬·ñÔòÄú½«Ê¹µÃÊý¾Ý¿âÄܹ»±»Óû§¡°nobody¡±·ÃÎÊ¡£Õ⽫Òâζ×ÅһЩ¶ñÒâµÄ½Å±¾½«¸üññ·ÃÎʲ¢ÇÒÐÞ¸ÄÊý¾Ý¿â£¬ÉõÖÁ²»ÓÃÓû§ÃûºÍÃÜÂë¡£»òÐíÒ»Ð©ÍøÂçÖ©Öë»áÎÞÒâÖз¢ÏÖÄúµÄÊý¾Ý¿â¹ÜÀíÔ±µÄ¹ÜÀíÒ³Ãæ£¬È»ºóɾ³ýÄúËùÓеÄÊý¾Ý¿â¡£ÕâÊÇÍêÈ«ÓпÉÄܵġ£Äú¿ÉÒÔÀûÓà Apache µÄÈÏÖ¤»úÖÆÀ´·ÀÖ¹ÕâЩµÄ·¢Éú£¬»òÕßÄú¿ÉÒÔÀûÓà LDAP »ò .htaccess ÎļþµÈÀ´Éè¼ÆÄú×Ô¼ºµÄ·ÃÎÊģʽ£¬²¢½«ÕâЩ´úÂë°üº¬ÎªÄú PHP ½Å±¾µÄÒ»²¿·Ö¡£ + µ± PHP ±»ÓÃ×÷ Apache µÄÄ£¿éʱ£¬Ëü½«¼Ì³Ð Apache µÄÓû§È¨ÏÞ£¨µäÐÍÇé¿öΪÓû§¡°nobody¡±£©¡£ + Õ⽫¶Ô°²È«¼°ÊÚȨ»úÖÆ²úÉúһЩ³å»÷¡£ÀýÈ磬Èç¹ûÄúʹÓà PHP À´·ÃÎÊÊý¾Ý¿â£¬³ý·ÇÊý¾Ý¿â±¾ÉíÓÐÄÚ½¨µÄ·ÃÎÊ¿ØÖÆ£¬·ñÔòÄú½«Ê¹µÃÊý¾Ý¿âÄܹ»±»Óû§¡°nobody¡±·ÃÎÊ¡£ÕâÒâζ×ŶñÒâµÄ½Å±¾Äܹ»·ÃÎʲ¢ÐÞ¸ÄÊý¾Ý¿â£¬ÉõÖÁ²»ÐèÒªÓû§ÃûºÍÃÜÂë¡£ÍøÂçºÚ¿ÍÎÞÒâÖзÃÎʵ½ÁËÊý¾Ý¿â¹ÜÀíÔ±µÄ WEB Ò³Ãæ²¢Í¨¹ýÕâÀïɾ³ýËùÓеÄÊý¾Ý¿âÊÇÍêÈ«ÓпÉÄÜ·¢ÉúµÄ¡£Äú¿ÉÒÔÀûÓà Apache µÄÈÏÖ¤»úÖÆÀ´·ÀÖ¹ÕâЩµÄ·¢Éú£¬»òÕßÒ²¿ÉÒÔÀûÓà LDAP »ò .htaccess ÎļþµÈÀ´Éè¼ÆÄú×Ô¼ºµÄ·ÃÎÊģʽ£¬²¢½«ÕâЩ´úÂë°üº¬ÎªÄú PHP ½Å±¾µÄÒ»²¿·Ö¡£ </simpara> <simpara> - Often, once security is established to the point where the PHP user - (in this case, the apache user) has very little risk attached to it, - it is discovered that PHP is now prevented from writing any files - to user directories. Or perhaps it has been prevented from accessing - or changing databases. It has equally been secured from writing - good and bad files, or entering good and bad database transactions. + ͨ³££¬Ò»µ©°²È«»úÖÆ½¨Á¢²¢Ê¹µÃ PHP µÄÓÃÓÚ£¨ÔÚÕâÖÖÇé¿öÏ£¬Îª Apache Óû§£©½öΪ´Ë³Ðµ£ºÜСµÄ·çÏÕʱ£¬ÎÒÃÇ·¢ÏÖ PHP ´Ëʱ±»½ûÖ¹ÍùÓû§Ä¿Â¼Ð´ÈëÈκÎÎļþ£¬»òÕß»¹ÓпÉÄܱ»½ûÖ¹·ÃÎʺ͸ü¸ÄÊý¾Ý¿â¡£ÎÞÂÛ·ÀÖ¹µÄ¶ÔÏóÖÐдÈëÎļþµÄºÃ»µÒÔ¼°½øÈëµÄÊý¾Ý¿âÊÂÎñµÄºÃ»µ£¬Æä°²È«ÐÔ¶¼ÊÇͬµÈµÄ¡£ </simpara> <simpara> - A frequent security mistake made at this point is to allow apache - root permissions, or to escalate apache's abilitites in some other - way. + ÔÚÕâ¸öʱºò£¬Ò»¸öƵ·±³öÏֵݲȫ´íÎóÊǸø Apache root ȨÏÞ£¬»òÕßÓÃÆäËü·½·¨ÌáÉý Apache µÄÄÜÁ¦¡£ </simpara> <simpara> - Escalating the Apache user's permissions to root is extremely - dangerous and may compromise the entire system, so sudo'ing, - chroot'ing, or otherwise running as root should not be considered by - those who are not security professionals. + ¸ø Apache Óû§¸³Óè root ȨÏÞÊǼ°ÆäΣÏյ쬶øÇÒÓпÉÄÜ»áÁ¬ÀÛÕû¸öϵͳ¡£Òò´Ë£¬½øÐÐ sudo¡¢chroot£¬»òÕßÒÔ root Õ˺ÅÔËÐеȲÙ×÷²»Ó¦¸Ã¿¼ÂÇÈÃÄÇЩ·Ç°²È«×¨¼ÒÀ´Ö´ÐС£ </simpara> <simpara> - There are some simpler solutions. By using - <link linkend="ini.open-basedir">open_basedir</link> you can control and restrict what - directories are allowed to be used for PHP. You can also set up - apache-only areas, to restrict all web based activity to non-user, - or non-system, files. + »¹ÓÐһЩ¸ü¼òµ¥µÄÇé¿ö¡£Äú¿ÉÒÔʹÓà <link linkend="ini.open-basedir">open_basedir</link> À´¿ØÖƺÍÏÞÖÆ PHP Äܹ»Ê¹ÓõÄĿ¼¡£Äú»¹¿ÉÒÔ½¨Á¢ Apache µÄרÓÃÇøÓò£¬ÒÔ½«ËùÓлùÓÚ WEB µÄ»î¶¯¶¼ÏÞÖÆµ½·ÇÓû§¡¢ÏµÍ³ºÍÎļþ¡£ </simpara> </sect1> <sect1 id="security.filesystem"> - <title>ÎļþϵͳµÄ°²È«</title> + <title>Îļþϵͳ°²È«</title> <simpara> - PHP is subject to the security built into most server systems with - respect to permissions on a file and directory basis. This allows - you to control which files in the filesystem may be read. Care - should be taken with any files which are world readable to ensure - that they are safe for reading by all users who have access to that - filesystem. - </simpara> - <simpara> - Since PHP was designed to allow user level access to the filesystem, - it's entirely possible to write a PHP script that will allow you - to read system files such as /etc/passwd, modify your ethernet - connections, send massive printer jobs out, etc. This has some - obvious implications, in that you need to ensure that the files - that you read from and write to are the appropriate ones. - </simpara> - <simpara> - Consider the following script, where a user indicates that they'd - like to delete a file in their home directory. This assumes a - situation where a PHP web interface is regularly used for file - management, so the Apache user is allowed to delete files in - the user home directories. + PHP ÊÜ´ó¶àÊý·þÎñÆ÷ϵͳ°²È«»úÖÆµÄ¿ØÖÆ£¬ÕâЩ°²È«»úÖÆÍ¨³£ÊÇ»ùÓÚÎļþºÍĿ¼Ðí¿É»ù´¡µÄ¡£ÕâʹµÃÄú¿ÉÒÔ¿ØÖÆÎļþϵͳÖеÄÄÄЩÎļþ¿ÉÒÔ±»¶ÁÈ¡¡£ÄúÐèÒªÌØ±ð×¢ÒâËùÓÐÈ«¾Ö¿É¶ÁµÄÎļþ£¬Òª±£Ö¤ËùÓзÃÎʸÃÎļþϵͳµÄÓû§¶ÔËüÃǵĶÁÈ¡Êǰ²È«µÄ¡£ + </simpara> + <simpara> + ÓÉÓÚ PHP ÔÚÉè¼ÆµÄʱºò£¬ÔÊÐíÓû§¼¶·ÃÎÊÎļþϵͳ£¬Òò´Ë±àдһ¸ö PHP ½Å±¾Ê¹µÃÄúÄܹ»¶ÁÈ¡ÖîÈç /etc/passwd£¬¸ü¸ÄÄúµÄÒÔÌ«ÍøÁ¬½Ó£¬·¢ËÍ·±ÖصĴòÓ¡»úÈÎÎñµÈÊÇÍêÈ«ÓпÉÄܵġ£ÕâÀïÓÐһЩÃ÷ÏԵĹØÁª£¬ÄúÐèÒª±£Ö¤Äú¶ÁÈ¡ºÍдÈëµÄÊÇÕýÈ·µÄÎļþ¡£ + </simpara> + <simpara> + ÔÚÒÔϽű¾ÖУ¬Ò»¸öÓû§Ï£Íû¸Ã½Å±¾Äܹ»É¾³ýËüÃÇÖ÷Ŀ¼ÖеÄÒ»¸öÎļþ¡£Õâ½ö½öÊǼÙÉèÁËÒ»ÖÖ PHP WEB ½Ó¿Úͨ³£±»ÓÃ×÷Îļþ¹ÜÀíµÄÇé¿ö£¬Òò´Ë Apache Óû§±»ÔÊÐíɾ³ýÓû§Ö÷Ŀ¼µÄÎļþ¡£ </simpara> <para> <example> - <title>±¡ÈõµÄ±äÁ¿¼ì²é½«»áµ¼Ö¡­¡­</title> + <title>±¡ÈõµÄ±äÁ¿¼ìÑ齫µ¼Ö¡­¡­</title> <programlisting role="php"> <![CDATA[ <?php @@ -229,13 +202,9 @@ ]]> </programlisting> </example> - Since the username is postable from a user form, they can submit - a username and file belonging to someone else, and delete files. - In this case, you'd want to use some other form of authentication. - Consider what could happen if the variables submitted were - "../etc/" and "passwd". The code would then effectively read: + ÓÉÓÚÓû§ÃûÊÇ¿ÉÒÔ´ÓÓû§±íµ¥·¢Ë͵ģ¬Òò´ËËûÃÇ¿ÉÒÔÌá½»Ò»¸öÓû§ÃûºÍÊôÓÚÆäËûÈ˵ÄÎļþ£¬Ê¹µÃÕâЩÎļþ±»É¾³ý¡£ÔÚ¸ÃÇé¿öÏ£¬Äú»áÐèҪʹÓÃÁíÍâµÄ±íµ¥À´ÊÚȨ¡£¿¼ÂÇÒ»ÏÂÈç¹û±»Ìá½»µÄ±äÁ¿ÊÇ¡°../etc/¡±ºÍ¡°passwd¡±½«»á·¢Éúʲô£¿Õâ¸öʱºòÆä´úÂë¿ÉÒÔ±»Àí½âΪ£º <example> - <title>Ò»¸öÎļþϵͳ¹¥»÷ʵÀý</title> + <title>Ò»¸öÎļþϵͳ¹¥»÷</title> <programlisting role="php"> <![CDATA[ <?php @@ -250,23 +219,22 @@ ]]> </programlisting> </example> - There are two important measures you should take to prevent these - issues. + ÓÐÁ½ÖÖÄú±ØÐë²ÉÈ¡µÄ´ëÊ©À´±ÜÃâÕâЩÎÊÌâ¡£ <itemizedlist> <listitem> <simpara> - Only allow limited permissions to the PHP web user binary. + ¶Ô PHP WEB Óû§½ö¸³ÓèÓÐÏÞµÄȨÏÞ¡£ </simpara> </listitem> <listitem> <simpara> - Check all variables which are submitted. + ¼ìÑéËùÓÐÌá½»µÄ±äÁ¿¡£ </simpara> </listitem> </itemizedlist> - Here is an improved script: + ÒÔÏÂÊǾ­¹ý¸Ä½øµÄ½Å±¾£º <example> - <title>¸ü¼Ó°²È«¿É¿¿µÄÎļþÃû¼ì²é</title> + <title>¸ü¼Ó°²È«µÄÎļþÃû¼ìÑé</title> <programlisting role="php"> <![CDATA[ <?php @@ -289,12 +257,9 @@ ]]> </programlisting> </example> - However, even this is not without it's flaws. If your authentication - system allowed users to create their own user logins, and a user - chose the login "../etc/", the system is once again exposed. For - this reason, you may prefer to write a more customized check: + ¾¡¹ÜÈç´Ë£¬¸Ã½Å±¾»¹ÊÇÓÐһЩÎÊÌâ¡£Èç¹ûÄúµÄÊÚȨϵͳÔÊÐíÓû§½¨Á¢ËûÃÇ×Ô¼ºµÄÓû§µÇ¼£¬¶øÄ³Óû§Ñ¡ÔñµÇ¼¡°../etc/¡±£¬ÏµÍ³½«±»Ôٴα©Â¶¡£»ùÓÚÕâÒ»µã£¬Äú¿ÉÄܸüÔ¸Òâ±àдһ¸ö¸üºÃµÄ¼ìÑ飺 <example> - <title>¸ü¼Ó°²È«¿É¿¿µÄÎļþÃû¼ì²é</title> + <title>¸ü°²È«µÄÎļþÃû¼ìÑé</title> <programlisting role="php"> <![CDATA[ <?php @@ -313,12 +278,7 @@ </example> </para> <para> - Depending on your operating system, there are a wide variety of files - which you should be concerned about, including device entries (/dev/ - or COM1), configuration files (/etc/ files and the .ini files), - well known file storage areas (/home/, My Documents), etc. For this - reason, it's usually easier to create a policy where you forbid - everything except for what you explicitly allow. + ¸ù¾ÝÄúµÄ²Ù×÷ϵͳµÄ²»Í¬£¬ÄúÐèÒª¿¼ÂÇÐí¶à¸÷ÖÖ¸÷ÑùµÄÎļþ£¬°üÀ¨É豸ÏîÄ¿£¨/dev/ »ò COM1£©£¬ÉèÖÃÎļþ£¨/etc/ ÎļþºÍ .ini Îļþ£©£¬Í¨³£µÄÎļþ´æ´¢Çø£¨/home/£¬My Documents£©µÈ¡£»ùÓÚÕâÒ»µã£¬½¨Á¢Ò»¸ö²ßÂÔ½ûÖ¹ËùÓгýÁËÄúÃ÷È·µÄÊÚȨµÄÐÐΪ¿ÉÄÜÒª¸ü¼òµ¥Ò»Ð©¡£ </para> </sect1>
« previous php.doc.zh (#959) next »