cvs: phpdoc-ja /chapters security.xml
| From: | Rui Hirokawa | Date: | Sat, 25 May 2002 02:00:10 +0000 |
| Subject: | cvs: phpdoc-ja /chapters security.xml | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969345834@lists.php.net to get a copy of this message | ||
hirokawa Fri May 24 22:00:10 2002 EDT
Modified files:
/phpdoc-ja/chapters security.xml
Log:
translation updated.
Index: phpdoc-ja/chapters/security.xml diff -u phpdoc-ja/chapters/security.xml:1.21 phpdoc-ja/chapters/security.xml:1.22 --- phpdoc-ja/chapters/security.xml:1.21 Sat Mar 30 10:21:24 2002 +++ phpdoc-ja/chapters/security.xml Fri May 24 22:00:10 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.21 $ --> +<!-- $Revision: 1.22 $ --> <chapter id="security"> <title>ã»ãã¥ãªãã£</title> @@ -459,7 +459,6 @@ <![CDATA[ <?php $username = $HTTP_SERVER_VARS['REMOTE_USER']; // èªè¨¼æ©æ§ã使ç¨ãã - $homedir = "/home/$username"; if (!ereg('^[^./][^/]*$', $userfile)) @@ -467,7 +466,6 @@ if (!ereg('^[^./][^/]*$', $username)) die('bad username'); // å¦çãããçµäºã - //etc... ?> ]]> @@ -563,7 +561,7 @@ </sect2> <sect2 id="security.database.storage"> - <title>æå·åè¨æ¶ã¢ãã«</title> + <title>ã¹ãã¬ã¼ã¸ã®æå·å</title> <simpara> SSL/SSHã«ãã£ã¦ã¯ã©ã¤ã¢ã³ã/ãµã¼ãéã§éä¿¡ããããã¼ã¿ã¯ä¿è·ããã¾ããã ãã¼ã¿ãã¼ã¹ã«ä¿åããããã¼ã¿ã¯ä¿è·ããã¾ãããSSLã¯ããã¾ã§éä¿¡ä¸ã® @@ -605,10 +603,10 @@ $result = pg_exec($connection, $query); if (pg_numrows($result) > 0) { - echo "Welcome, $username!"; + echo "ããããã$username ãã!"; } else { - echo "Authentication failed for $username."; + echo "$username ã®èªè¨¼ã失æãã¾ããã"; } ]]> </programlisting> @@ -681,24 +679,27 @@ </para> <note> <para> - It is common technique to force the SQL parser to ignore the rest of the - query written by the developer with <literal>--</literal> which is the - comment sign in SQL. + SQLãã¼ãµã«ã¯ã¨ãªã®æ®ãã®é¨åãç¡è¦ãããããã«éçºè ã«ãã使ã + ããææ³ã¨ãã¦ãSQLã®ã³ã¡ã³ã符åã§ãã<literal>--</literal>ãã + ãã¾ãã </para> </note> <para> - A feasible way to gain passwords is to circumvent your search result pages. - What the attacker needs only is to try if there is any submitted variable - used in SQL statement which is not handled properly. These filters can be set - commonly in a preceding form to customize <literal>WHERE, ORDER BY, - LIMIT</literal> and <literal>OFFSET</literal> clauses in <literal>SELECT</literal> - statements. If your database supports the <literal>UNION</literal> construct, - the attacker may try to append an entire query to the original one to list - passwords from an arbitrary table. Using encrypted password fields is - strongly encouraged. + ãã¹ã¯ã¼ããåå¾ããæãã¹ãææ®µã«ããµã¤ãã®æ¤ç´¢çµæã®ãã¼ã¸ã欺ã + ã¨ãããã®ãããã¾ããæ»æããè ãå¿ è¦ã¨ãããã®ã¯ãæç¨¿ããã夿° + ã®ä¸ã§SQLå½ä»¤ã§ä½¿ç¨ãããéã«æ£ããæ±ããã¦ããªããã®ããããã©ã + ãã確ãããã ãã§ãããããã®ãã£ã«ã¿ã¯ãé常ã + <literal>SELECT</literal>æã®<literal>WHERE, ORDER BY, + LIMIT</literal>åã³<literal>OFFSET</literal>å¥ãã«ã¹ã¿ãã¤ãºããã + ãã«åã«ç½®ãããå½¢ã§è¨å®ããã¾ãã使ç¨ãããã¼ã¿ãã¼ã¹ã + <literal>UNION</literal>æ§é ããµãã¼ããã¦ããå ´åã + æ»æè ã¯å ã®ã¯ã¨ãªã«ä»»æã®ãã¼ãã«ãããã¹ã¯ã¼ãã®ãªã¹ããåå¾ãã + ã¯ã¨ãªã追å ãããã¨ããããããã¾ããã + æå·åããããã¹ã¯ã¼ããã£ã¼ã«ãã使ç¨ãããã¨ãå¼·ãæ¨å¥¨ããã¾ãã <example> <title> - Listing out articles ... and some passwords (any database server) + è¨äº...ããã¦(å ¨ã¦ã®ãã¼ã¿ãã¼ã¹ãµã¼ãã¼ã®)ããã¤ãã®ãã¹ã¯ã¼ã + ã®ãªã¹ãã表示ãã </title> <programlisting role="php"> <![CDATA[ @@ -709,8 +710,8 @@ ]]> </programlisting> </example> - The static part of the query can be combined with another - <literal>SELECT</literal> statement which reveals all passwords: + ã¯ã¨ãªã®éçãªé¨åã¯ã以ä¸ã®ããã«å ¨ã¦ã®ãã¹ã¯ã¼ããå¤é¨ã«ãããå¥ã® + <literal>SELECT</literal>æã¨çµã¿åããããã¨ãã§ãã¾ãã <informalexample> <programlisting> <![CDATA[ @@ -720,21 +721,22 @@ ]]> </programlisting> </informalexample> - If this query (playing with the <literal>'</literal> and - <literal>--</literal>) were assigned to one of the variables used in - <varname>$query</varname>, the query beast awakened. + (<literal>'</literal>åã³<literal>--</literal>ã使ç¨ãã) + ãã®ã¯ã¨ãªã<varname>$query</varname>ã§ä½¿ç¨ããã夿°ã®ï¼ã¤ã«ä»£å ¥ + ãããå ´åããã®æªæã®ããã¯ã¨ãªãå®è¡ããããã¨ã«ãªãã¾ãã </para> <para> - SQL UPDATEs are also subject to attacking your database. These queries are - also threatened by chopping and appending an entirely new query to it. But - the attacker might fiddle with the <literal>SET</literal> clause. In this - case some schema information must be possessed to manipulate the query - successfully. This can be acquired by examing the form variable names, or - just simply brute forcing. There are not so many naming convention for - fields storing passwords or usernames. + SQL UPDATE ããã¼ã¿ãã¼ã¹ãæ»æããããã«ä½¿ç¨ããã¾ãããããã®ã¯ + ã¨ãªã忍ã¦ããæ°ããã¯ã¨ãªãå ã®ã¯ã¨ãªã«è¿½å ãããã¨ã«ããæ»æ + ãåãã¾ããããããæ»æè ã¯<literal>SET</literal>å¥ã使ç¨ããå¯ + è½æ§ãããã¾ãããã®å ´åãã¯ã¨ãªãæåãããããã«ããã¤ãã®ã¹ãã¼ + ãæ å ±ãä¿æããå¿ è¦ãããã¾ããããã¯ããã©ã¼ã ã®å¤æ°åãç·å½ã + ãæ³ã«ãã調ã¹ããã¨ãã§ãã¾ãããã¹ã¯ã¼ãã¾ãã¯ã¦ã¼ã¶åãä¿åã + ããã£ã¼ã«ãç¨ã®å½åè¨æ³ã¯ããå¤ãã¯ããã¾ããã <example> <title> - From resetting a password ... to gaining more privileges (any database server) + ãã¹ã¯ã¼ãã®ãªã»ãããã ... (å ¨ã¦ã®ãã¼ã¿ãã¼ã¹ãµã¼ãã¼ã§)ããå¤ + ãã®æ¨©éãå¾ãã¾ã§ </title> <programlisting role="php"> <![CDATA[ @@ -742,11 +744,13 @@ ]]> </programlisting> </example> - But a malicious user sumbits the value - <literal>' or uid like'%admin%'; --</literal> to <varname>$uid</varname> to - change the admin's password, or simply sets <varname>$pwd</varname> to - <literal>"hehehe', admin='yes', trusted=100 "</literal> (with a trailing - space) to gain more privileges. Then, the query will be twisted: + ããããæªæã®ããã¦ã¼ã¶ã¯ã管çè ã®ãã¹ã¯ã¼ãã夿´ããããã« + å¤ <literal>' or uid like'%admin%'; --</literal> ã + <varname>$uid</varname> ã«ä»£å ¥ããããã¾ãã¯ãããå¤ãã®æ¨©éãå¾ + ãããã«ãåç´ã«<varname>$pwd</varname> ã«(å¾ãã«ç©ºç½ãä»ãã¦) + <literal>"hehehe', admin='yes', trusted=100 "</literal>ã¨è¨å®ãã + å¯è½æ§ãããã¾ãããã®å ´åããã®ã¯ã¨ãªã¯ä»¥ä¸ã®ããã«æ¹è¬¬ããã¦ã + ã¾ãã¾ãã <informalexample> <programlisting role="php"> <![CDATA[ @@ -760,10 +764,11 @@ </informalexample> </para> <para> - A frightening example how operating system level commands can be accessed - on some database hosts. + æãããä¾ã¨ãã¦ãããã¤ãã®ãã¼ã¿ãã¼ã¹ãã¹ãã®ãªãã¬ã¼ãã£ã³ + ã°ã·ã¹ãã ã¬ãã«ã®ã³ãã³ããã¢ã¯ã»ã¹å¯è½ã¨ãªãæ¹æ³ã示ãã¾ãã <example> - <title>Attacking the database host's operating system (MSSQL Server)</title> + <title>ãã¼ã¿ãã¼ã¹ãã¹ãã®ãªãã¬ã¼ãã£ã³ã°ã·ã¹ãã ãæ»æãã + (MSSQLãµã¼ãã¼)</title> <programlisting role="php"> <![CDATA[ $query = "SELECT * FROM products WHERE id LIKE '%$prod%'"; @@ -771,9 +776,10 @@ ]]> </programlisting> </example> - If attacker submits the value - <literal>a%' exec master..xp_cmdshell 'net user test testpass /ADD' --</literal> - to <varname>$prod</varname>, then the <varname>$query</varname> will be: + æ»æè ããå¤ + <literal>a%' exec master..xp_cmdshell 'net user test testpass + /ADD' --</literal>ã<varname>$prod</varname>, then the + <varname>$query</varname> ã«æç¨¿ããå ´åã以ä¸ã®ããã«ãªãã¾ãã <informalexample> <programlisting role="php"> <![CDATA[ @@ -782,73 +788,77 @@ ]]> </programlisting> </informalexample> - MSSQL Server executes the SQL statements in the batch including a command - to add a new user to the local accounts database. If this application - were running as <literal>sa</literal> and the MSSQLSERVER service is - running with sufficient privileges, the attacker would now have an - account with which to access this machine. + MSSQLãµã¼ãâã¯ãæ°è¦ã¦ã¼ã¶ããã¼ã«ã«ã¢ã«ã¦ã³ãç¨ãã¼ã¿ãã¼ã¹ã«è¿½ + å ããã³ãã³ããå«ãSQLå½ä»¤ããããå®è¡ãã¾ãã + ãã®ã¢ããªã±ã¼ã·ã§ã³ã<literal>sa</literal>ã§å®è¡ããã + MSSQLSERVERãµã¼ãã¹ãå åãªæ¨©éã§å®è¡ããã¦ããå ´åãæ»æè 㯠+ ãã®ãã·ã³ã«ã¢ã¯ã»ã¹ããæ¨©éãæãããã¨ã«ãªãã¾ãã </para> <note> <para> - Some of the examples above is tied to a specific database server. This - does not mean that a similar attack is impossible against other products. - Your database server may be so vulnerable in other manner. + ä¸è¨ã®ããã¤ãã®ä¾ã¯ããã¼ã¿ãã¼ã¹ãµã¼ãã®ç¨®é¡ã«ä¾åãã¦ãã¾ãã + ããã¯ãä»ã®è£½åã«å¯¾ãã¦åæ§ãªæ»æãã§ããªããã¨ãæå³ãããã®ã§ + ã¯ããã¾ããã使ç¨ãã¦ãããã¼ã¿ãã¼ã¹ãä»ã®ææ®µã§æ»æå¯è½ã§ãã + å¯è½æ§ãããã¾ãã </para> </note> <sect3 id="security.database.avoiding"> - <title>Avoiding techniques</title> + <title>åé¿ããæ¹æ³</title> <simpara> - You may plead that the attacker must possess a piece of information - about the database schema in most examples. You are right, but you - never know when and how it can be taken out, and if it happens, - your database may be exposed. If you are using an open source, or - publicly available database handling package, which may belong to a - content management system or forum, the intruders easily produce - a copy of a piece of your code. It may be also a security risk if it - is a poorly designed one. + ã»ã¨ãã©ã®ä¾ã§ã¯æ»æããè ã¯ç¹å®ã®ãã¼ã¿ãã¼ã¹ã®ã¹ãã¼ãã«é¢ã㦠+ è¥å¹²ã®æ å ±ãä¿æãã¦ããå¿ è¦ãããã¨å¼è§£ãããããããã¾ããã + ããã¯æ£ããã§ããããã¤ä½æãããå¤é¨ã«ããããããç¥ããã¨ã¯ã§ + ãã¾ãããããã£ãããã®æ å ±ããããã¨ããã¼ã¿ãã¼ã¹ãå¤é¨ã«é示 + ãããå¯è½æ§ãããã¾ãããªã¼ãã³ã½ã¼ã¹ã¾ãã¯ä¸è¬çã«å ¥æå¯è½ãªãã¼ + ã¿ãã¼ã¹å¦çããã±ã¼ã¸ã使ç¨ãã¦ããå ´å(ããã¯ã³ã³ãã³ãç£çã·ã¹ + ãã ã¾ãã¯ãã©ã¼ã©ã ã«å«ã¾ãã¦ããå¯è½æ§ãããã¾ã)ãä¾µå ¥è ã¯ç°¡å + ã«ä½¿ç¨ããã¦ããã³ã¼ãã®ä¸é¨ãå ¥æãããã¨ãã§ãã¾ãããã®ã³ã¼ã + ã®è¨è¨ãæªãå ´åã«ãã»ãã¥ãªãã£ãªã¹ã¯ãçããå¯è½æ§ãããã¾ãã </simpara> <simpara> - These attacks are mainly based on exploiting the code not being written - with security in mind. Never trust on any kind of input, especially - which comes from the client side, even though it comes from a select box, - a hidden input field or a cookie. The first example shows that such a - blameless query can cause disasters. + ãããã®æ»æã¯ãã»ãã¥ãªãã£ãèæ ®ãã¦æ¸ããã¦ããªãã³ã¼ããæ»æ + ããæ¹æ³ã§ããç¹ã«ã¯ã©ã¤ã¢ã³ãå´ããå ¥åããããããã種é¡ã®å ¥å + ãæ±ºãã¦ä¿¡ç¨ããªãã§ä¸ãããããã¯ãselectããã¯ã¹ãhidden input + ãã£ã¼ã«ããCookieã®å ´åãåæ§ã§ããæåã®ä¾ã¯ããã®ãããªæ¬ ç¹ã® + ãªãã¯ã¨ãªãç ´æ» ããããããããã¨ã示ããã®ã§ãã </simpara> <itemizedlist> <listitem> <simpara> - Never connect to the database as a superuser or as the database owner. - Use always customized users with very limited privileges. + ãã¼ã¿ãã¼ã¹ã«ã¹ã¼ãã¼ã¦ã¼ã¶ã¼ã¾ãã¯ãã¼ã¿ãã¼ã¹ã®ææè ã¨ã㦠+ æ¥ç¶ããªãã§ä¸ããã é常ã«å¶éãããæ¨©éãæããã«ã¹ã¿ãã¤ãº + ãããã¦ã¼ã¶ã常ã«ä½¿ç¨ãã¦ä¸ããã </simpara> </listitem> <listitem> <simpara> - Check if the given input has the expected data type. PHP has - a wide range of input validating functions, from the simplest ones - found in <link linkend="ref.variables">Variable Functions</link> and - in <link linkend="ref.ctype">Character Type Functions</link> - (e.g. <function>is_numeric</function>, <function>ctype_digit</function> - respectively) onwards the - <link linkend="ref.pcre">Perl compatible Regular Expressions</link> - support. + æå®ãããå ¥åãæå¾ ãããã¼ã¿åã§ãããã¨ã確èªãã¦ä¸ããã + PHPã¯ãå¤ãã®ç¨®é¡ã®å ¥åæ¤è¨¼ç¨é¢æ°ãæãã¦ããã + <link linkend="ref.variables">夿°é¢é£ã®é¢æ°</link>ã + <link linkend="ref.ctype">æåå颿°</link>ã«ããç°¡åãªé¢æ° + (ä¾: ããããã<function>is_numeric</function>, + <function>ctype_digit</function>) ãã + <link linkend="ref.pcre">Perläºæã®æ£è¦è¡¨ç¾</link>ã®ãµãã¼ãã¾ + ã§ããã¾ãã </simpara> </listitem> <listitem> <para> - If the application waits for numerical input, consider to verify data - with <function>is_numeric</function>, or silently change its type - using <function>settype</function>, or use its numeric representation - by <function>sprintf</function>. + ã¢ããªã±ã¼ã·ã§ã³ããæ°å¤å ¥åãæå¾ ãã¦ããå ´åããã¼ã¿ã + <function>is_numeric</function>ã§æ¤è¨¼ãããã + <function>settype</function>ã«ããæé»ã®å夿ãè¡ããã + <function>sprintf</function>ã«ããæ°å¤è¡¨ç¾ã使ç¨ãããã¨ãæ¤è¨ + ãã¦ã¿ã¦ä¸ããã <example> - <title>A more secure way to compose a query for paging</title> + <title>ãã¼ã¸ã³ã°ç¨ã®ã¯ã¨ãªãæ§ç¯ããããã®ããå®å ¨ãªæ¹æ³</title> <programlisting role="php"> <![CDATA[ settype($order, 'integer'); $query = "SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET $offset;"; -// please note %d in the format string, using %s would be meaningless +// ãã©ã¼ãããæååã®%dã«æ³¨æãã¦ä¸ããã%sã使ç¨ãã¦ãæå³ãããã¾ããã $query = sprintf("SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET %d;", $offset); ]]> </programlisting> @@ -857,36 +867,40 @@ </listitem> <listitem> <simpara> - Quote each non numeric user input which is passed to the database with - <function>addslashes</function> or <function>addcslashes</function>. - See <link linkend="security.database.storage">the first example</link>. - As the examples shows, quotes burnt into the static part of the query - is not enough, and can be easily hacked. + ãã¼ã¿ãã¼ã¹ã«æ¸¡ãæ°å¤ä»¥å¤ã®ã¦ã¼ã¶å ¥åã + <function>addslashes</function> ã¾ã㯠+ <function>addcslashes</function>ã§ã¯ãªã¼ããã¦ä¸ããã + <link linkend="security.database.storage">æåã®ä¾</link>ãåç § + ãã¦ä¸ãããåæã®ä¾ã示ãããã«ãã¯ã¨ãªã®éçãªé¨åãã¯ãªã¼ã + ããã ãã§ã¯å åã§ã¯ãªããç°¡åã«ã¯ã©ãã¯ããã¦ãã¾ãå¯è½æ§ãã + ãã¾ãã </simpara> </listitem> <listitem> <simpara> - Do not print out any database specific information, especially - about the schema, by fair means or foul. See also <link - linkend="security.errors">Error Reporting</link> and <link - linkend="ref.errorfunc">Error Handling and Logging Functions</link>. + ãã¼ã¿ãã¼ã¹åºæã®æ å ±ãç¹ã«ã¹ãã¼ãã«é¢ããæ å ±ã¯åºåãã¦ã¯ã + ãã¾ããã<link linkend="security.errors">ã¨ã©ã¼åºå</link>ãã + ã³<link linkend="ref.errorfunc">ã¨ã©ã¼å¦çããã³ãã°é¢æ°</link> + ãåç §ä¸ããã </simpara> </listitem> <listitem> <simpara> - You may use stored procedures and previously defined cursors to abstract - data access so that users do not directly access tables or views, but - this solution has another impacts. + ã¦ã¼ã¶ããã¼ãã«ã¾ãã¯ãã¥ã¼ã«ç´æ¥ã¢ã¯ã»ã¹ã§ããªãããã«ã + ãã¼ã¿ã¢ã¯ã»ã¹ãæ½è±¡åãããã¨ãç®çã¨ãã¦ã¹ãã¢ãããã·ã¼ã¸ã£ + åã³äºåã«å®ç¾©ããã«ã¼ã½ã«ã使ç¨ãããã¨ãã§ãã¾ããããã®ã½ãªã¥ã¼ + ã·ã§ã³ã«ã¯ãå¯ä½ç¨ãããã¾ãã </simpara> </listitem> </itemizedlist> <simpara> - Besides these, you benefit from logging queries either within your script - or by the database itself, if it supports. Obviously, the logging is unable - to prevent any harmful attempt, but it can be helpful to trace back which - application has been circumvented. The log is not useful by itself, but - through the information it contains. The more detail is generally better. + ãããã®ã±ã¼ã¹ã«ããã¦ãã¹ã¯ãªããã¾ãã¯ãµãã¼ãããã¦ããå ´å㯠+ ãã¼ã¿ãã¼ã¹èªä½ã§ã¯ã¨ãªã®ãã°ãã¨ããã¨ãæçã§ãã + æããã«ãã°ã¯ç ´å£çãªè¡çºã鲿¢ãããã¨ã¯ã§ãã¾ããããæ»æãã + ãã¢ããªã±ã¼ã·ã§ã³ã追跡ããéã«ã¯æå¹ã§ãããã°èªä½ã¯æçã§ã¯ã + ãã¾ããããå«ã¾ãã¦ããæ å ±ã¯æçã§ããé常ããã詳細ãªãã°ã㨠+ ãæ¹ãè¯ãã§ãããã </simpara> </sect3> </sect2> @@ -1166,7 +1180,7 @@ </para> <para> PHPãé ãããã®ç°¡åãªææ³ãããã¤ããããã·ã¹ãã ã®å¼±ç¹ãè¦ã¤ãã - ãã¨ããæ»æãé å»¶ããããã¨ãã§ããå¯è½æ§ãããã¾ããphp.iniãã¡ + ãã¨ããæ»æãé å»¶ããããã¨ãã§ããå¯è½æ§ãããã¾ãã&php.ini;ãã¡ ã¤ã«ã§expose_php = offã¨è¨å®ãããã¨ã«ãããæ»æè ãå©ç¨å¯è½ãªæ å ±ãæ¸ãããã¨ãå¯è½ã§ãã </para>
Index: phpdoc-ja/chapters/security.xml diff -u phpdoc-ja/chapters/security.xml:1.21 phpdoc-ja/chapters/security.xml:1.22 --- phpdoc-ja/chapters/security.xml:1.21 Sat Mar 30 10:21:24 2002 +++ phpdoc-ja/chapters/security.xml Fri May 24 22:00:10 2002 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<!-- $Revision: 1.21 $ --> +<!-- $Revision: 1.22 $ --> <chapter id="security"> <title>ã»ãã¥ãªãã£</title> @@ -459,7 +459,6 @@ <![CDATA[ <?php $username = $HTTP_SERVER_VARS['REMOTE_USER']; // èªè¨¼æ©æ§ã使ç¨ãã - $homedir = "/home/$username"; if (!ereg('^[^./][^/]*$', $userfile)) @@ -467,7 +466,6 @@ if (!ereg('^[^./][^/]*$', $username)) die('bad username'); // å¦çãããçµäºã - //etc... ?> ]]> @@ -563,7 +561,7 @@ </sect2> <sect2 id="security.database.storage"> - <title>æå·åè¨æ¶ã¢ãã«</title> + <title>ã¹ãã¬ã¼ã¸ã®æå·å</title> <simpara> SSL/SSHã«ãã£ã¦ã¯ã©ã¤ã¢ã³ã/ãµã¼ãéã§éä¿¡ããããã¼ã¿ã¯ä¿è·ããã¾ããã ãã¼ã¿ãã¼ã¹ã«ä¿åããããã¼ã¿ã¯ä¿è·ããã¾ãããSSLã¯ããã¾ã§éä¿¡ä¸ã® @@ -605,10 +603,10 @@ $result = pg_exec($connection, $query); if (pg_numrows($result) > 0) { - echo "Welcome, $username!"; + echo "ããããã$username ãã!"; } else { - echo "Authentication failed for $username."; + echo "$username ã®èªè¨¼ã失æãã¾ããã"; } ]]> </programlisting> @@ -681,24 +679,27 @@ </para> <note> <para> - It is common technique to force the SQL parser to ignore the rest of the - query written by the developer with <literal>--</literal> which is the - comment sign in SQL. + SQLãã¼ãµã«ã¯ã¨ãªã®æ®ãã®é¨åãç¡è¦ãããããã«éçºè ã«ãã使ã + ããææ³ã¨ãã¦ãSQLã®ã³ã¡ã³ã符åã§ãã<literal>--</literal>ãã + ãã¾ãã </para> </note> <para> - A feasible way to gain passwords is to circumvent your search result pages. - What the attacker needs only is to try if there is any submitted variable - used in SQL statement which is not handled properly. These filters can be set - commonly in a preceding form to customize <literal>WHERE, ORDER BY, - LIMIT</literal> and <literal>OFFSET</literal> clauses in <literal>SELECT</literal> - statements. If your database supports the <literal>UNION</literal> construct, - the attacker may try to append an entire query to the original one to list - passwords from an arbitrary table. Using encrypted password fields is - strongly encouraged. + ãã¹ã¯ã¼ããåå¾ããæãã¹ãææ®µã«ããµã¤ãã®æ¤ç´¢çµæã®ãã¼ã¸ã欺ã + ã¨ãããã®ãããã¾ããæ»æããè ãå¿ è¦ã¨ãããã®ã¯ãæç¨¿ããã夿° + ã®ä¸ã§SQLå½ä»¤ã§ä½¿ç¨ãããéã«æ£ããæ±ããã¦ããªããã®ããããã©ã + ãã確ãããã ãã§ãããããã®ãã£ã«ã¿ã¯ãé常ã + <literal>SELECT</literal>æã®<literal>WHERE, ORDER BY, + LIMIT</literal>åã³<literal>OFFSET</literal>å¥ãã«ã¹ã¿ãã¤ãºããã + ãã«åã«ç½®ãããå½¢ã§è¨å®ããã¾ãã使ç¨ãããã¼ã¿ãã¼ã¹ã + <literal>UNION</literal>æ§é ããµãã¼ããã¦ããå ´åã + æ»æè ã¯å ã®ã¯ã¨ãªã«ä»»æã®ãã¼ãã«ãããã¹ã¯ã¼ãã®ãªã¹ããåå¾ãã + ã¯ã¨ãªã追å ãããã¨ããããããã¾ããã + æå·åããããã¹ã¯ã¼ããã£ã¼ã«ãã使ç¨ãããã¨ãå¼·ãæ¨å¥¨ããã¾ãã <example> <title> - Listing out articles ... and some passwords (any database server) + è¨äº...ããã¦(å ¨ã¦ã®ãã¼ã¿ãã¼ã¹ãµã¼ãã¼ã®)ããã¤ãã®ãã¹ã¯ã¼ã + ã®ãªã¹ãã表示ãã </title> <programlisting role="php"> <![CDATA[ @@ -709,8 +710,8 @@ ]]> </programlisting> </example> - The static part of the query can be combined with another - <literal>SELECT</literal> statement which reveals all passwords: + ã¯ã¨ãªã®éçãªé¨åã¯ã以ä¸ã®ããã«å ¨ã¦ã®ãã¹ã¯ã¼ããå¤é¨ã«ãããå¥ã® + <literal>SELECT</literal>æã¨çµã¿åããããã¨ãã§ãã¾ãã <informalexample> <programlisting> <![CDATA[ @@ -720,21 +721,22 @@ ]]> </programlisting> </informalexample> - If this query (playing with the <literal>'</literal> and - <literal>--</literal>) were assigned to one of the variables used in - <varname>$query</varname>, the query beast awakened. + (<literal>'</literal>åã³<literal>--</literal>ã使ç¨ãã) + ãã®ã¯ã¨ãªã<varname>$query</varname>ã§ä½¿ç¨ããã夿°ã®ï¼ã¤ã«ä»£å ¥ + ãããå ´åããã®æªæã®ããã¯ã¨ãªãå®è¡ããããã¨ã«ãªãã¾ãã </para> <para> - SQL UPDATEs are also subject to attacking your database. These queries are - also threatened by chopping and appending an entirely new query to it. But - the attacker might fiddle with the <literal>SET</literal> clause. In this - case some schema information must be possessed to manipulate the query - successfully. This can be acquired by examing the form variable names, or - just simply brute forcing. There are not so many naming convention for - fields storing passwords or usernames. + SQL UPDATE ããã¼ã¿ãã¼ã¹ãæ»æããããã«ä½¿ç¨ããã¾ãããããã®ã¯ + ã¨ãªã忍ã¦ããæ°ããã¯ã¨ãªãå ã®ã¯ã¨ãªã«è¿½å ãããã¨ã«ããæ»æ + ãåãã¾ããããããæ»æè ã¯<literal>SET</literal>å¥ã使ç¨ããå¯ + è½æ§ãããã¾ãããã®å ´åãã¯ã¨ãªãæåãããããã«ããã¤ãã®ã¹ãã¼ + ãæ å ±ãä¿æããå¿ è¦ãããã¾ããããã¯ããã©ã¼ã ã®å¤æ°åãç·å½ã + ãæ³ã«ãã調ã¹ããã¨ãã§ãã¾ãããã¹ã¯ã¼ãã¾ãã¯ã¦ã¼ã¶åãä¿åã + ããã£ã¼ã«ãç¨ã®å½åè¨æ³ã¯ããå¤ãã¯ããã¾ããã <example> <title> - From resetting a password ... to gaining more privileges (any database server) + ãã¹ã¯ã¼ãã®ãªã»ãããã ... (å ¨ã¦ã®ãã¼ã¿ãã¼ã¹ãµã¼ãã¼ã§)ããå¤ + ãã®æ¨©éãå¾ãã¾ã§ </title> <programlisting role="php"> <![CDATA[ @@ -742,11 +744,13 @@ ]]> </programlisting> </example> - But a malicious user sumbits the value - <literal>' or uid like'%admin%'; --</literal> to <varname>$uid</varname> to - change the admin's password, or simply sets <varname>$pwd</varname> to - <literal>"hehehe', admin='yes', trusted=100 "</literal> (with a trailing - space) to gain more privileges. Then, the query will be twisted: + ããããæªæã®ããã¦ã¼ã¶ã¯ã管çè ã®ãã¹ã¯ã¼ãã夿´ããããã« + å¤ <literal>' or uid like'%admin%'; --</literal> ã + <varname>$uid</varname> ã«ä»£å ¥ããããã¾ãã¯ãããå¤ãã®æ¨©éãå¾ + ãããã«ãåç´ã«<varname>$pwd</varname> ã«(å¾ãã«ç©ºç½ãä»ãã¦) + <literal>"hehehe', admin='yes', trusted=100 "</literal>ã¨è¨å®ãã + å¯è½æ§ãããã¾ãããã®å ´åããã®ã¯ã¨ãªã¯ä»¥ä¸ã®ããã«æ¹è¬¬ããã¦ã + ã¾ãã¾ãã <informalexample> <programlisting role="php"> <![CDATA[ @@ -760,10 +764,11 @@ </informalexample> </para> <para> - A frightening example how operating system level commands can be accessed - on some database hosts. + æãããä¾ã¨ãã¦ãããã¤ãã®ãã¼ã¿ãã¼ã¹ãã¹ãã®ãªãã¬ã¼ãã£ã³ + ã°ã·ã¹ãã ã¬ãã«ã®ã³ãã³ããã¢ã¯ã»ã¹å¯è½ã¨ãªãæ¹æ³ã示ãã¾ãã <example> - <title>Attacking the database host's operating system (MSSQL Server)</title> + <title>ãã¼ã¿ãã¼ã¹ãã¹ãã®ãªãã¬ã¼ãã£ã³ã°ã·ã¹ãã ãæ»æãã + (MSSQLãµã¼ãã¼)</title> <programlisting role="php"> <![CDATA[ $query = "SELECT * FROM products WHERE id LIKE '%$prod%'"; @@ -771,9 +776,10 @@ ]]> </programlisting> </example> - If attacker submits the value - <literal>a%' exec master..xp_cmdshell 'net user test testpass /ADD' --</literal> - to <varname>$prod</varname>, then the <varname>$query</varname> will be: + æ»æè ããå¤ + <literal>a%' exec master..xp_cmdshell 'net user test testpass + /ADD' --</literal>ã<varname>$prod</varname>, then the + <varname>$query</varname> ã«æç¨¿ããå ´åã以ä¸ã®ããã«ãªãã¾ãã <informalexample> <programlisting role="php"> <![CDATA[ @@ -782,73 +788,77 @@ ]]> </programlisting> </informalexample> - MSSQL Server executes the SQL statements in the batch including a command - to add a new user to the local accounts database. If this application - were running as <literal>sa</literal> and the MSSQLSERVER service is - running with sufficient privileges, the attacker would now have an - account with which to access this machine. + MSSQLãµã¼ãâã¯ãæ°è¦ã¦ã¼ã¶ããã¼ã«ã«ã¢ã«ã¦ã³ãç¨ãã¼ã¿ãã¼ã¹ã«è¿½ + å ããã³ãã³ããå«ãSQLå½ä»¤ããããå®è¡ãã¾ãã + ãã®ã¢ããªã±ã¼ã·ã§ã³ã<literal>sa</literal>ã§å®è¡ããã + MSSQLSERVERãµã¼ãã¹ãå åãªæ¨©éã§å®è¡ããã¦ããå ´åãæ»æè 㯠+ ãã®ãã·ã³ã«ã¢ã¯ã»ã¹ããæ¨©éãæãããã¨ã«ãªãã¾ãã </para> <note> <para> - Some of the examples above is tied to a specific database server. This - does not mean that a similar attack is impossible against other products. - Your database server may be so vulnerable in other manner. + ä¸è¨ã®ããã¤ãã®ä¾ã¯ããã¼ã¿ãã¼ã¹ãµã¼ãã®ç¨®é¡ã«ä¾åãã¦ãã¾ãã + ããã¯ãä»ã®è£½åã«å¯¾ãã¦åæ§ãªæ»æãã§ããªããã¨ãæå³ãããã®ã§ + ã¯ããã¾ããã使ç¨ãã¦ãããã¼ã¿ãã¼ã¹ãä»ã®ææ®µã§æ»æå¯è½ã§ãã + å¯è½æ§ãããã¾ãã </para> </note> <sect3 id="security.database.avoiding"> - <title>Avoiding techniques</title> + <title>åé¿ããæ¹æ³</title> <simpara> - You may plead that the attacker must possess a piece of information - about the database schema in most examples. You are right, but you - never know when and how it can be taken out, and if it happens, - your database may be exposed. If you are using an open source, or - publicly available database handling package, which may belong to a - content management system or forum, the intruders easily produce - a copy of a piece of your code. It may be also a security risk if it - is a poorly designed one. + ã»ã¨ãã©ã®ä¾ã§ã¯æ»æããè ã¯ç¹å®ã®ãã¼ã¿ãã¼ã¹ã®ã¹ãã¼ãã«é¢ã㦠+ è¥å¹²ã®æ å ±ãä¿æãã¦ããå¿ è¦ãããã¨å¼è§£ãããããããã¾ããã + ããã¯æ£ããã§ããããã¤ä½æãããå¤é¨ã«ããããããç¥ããã¨ã¯ã§ + ãã¾ãããããã£ãããã®æ å ±ããããã¨ããã¼ã¿ãã¼ã¹ãå¤é¨ã«é示 + ãããå¯è½æ§ãããã¾ãããªã¼ãã³ã½ã¼ã¹ã¾ãã¯ä¸è¬çã«å ¥æå¯è½ãªãã¼ + ã¿ãã¼ã¹å¦çããã±ã¼ã¸ã使ç¨ãã¦ããå ´å(ããã¯ã³ã³ãã³ãç£çã·ã¹ + ãã ã¾ãã¯ãã©ã¼ã©ã ã«å«ã¾ãã¦ããå¯è½æ§ãããã¾ã)ãä¾µå ¥è ã¯ç°¡å + ã«ä½¿ç¨ããã¦ããã³ã¼ãã®ä¸é¨ãå ¥æãããã¨ãã§ãã¾ãããã®ã³ã¼ã + ã®è¨è¨ãæªãå ´åã«ãã»ãã¥ãªãã£ãªã¹ã¯ãçããå¯è½æ§ãããã¾ãã </simpara> <simpara> - These attacks are mainly based on exploiting the code not being written - with security in mind. Never trust on any kind of input, especially - which comes from the client side, even though it comes from a select box, - a hidden input field or a cookie. The first example shows that such a - blameless query can cause disasters. + ãããã®æ»æã¯ãã»ãã¥ãªãã£ãèæ ®ãã¦æ¸ããã¦ããªãã³ã¼ããæ»æ + ããæ¹æ³ã§ããç¹ã«ã¯ã©ã¤ã¢ã³ãå´ããå ¥åããããããã種é¡ã®å ¥å + ãæ±ºãã¦ä¿¡ç¨ããªãã§ä¸ãããããã¯ãselectããã¯ã¹ãhidden input + ãã£ã¼ã«ããCookieã®å ´åãåæ§ã§ããæåã®ä¾ã¯ããã®ãããªæ¬ ç¹ã® + ãªãã¯ã¨ãªãç ´æ» ããããããããã¨ã示ããã®ã§ãã </simpara> <itemizedlist> <listitem> <simpara> - Never connect to the database as a superuser or as the database owner. - Use always customized users with very limited privileges. + ãã¼ã¿ãã¼ã¹ã«ã¹ã¼ãã¼ã¦ã¼ã¶ã¼ã¾ãã¯ãã¼ã¿ãã¼ã¹ã®ææè ã¨ã㦠+ æ¥ç¶ããªãã§ä¸ããã é常ã«å¶éãããæ¨©éãæããã«ã¹ã¿ãã¤ãº + ãããã¦ã¼ã¶ã常ã«ä½¿ç¨ãã¦ä¸ããã </simpara> </listitem> <listitem> <simpara> - Check if the given input has the expected data type. PHP has - a wide range of input validating functions, from the simplest ones - found in <link linkend="ref.variables">Variable Functions</link> and - in <link linkend="ref.ctype">Character Type Functions</link> - (e.g. <function>is_numeric</function>, <function>ctype_digit</function> - respectively) onwards the - <link linkend="ref.pcre">Perl compatible Regular Expressions</link> - support. + æå®ãããå ¥åãæå¾ ãããã¼ã¿åã§ãããã¨ã確èªãã¦ä¸ããã + PHPã¯ãå¤ãã®ç¨®é¡ã®å ¥åæ¤è¨¼ç¨é¢æ°ãæãã¦ããã + <link linkend="ref.variables">夿°é¢é£ã®é¢æ°</link>ã + <link linkend="ref.ctype">æåå颿°</link>ã«ããç°¡åãªé¢æ° + (ä¾: ããããã<function>is_numeric</function>, + <function>ctype_digit</function>) ãã + <link linkend="ref.pcre">Perläºæã®æ£è¦è¡¨ç¾</link>ã®ãµãã¼ãã¾ + ã§ããã¾ãã </simpara> </listitem> <listitem> <para> - If the application waits for numerical input, consider to verify data - with <function>is_numeric</function>, or silently change its type - using <function>settype</function>, or use its numeric representation - by <function>sprintf</function>. + ã¢ããªã±ã¼ã·ã§ã³ããæ°å¤å ¥åãæå¾ ãã¦ããå ´åããã¼ã¿ã + <function>is_numeric</function>ã§æ¤è¨¼ãããã + <function>settype</function>ã«ããæé»ã®å夿ãè¡ããã + <function>sprintf</function>ã«ããæ°å¤è¡¨ç¾ã使ç¨ãããã¨ãæ¤è¨ + ãã¦ã¿ã¦ä¸ããã <example> - <title>A more secure way to compose a query for paging</title> + <title>ãã¼ã¸ã³ã°ç¨ã®ã¯ã¨ãªãæ§ç¯ããããã®ããå®å ¨ãªæ¹æ³</title> <programlisting role="php"> <![CDATA[ settype($order, 'integer'); $query = "SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET $offset;"; -// please note %d in the format string, using %s would be meaningless +// ãã©ã¼ãããæååã®%dã«æ³¨æãã¦ä¸ããã%sã使ç¨ãã¦ãæå³ãããã¾ããã $query = sprintf("SELECT id, name FROM products ORDER BY name LIMIT 20 OFFSET %d;", $offset); ]]> </programlisting> @@ -857,36 +867,40 @@ </listitem> <listitem> <simpara> - Quote each non numeric user input which is passed to the database with - <function>addslashes</function> or <function>addcslashes</function>. - See <link linkend="security.database.storage">the first example</link>. - As the examples shows, quotes burnt into the static part of the query - is not enough, and can be easily hacked. + ãã¼ã¿ãã¼ã¹ã«æ¸¡ãæ°å¤ä»¥å¤ã®ã¦ã¼ã¶å ¥åã + <function>addslashes</function> ã¾ã㯠+ <function>addcslashes</function>ã§ã¯ãªã¼ããã¦ä¸ããã + <link linkend="security.database.storage">æåã®ä¾</link>ãåç § + ãã¦ä¸ãããåæã®ä¾ã示ãããã«ãã¯ã¨ãªã®éçãªé¨åãã¯ãªã¼ã + ããã ãã§ã¯å åã§ã¯ãªããç°¡åã«ã¯ã©ãã¯ããã¦ãã¾ãå¯è½æ§ãã + ãã¾ãã </simpara> </listitem> <listitem> <simpara> - Do not print out any database specific information, especially - about the schema, by fair means or foul. See also <link - linkend="security.errors">Error Reporting</link> and <link - linkend="ref.errorfunc">Error Handling and Logging Functions</link>. + ãã¼ã¿ãã¼ã¹åºæã®æ å ±ãç¹ã«ã¹ãã¼ãã«é¢ããæ å ±ã¯åºåãã¦ã¯ã + ãã¾ããã<link linkend="security.errors">ã¨ã©ã¼åºå</link>ãã + ã³<link linkend="ref.errorfunc">ã¨ã©ã¼å¦çããã³ãã°é¢æ°</link> + ãåç §ä¸ããã </simpara> </listitem> <listitem> <simpara> - You may use stored procedures and previously defined cursors to abstract - data access so that users do not directly access tables or views, but - this solution has another impacts. + ã¦ã¼ã¶ããã¼ãã«ã¾ãã¯ãã¥ã¼ã«ç´æ¥ã¢ã¯ã»ã¹ã§ããªãããã«ã + ãã¼ã¿ã¢ã¯ã»ã¹ãæ½è±¡åãããã¨ãç®çã¨ãã¦ã¹ãã¢ãããã·ã¼ã¸ã£ + åã³äºåã«å®ç¾©ããã«ã¼ã½ã«ã使ç¨ãããã¨ãã§ãã¾ããããã®ã½ãªã¥ã¼ + ã·ã§ã³ã«ã¯ãå¯ä½ç¨ãããã¾ãã </simpara> </listitem> </itemizedlist> <simpara> - Besides these, you benefit from logging queries either within your script - or by the database itself, if it supports. Obviously, the logging is unable - to prevent any harmful attempt, but it can be helpful to trace back which - application has been circumvented. The log is not useful by itself, but - through the information it contains. The more detail is generally better. + ãããã®ã±ã¼ã¹ã«ããã¦ãã¹ã¯ãªããã¾ãã¯ãµãã¼ãããã¦ããå ´å㯠+ ãã¼ã¿ãã¼ã¹èªä½ã§ã¯ã¨ãªã®ãã°ãã¨ããã¨ãæçã§ãã + æããã«ãã°ã¯ç ´å£çãªè¡çºã鲿¢ãããã¨ã¯ã§ãã¾ããããæ»æãã + ãã¢ããªã±ã¼ã·ã§ã³ã追跡ããéã«ã¯æå¹ã§ãããã°èªä½ã¯æçã§ã¯ã + ãã¾ããããå«ã¾ãã¦ããæ å ±ã¯æçã§ããé常ããã詳細ãªãã°ã㨠+ ãæ¹ãè¯ãã§ãããã </simpara> </sect3> </sect2> @@ -1166,7 +1180,7 @@ </para> <para> PHPãé ãããã®ç°¡åãªææ³ãããã¤ããããã·ã¹ãã ã®å¼±ç¹ãè¦ã¤ãã - ãã¨ããæ»æãé å»¶ããããã¨ãã§ããå¯è½æ§ãããã¾ããphp.iniãã¡ + ãã¨ããæ»æãé å»¶ããããã¨ãã§ããå¯è½æ§ãããã¾ãã&php.ini;ãã¡ ã¤ã«ã§expose_php = offã¨è¨å®ãããã¨ã«ãããæ»æè ãå©ç¨å¯è½ãªæ å ±ãæ¸ãããã¨ãå¯è½ã§ãã </para>