text
stringlengths 1
254
| output
stringlengths 2
255
|
---|---|
In short, it cannot really be trusted.
|
Contents of the Accept-Language: header from the current request, if there is one. Example: 'en '.
|
This is a string denoting the user agent being which is accessing the page.
|
Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive '.
|
Mozilla / 4.5 [en] (X11; U; Linux 2.2.9 i586).
|
Contents of the Host: header from the current request, if there is one.
|
The IP address from which the user is viewing the current page.
|
The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.
|
For example in Apache you 'll need HostnameLookups On inside httpd.conf for it to exist.
|
The IP address from which the user is viewing the current page.
|
The port being used on the user 's machine to communicate with the web server.
|
The port being used on the user's machine to communicate with the web server.
|
The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file.
|
The absolute pathname of the currently executing script.
|
The port on the server machine being used by the web server for communication.
|
The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host.
|
String containing the server version and virtual host name which are added to server-generated pages, if enabled.
|
The port on the server machine being used by the web server for communication. For default setups, this will be '80 '; using SSL, for instance, will change this to whatever your defined secure HTTP port is.
|
Contains the current script 's path.
|
String containing the server version and virtual host name which are added to server-generated pages, if enabled.
|
The URI which was given in order to access this page; for instance, '/ index.html'.
|
Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.
|
When running under Apache as module doing HTTP authentication this variable is set to the password provided by the user.
|
Contains the current script's path. This is useful for pages which need to point to themselves.
|
Note:
|
The URI which was given in order to access this page; for instance, '/index.html '.
|
In earlier versions, use $HTTP_ENV_VARS.
|
泚æ 4.1.0ã§å°å
¥ãããŸããããã以åã®ããŒãžã§ã³ã®å Žåã¯ã $HTTP_ENV_VARS ã䜿çšããŠäžããã
|
Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor.
|
Other environment variables include the CGI variables, placed there regardless of whether PHP is running as a server module or CGI processor.
|
This simply means that it is available in all scopes throughout a script.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_ENV; to access it within functions or methods, as you do with $HTTP_ENV_VARS.
|
$HTTP_ENV_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_ENV_VARS and $_ENV are different variables and that PHP handles them as such)
|
$HTTP_ENV_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_ENV_VARS and $_ENV are different variables and that PHP handles them as such)
|
Note:
|
泚æ 4.1.0ã§å°å
¥ãããŸããããã以åã®ããŒãžã§ã³ã®å Žåã¯ã $HTTP_COOKIE_VARS ã䜿çšããŠäžããã
|
An associative array of variables passed to the current script via HTTP cookies.
|
An associative array of variables passed to the current script via HTTP cookies. Automatically global in any scope.
|
This is a 'superglobal', or automatic global, variable.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_COOKIE; to access it within functions or methods, as you do with $HTTP_COOKIE_VARS.
|
You don' t need to do a global $_COOKIE; to access it within functions or methods, as you do with $HTTP_COOKIE_VARS.
|
$HTTP_COOKIE_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_COOKIE_VARS and $_COOKIE are different variables and that PHP handles them as such)
|
These individual globals are not autoglobals.
|
泚æ 4.1.0ã§å°å
¥ãããŸããããã以åã®ããŒãžã§ã³ã®å Žåã¯ã $HTTP_GET_VARS ã䜿çšããŠäžããã
|
An associative array of variables passed to the current script via the HTTP GET method.
|
An associative array of variables passed to the current script via the HTTP GET method. Automatically global in any scope.
|
This is a 'superglobal', or automatic global, variable.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_GET; to access it within functions or methods, as you do with $HTTP_GET_VARS.
|
You don' t need to do a global $_GET; to access it within functions or methods, as you do with $HTTP_GET_VARS.
|
$HTTP_GET_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_GET_VARS and $_GET are different variables and that PHP handles them as such)
|
These individual globals are not autoglobals.
|
泚æ 4.1.0ã§å°å
¥ãããŸããããã以åã®ããŒãžã§ã³ã®å Žåã¯ã $HTTP_POST_VARS ã䜿çšããŠäžããã
|
An associative array of variables passed to the current script via the HTTP POST method.
|
An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.
|
This simply means that it is available in all scopes throughout a script.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.
|
$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)
|
$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)
|
An associative array of items uploaded to the current script via the HTTP POST method.
|
泚æ 4.1.0ã§å°å
¥ãããŸããããã以åã®ããŒãžã§ã³ã®å Žåã¯ã $HTTP_POST_FILES ã䜿çšããŠäžããã
|
This is a 'superglobal', or automatic global, variable.
|
An associative array of items uploaded to the current script via the HTTP POST method. Automatically global in any scope.
|
You don' t need to do a global $_FILES; to access it within functions or methods, as you do with $HTTP_POST_FILES.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_FILES; to access it within functions or methods, as you do with $HTTP_POST_FILES.
|
$HTTP_POST_FILES contains the same information, but is not an autoglobal.
|
$HTTP_POST_FILES contains the same information, but is not an autoglobal.
|
An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.
|
泚æ 4.1.0ã§å°å
¥ãããŸããã以åã®ããŒãžã§ã³ã«ã¯ãåçãªé
åã¯ãããŸã ãã
|
Prior to PHP 4.3.0, $_FILES information was also included into $_REQUEST.
|
An associative array consisting of the contents of $_GET, $_POST, $_COOKIE, and $_FILES.
|
This simply means that it is available in all scopes throughout a script.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_REQUEST; to access it within functions or methods.
|
These individual globals are not autoglobals.
|
泚æ 4.1.0ã§å°å
¥ãããŸããããã以åã®ããŒãžã§ã³ã§ã¯ã $HTTP_SESSION_VARS ã䜿çšããŠäžããã
|
An associative array containing session variables available to the current script.
|
An associative array containing session variables available to the current script. See the Session functions documentation for more information on how this is used.
|
This is a 'superglobal', or automatic global, variable.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.
|
You don' t need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.
|
$HTTP_SESSION_VARS contains the same information, but is not an autoglobal.
|
These individual globals are not autoglobals.
|
泚æ $GLOBALS ã¯ãPHP 3.0.0以éã§å©çšå¯èœã§ãã
|
The variable names are the keys of the array.
|
An associative array containing references to all variables which are currently defined in the global scope of the script. The variable names are the keys of the array.
|
You don' t need to do a global $GLOBALS; to access it within functions or methods.
|
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $GLOBALS; to access it within functions or methods.
|
The function is_resource() can be used to determine if a variable is a resource and get_resource_type() will return the type of resource it is.
|
以äžã«PHPã®ãªãœãŒã¹ãçæã䜿çšãç Žæ£ããããã®é¢æ°ã®äžèЧã瀺ããŸãã is_resource() ã«ãããã倿°ããªãœãŒã¹ã§ãããã© ããã調ã¹ãããšãå¯èœã§ãããŸãã get_resource_type() ã¯å€æ°ã®ãªãœãŒã¹åãè¿ããŸãã
|
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.
|
ãã°ãã°ãPHPãŠãŒã¶(ãã®å Žåã¯ApacheãŠãŒã¶)ãéåžžã«å°ããªãªã¹ã¯ã æããå Žæã«äžåºŠã»ãã¥ãªãã£ã確ç«ããããšãPHPã¯ãŠãŒã¶ãã£ã¬ã¯ã ãªã«ãŠã€ã«ã¹ãã¡ã€ã«ãæžã蟌ãã ãããããšãã§ããªããªããŸãããã ãã¯ãããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããã倿Žããããšãã£ãããšãåºæ¥ãªã ãªããŸãããã®å Žåãè¯ããã¡ã€ã«ããã³æªããã¡ã€ã«ã®æžã蟌ã¿ããŸã ã¯ãè¯ãããŒã¿ããŒã¹ãã©ã³ã¶ã¯ã·ã§ã³ãšæªãããŒã¿ããŒã¹ãã©ã³ã¶ã¯ã· ã§ã³ã«é¢ããŠçããå®å
šæ§ã確ä¿ãããŠãããšèšããŸãã
|
It has equally been secured from writing good and bad files, or entering good and bad database transactions.
|
ãã®èгç¹ãããã°ãã°è¡ãããã»ãã¥ãªãã£äžã®å€±æãšããŠApacheã«ã«ãŒ ãæš©éãäžããããä»ã®äœããã®ææ®µã§Apacheã®æš©éãææ Œããããšãã ãã®ããããŸãã
|
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ãŠãŒã¶ã®æš©éãã«ãŒãã«ææ Œãããããšã¯éåžžã«å±éºã§ãããã· ã¹ãã å
šäœãå±éºã«ãããå¯èœæ§ããããŸãããã£ãŠãsudoãchrootã®å® è¡ãã«ãŒãæš©éã§å®è¡ãè¡ãä»ã®ææ®µã¯ãã»ãã¥ãªãã£ã«ç²Ÿéããäººä»¥å€ ã¯ãèæ
®ããã¹ãã§ã¯ãããŸããã
|
You can also set up apache-only areas, to restrict all web based activity to non-user, or non-system, files.
|
ããã€ãã®ããç°¡åãªè§£æ±ºçããããŸãã open_basedir ã䜿çšããããšã«ã ããPHPã«äœ¿çšãèš±å¯ãããã£ã¬ã¯ããªãå¶åŸ¡ãããå¶éãããããããš ãå¯èœã§ãããŸããå
šãŠã®WebããŒã¹ã®äœæ¥ããŠãŒã¶ãã¡ã€ã«ãã·ã¹ãã ãã¡ã€ã«ä»¥å€ã®ãã¡ã€ã«ã«å¶éããããã«ãApacheå°çšãšãªã¢ãèšå®ãã ããšãå¯èœã§ãã
|
Accessing system files: http: / /my.host / cgi-bin / php? / etc / passwd
|
ã·ã¹ãã ãã¡ã€ã«ãžã®ã¢ã¯ã»ã¹: http://my.host/cgi-bin/php?/etc/passwd
|
Usually interpreters open and execute the file specified as the first argument on the command line.
|
URL ã«ãããŠçå笊 (?) ã®åŸã®ã¯ãšãªãŒæ
å ±ã¯ãCGI ã€ã³ã¿ãŒãã§ãŒ ã¹ã«ãããã€ã³ã¿ããªã¿ã«ã³ãã³ãã©ã€ã³åŒæ°ãšããŠæž¡ãããŸããé åžžãã€ã³ã¿ããªã¿ã¯ãã³ãã³ãã©ã€ã³äžã®æåã®åŒæ°ã«æå®ããããã¡ ã€ã«ãéããå®è¡ããŸãã
|
Accessing any web document on server: http: / /my.host / cgi-bin / php / secret / doc.html
|
CGI ãã€ããªãšããŠå®è¡ãããå ŽåãPHP ã¯ãã³ãã³ãã©ã€ã³åŒæ°ã® è§£éãæåŠããŸãã
|
Usually some web server configuration directives (Apache:
|
ãµãŒããŒäžã® Web ããã¥ã¡ã³ããžã®ã¢ã¯ã»ã¹: http://my.host/cgi-bin/php/secret/doc.html
|
This way any user able to access / cgi-bin / php is able to access any protected document on the web server.
|
PHP ã§ã¯ããµãŒããŒããã¥ã¡ã³ãããªãŒã«ã¢ã¯ã»ã¹å¶éä»ãã®ãã£ã¬ ã¯ããªãããå Žåãã³ã³ãã€ã«æã®èšå®ãªãã·ã§ã³ --enable-force-cgi-redirect ããã³å®è¡æã®èšå®åœä»€ doc_root ãš user_dir ããã®æ»æã鲿¢ã ãããã«äœ¿çšããããšãã§ããŸãã ããããçµã¿åãããããã€ã ã®ææ³ã«ã€ããŠä»¥äžã«è©³çްãªèª¬æã瀺ããŸãã
|
If your web server does not allow you to do redirects, or the server does not have a way to communicate to the PHP binary that the request is a safely redirected request, you can specify the option --enable-force-cgi-redirect to the configure script.
|
ãªãã€ã¬ã¯ã·ã§ã³ã¯ãäŸãã° Apache ã§ã¯åœä»€ AddHandler ããã³ Action ã§èšå®ããããšãã§ããŸãã(以äžãåç
§ããŠãã ããã)
|
Redirection can be configured in Apache by using AddHandler and Action directives (see below).
|
ãã®ã³ã³ãã€ã«æã®ãªãã·ã§ã³ã¯ã http://my.host/cgi-bin/php/secretdir/script.php ã®ããã« URL ããçŽæ¥ PHP ãåŒã³åºãããšãçŠæ¢ããŸãã 代ããã«ã Web ãµãŒããŒã®ãªãã€ã¬ã¯ã·ã§ã³ã«ããåŠçãããå Žåã¯ã PHP ã¯ãã®ã¢ãŒãã§ã®ã¿åŠçãè¡ããŸãã
|
Instead, PHP will only parse in this mode if it has gone through a web server redirect rule.
|
éåžžãApache çšèšå®ã§ã®ãªãã€ã¬ã¯ã·ã§ã³ã¯ã 次ã®åœä»€ã䜿çšããŠè¡ããŸãã
|
Action php-script / cgi-bin / php AddHandler php-script .php
|
ãã®ãªãã·ã§ã³ã¯ãApache Web ãµãŒããŒã§ã®ã¿ãã¹ããããŠããããªã¯ ãšã¹ãã®ãªãã€ã¬ã¯ãæã« Apache ãæšæºã§ã¯ãªãCGI ç°å¢å€æ° REDIRECT_STATUS ãã»ããããããšãåæã«ããŠããŸãã ãªã¯ãšã¹ããçŽæ¥ã®ãã®ã§ããã鿥ã®ãã®ã§ããããç€ºãææ®µãWeb ãµãŒããŒãå
šããµããŒãããŠããªãå Žåã¯ããã®ãªãã·ã§ã³ã䜿çšãã ããšã¯ã§ããŸããããã®å Žåãããã§èšãã CGI çãå®è¡ããä»ã®æ¹æ³ ã®å
ã®äžã€ã䜿çšããå¿
èŠããããŸãã
|
If, because of some configuration mistake, the scripts are not executed but displayed as regular HTML documents, this may result in leakage of intellectual property or security information like passwords.
|
åç¯ã§èšãããããªãªã¯ãšã¹ãããªãã€ã¬ã¯ãããããã®ã§ãªãããšã 確ãããæ¹æ³ãå©çšå¯èœã§ãªãå Žåã ã¹ã¯ãªããçšã® doc_root ã Web ããã¥ã¡ã³ãçšã«ãŒããšã¯å¥ã« ã»ããã¢ããããå¿
èŠããããŸãã
|
Also if the method for making sure the requests are not redirected, as described in the previous section, is not available, it is necessary to set up a script doc_root that is different from web document root.
|
èšå®çšåœä»€ doc_root ã«ãã èšå®ãã¡ã€ã« ãã¡ã€ã«äžã§ PHP ã¹ã¯ãªããçšããã¥ã¡ã³ãã«ãŒããèšå®ããããšãã§ããŸãã ãŸãã¯ãç°å¢å€æ° PHP_DOCUMENT_ROOT ã§ãèšå®ãã ããšãã§ããŸãã ãããèšå®ããå ŽåãCGI çã® PHP ã¯ã åžžã«éããã¡ã€ã«ã®ååããã® doc_root ãªã¯ãšã¹ãã®ãã¹æ
å ±ãçšããŠäœæãã (以äžã® user_dir ãé€ãã)確å®ã« ãã®ãã£ã¬ã¯ããªã®å€åŽã§ã¹ã¯ãªãããå®è¡ãããªãããã«ããŸãã
|
If it is set, the CGI version of PHP will always construct the file name to open with this doc_root and the path information in the request, so you can be sure no script is executed outside this directory (except for user_dir below).
|
ããã§å©çšå¯èœãªå¥ã®ãªãã·ã§ã³ã¯ã user_dir ã§ããuser_dir ãèšå®ãããŠããªãå Žåã éããããã¡ã€ã«åãå¶åŸ¡ããã®ã¯ã doc_root ã®ã¿ã§ãã http://my.host/~user/doc.php ã®ãã㪠URL ã¯ããŠãŒã¶ãŒããŒã ãã£ã¬ã¯ããªä»¥äžã®ãã¡ã€ã«ãéããã doc_root 以äžã® ~user/doc.php ãšãããã¡ã€ã«ãéãããšã«ãªããŸãã (ãã£ã¬ã¯ããªåããã«ã [~] ã§å§ãŸã£ãŠãã ãšããããšã«ãªããŸã)
|
Opening an url like http: / /my.host / ~user / doc.php does not result in opening a file under users home directory, but a file called ~user / doc.php under doc_root (yes, a directory name starting with a tilde [~]).
|
user_dir ãäŸãã°ã public_php ã« èšå®ãããŠããå Žåã http://my.host/~user/doc.php ã® ãããªãªã¯ãšã¹ãã¯ããã®ãŠãŒã¶ãŒ user ã®ããŒã ãã£ã¬ã¯ããªã«ãã public_php 以äžã® doc.php ãšããååã®ãã¡ã€ã«ããªãŒãã³ã㟠ãããŠãŒã¶ãŒã®ããŒã ãã£ã¬ã¯ããªãã /home/user ã§ããå Žåã å®è¡ããããã¡ã€ã«ã¯ã /home/user/public_php/doc.php ãšãªããŸãã
|
If the home of the user is / home / user, the file executed is / home / user / public_php / doc.php.
|
user_dir ã®å±éã¯ã doc_root ã®èšå®ã«ãããè¡ãããŸãã ãã®ãããããã¥ã¡ã³ãã«ãŒãããã³ãŠãŒã¶ãŒãã£ã¬ã¯ããªãžã® ã¢ã¯ã»ã¹ãå¥ã
ã«å¶åŸ¡ããããšãã§ããŸãã
|
A very secure option is to put the PHP parser binary somewhere outside of the web tree of files.
|
éåžžã«å®å
šæ§ã®é«ããªãã·ã§ã³ãšããŠPHP ããŒãµã®ãã€ããªããã¡ã€ã« çš Web ããªãŒã®å€åŽãäŸãã° /usr/local/bin ã«çœ®ãããšãèããããŸããã ã®ãªãã·ã§ã³ã®å¯äžã®æ¬ ç¹ã¯ãPHP ã¿ã°ãæããå
šãŠã®ãã¡ã€ã«ã®å
é è¡ã«æ¬¡ã®ãããªäžè¡ãå ããå¿
èŠãããããšã§ãã
|
To get PHP to handle PATH_INFO and PATH_TRANSLATED information correctly with this setup, the php parser should be compiled with the --enable-discard-path configure option.
|
ãã®èšå®ã§ PATH_INFO ããã³ PATH_TRANSLATED æ
å ±ãæ£ããåŠçããããã«ã¯ã PHP ããŒãµãèšå®ãªãã·ã§ã³ --enable-discard-path ãä»ããŠã³ã³ãã€ã«ããå¿
èŠããããŸãã
|
Each new version will often include both major and minor changes to enhance and repair security flaws, configuration mishaps, and other issues that will affect the overall security and stability of your system.
|
PHPã¯ãä»ã®å€§èŠæš¡ãªã·ã¹ãã ãšåæ§ã«ãåžžã«èª¿æ»ãæ¹è¯ãããŠããŸãã åæ°ããŒãžã§ã³ã«ã¯ãã°ãã°ã»ãã¥ãªãã£äžã®åé¡ãèšå®äžã®åé¡ããã ãŠãã·ã¹ãã å
šäœã®ã»ãã¥ãªãã£ãå®å®æ§ã«åœ±é¿ãããã®ä»ã®åé¡ãä¿®æ£ ããããã®ã¡ãžã£ãŒãŸãã¯ãã€ããŒãªå€æŽãå«ãŸããŠããŸãã
|
Prev
|
ä»ã®ã·ã¹ãã ã¬ãã«ã®ã¹ã¯ãªããèšèªãããã°ã©ã ãšåæ§ã«ãæåã®ã¢ã ããŒãã¯ãé »ç¹ã«æŽæ°ããææ°ã®ããŒãžã§ã³ãšãã®å€æŽã泚èŠãç¶ããã ãšã§ãã
|
Since very sensitive or secret informations can be stored in such database, you should strongly consider to protect them somehow.
|
仿¥ããã€ãããã¯ãªã³ã³ãã³ããæäŸãããŠã§ãã¢ããªã±ãŒã·ã§ã³ã« ãããŠã¯ããŒã¿ããŒã¹ã¯æ¬ ãäºã®ã§ããªã³ã³ããŒãã³ããšãªã£ãŠããŸãã ãããã£ãããŒã¿ããŒã¹ã«ã¯éèŠãªããããŠç§å¯ã«ãã¹ãæ
å ±ãæ ŒçŽ ãããããšã«ãªãã®ã§ãããããããã«ããŠä¿è·ãããã«ã€ããŠååã« èæ
®ããå¿
èŠããããŸãã
|
Nowadays, the commonly used query language in this interaction is the Structured Query Language (SQL).
|
æ
å ±ãåãåºãããæ ŒçŽããããã«ã¯ããŒã¿ããŒã¹ã«æ¥ç¶ããå¿
èŠããããŸãã ãããŠé©åãªã¯ãšãªãéä¿¡ããçµæãåãåããåæããŸããã¯ãšãªã« 䜿çšãããèšèªã¯Structured Query Language (SQL)ãäžè¬çã§ããã¢ã¿ãã«ãŒ ãã©ã®ããã« SQLã« å¹²æžãã ãã«ã€ããŠåç
§ããŠãã ããã
|
Good design of the database schema and the application deals with your greatest fears.
|
çããããæ°ã¥ãã®æ§ã«ãPHPããèªäœã¯è²Žæ¹ã®ããŒã¿ããŒã¹ãä¿è·ããããšã¯ ãããŸããã以äžã®ã»ã¯ã·ã§ã³ã¯PHPã¹ã¯ãªããããã©ã®ããã«ããŒã¿ããŒã¹ã« ã¢ã¯ã»ã¹ãæäœããã°ããã®ãããšããããšã«é¢ããéåžžã«åºæ¬çãªå°å
¥ã§ãã
|
Applications should never connect to the database as its owner or a superuser, because these users can execute any query at will, for example, modifying the schema (e.g. dropping tables) or deleting its entire content.
|
ãã®ã·ã³ãã«ãªã«ãŒã«ãèŠããŠçœ®ããŠãã ããïŒããã¯ãå€éé²è¡ãã§ãã ããå€ãã®ç®æã§ãããå€ãã®ä¿è·ãè¡ãããšã«ãããã¢ã¿ãã«ãŒãæ»æã« æåããŠæ©å¯æ
å ±ãæŒæŽ©ããå¯èœæ§ã¯æžã£ãŠãããŸããããŒã¿ããŒã¹ãš ã¢ããªã±ãŒã·ã§ã³ãæ£ãããã¶ã€ã³ããããšã§è²Žæ¹ã®å¿é
ãåãé€ãããšã ã§ããŸãã
|
This means that if intruders gain access to your database using one of these credentials, they can only effect as many changes as your application can.
|
ä»äººãçšæããæ¢åã®ãã®ã䜿çšããã®ã§ãªãéããæåã«è¡ãã®ã¯ããŒã¿ããŒã¹ã®äœæã§ãã ããŒã¿ããŒã¹ãäœæããããšããã®ããŒã¿ããŒã¹ã®ãªãŒããŒã¯äœæã³ãã³ãã å®è¡ãããŠãŒã¶ã«ãªããŸããéåžžããªãŒããŒ(ãšã¹ãŒããŒãŠãŒã¶ãŒ)ã®ã¿ã ãã®ããŒã¿ããŒã¹ã«å¯ŸããŠæäœãè¡ãããšãåºæ¥ãŸããä»ã®ãŠãŒã¶ãããŒã¿ããŒã¹ã 䜿çšããã«ã¯é©åãªæš©å©ãäžããããŠããå¿
èŠããããŸãã
|
If the system evolves, new ports will be intended to open to the database, and you have to reimplement the logic in each separate database client.
|
ã¢ããªã±ãŒã·ã§ã³ã¯ããŒã¿ããŒã¹ã«ãªãŒããŒããããã¯ã¹ãŒããŒãŠãŒã¶ãŒãšã㊠æ¥ç¶ããŠã¯çµ¶å¯Ÿã«ãããŸããããªããªããããã®ãŠãŒã¶ã¯ äŸãã°ã¹ããŒãã®å€æŽ(ããŒãã«ã®åé€ç)ãå
šã³ã³ãã³ãã®åé€ããšãã£ã ããããã¯ãšãªãŒãå®è¡ããããšãåºæ¥ãããã§ãã
|
You may want to estabilish the connections over SSL to encrypt client / server communications for increased security, or you can use ssh to encrypt the network connection between clients and the database server.
|
貎æ¹ãäœæããã¢ããªã±ãŒã·ã§ã³ãããŒã¿ããŒã¹ã«å¯ŸããŠè¡ãæäœã®åæ¹é¢ããšã«ã ææ»å¯Ÿè±¡ãšãªããªããžã§ã¯ãã«å¯ŸããŠãåºæ¥ãéãå°ãªãæš©éãæã£ãè€æ°ã® ãŠãŒã¶ãäœæããæ¹ãè¯ãã§ãããããŠãŒã¶ã«å¯ŸããŠã¯ãæäœéå¿
èŠãªæš©éã®ã¿ã äžããé¢ä¿ã®ç¡ãããŒã¿ãžã®ã¢ã¯ã»ã¹ãèš±å¯ããªãããã«ããŸããããã¯ã äžãäžäŸµå
¥è
ããã®ãŠãŒã¶ã®æš©éã以ã£ãŠããŒã¿ããŒã¹ã«ã¢ã¯ã»ã¹ããéã«ã ã¢ããªã±ãŒã·ã§ã³ãšé¢ä¿ã®ç¡ãããŒã¿ã«ãŸã§ã¢ã¯ã»ã¹ãããããšãé²ãããã§ãã
|
SSL / SSH protects data travelling from the client to the server, SSL / SSH does not protect the persistent data stored in a database.
|
å
šãŠã®ããžãã¹ããžãã¯ããŠã§ãã¢ããªã±ãŒã·ã§ã³(ã€ãŸã貎æ¹ã®ã¹ã¯ãªãã) ã§å®è£
ããããšã¯æšå¥šãããŸããã代ããã«ããã¥ãŒãããªã¬ãŒãã«ãŒã«ãšãã£ã ããŒã¿ããŒã¹ã®æ©èœã掻çšããæ¹ãè¯ãã§ããããã·ã¹ãã ãæŽæ°ããã æ°ããæ©èœãããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ããããšã«ãªã£ãå Žåãåã
ã®ããŒã¿ããŒã¹ ã¯ã©ã€ã¢ã³ãããšã«ååºŠåæ§ã®ããžãã¯ãå®è£
ããªããã°ãªããªããªããŸãã ããã«ãããªã¬ãŒã¯ééçã«ããããŠèªåçã«ãã£ãŒã«ããæ±ãããšãåºæ¥ãã®ã§ã ãããã°æãããã©ã³ã¶ã¯ã·ã§ã³ã®ããŒã«ããã¯æã«åœ¹ç«ã¡ãŸãã
|
Encrypting the data is a good way to mitigate this threat, but very few databases offer this type of data encryption.
|
æŽãªãã»ãã¥ãªãã£ã®ããã«ãã¯ã©ã€ã¢ã³ã/ãµãŒãéã®éä¿¡ã«ãããŠSSLãçšãã æå·åãè¡ã£ãæ¹ãè¯ãã§ãããããããã¯sshã䜿çšããããšãåºæ¥ãŸãã ã©ã¡ããã®ææ®µãè¬ããåŸããã©ãã£ãã¯ãã¢ãã¿ãªã³ã°ããŠã¿ãã° ããããäœããã®æ
å ±ãåŸãããšãå°é£ã ãšããäºãåãããšæããŸãã
|
PHP can assist you in this case with its several extensions, such as Mcrypt and Mhash, covering a wide variety of encryption algorithms.
|
SSL/SSHã«ãã£ãŠã¯ã©ã€ã¢ã³ã/ãµãŒãéã§éä¿¡ãããããŒã¿ã¯ä¿è·ãããŸããã ããŒã¿ããŒã¹ã«ä¿åãããããŒã¿ã¯ä¿è·ãããŸãããSSLã¯ãããŸã§éä¿¡äžã® ãããã³ã«ãªã®ã§ãã
|
The well-known example for the hashing is storing the MD5 hash of a password in a database, instead of the password itself.
|
äžæŠã¢ã¿ãã«ãŒãããŒã¿ããŒã¹ãž(ãŠã§ããµãŒããéããã«)ã¢ã¯ã»ã¹ã§ããŠããŸããšã ããã«æ ŒçŽãããŠããããŒã¿èªäœãæå·åãããŠããªãéããèªç±ã«é²èЧããã 䜿çšãããŠããŸããŸããããŒã¿ãæå·åããããšã«ãã£ãŠããã®è
åšãæžããããšã ã§ããŸããããã®æ©èœããµããŒãããŠããããŒã¿ããŒã¹ã¯å
ãã§ãã
|
Many web developers are unaware of how SQL queries can be tampered with, and assume that an SQL query is a trusted command.
|
ãã®åé¡ãžã®æãç°¡åãªå¯Ÿå¿çã¯ããŸãèªåå°çšã®æå·åããã±ãŒãžãäœæãã ãããããªãã®PHPã¹ã¯ãªãããã䜿çšããããšã§ããPHPã® Mcrypt, Mhash ãšãã£ã幟ã€ãã®æ¡åŒµã¢ãžã¥ãŒã«ã¯ãæ§ã
ãªæå·åã¢ã«ãŽãªãºã ããµããŒã ããŠããã®ã§åœ¹ã«ç«ã€ã§ããããããŒã¿æ ŒçŽæã«æå·åãè¡ããååŸæã« åŸ©å·åããŸãããã®æ¹æ³ã«ã€ããŠã¯ãªãã¡ã¬ã³ã¹ãåç
§ããŠãã ããã
|
Direct SQL Command Injection is a technique where an attacker creates or alters existing SQL commands to expose hidden data, or to override valuable ones, or even to execute dangerous system level commands on the database host.
|
ããå®å
šã«ããŒã¿ãé ãããå Žåããå
ã®ããŒã¿èªäœã¯å¿
èŠãªãå Žå(ã€ãŸã 衚瀺ãããªãå Žå)ã¯ãããã·ã¥ãèæ
®ã«å
¥ããã»ããè¯ãã§ãããã ããã·ã¥ã®è¯ãç¥ãããäœ¿çšæ¹æ³ã¯ããã¹ã¯ãŒãããã®ãŸãŸæ ŒçŽããã«ã ãã®MD5ããã·ã¥å€ãæ ŒçŽããæ¹æ³ã§ãã crypt() ã md5() ãåç
§ããŠãã ããã
|
This is accomplished by the application taking user input and combining it with static parameters to build a SQL query.
|
äŸ 5-5ããã·ã¥ãã¹ã¯ãŒããã£ãŒã«ãã䜿ã
|
Owing to the lack of input validation and connecting to the database on behalf of a superuser or the one who can create users, the attacker may create a superuser in your database.
|
å€ãã®éçºè
ã¯SQLã¯ãšãªãã©ã®ããã«æ¹ç«ãããããšããããšãäœã æ°ã«ãããŠãããããŸãSQLã¯ãšãªã¯ä¿¡çšã§ãããã®ãšèããŠããããã§ãã å®éã«ã¯SQLã¯ãšãªã¯ã¢ã¯ã»ã¹å¶éãåé¿ããããšãå¯èœã§ãåŸã£ãŠ éåžžã®èªèšŒãæš©éã®ãã§ãã¯ãç¡èŠããããšãã§ããŸããæã«ã¯ã OSã¬ãã«ã®ã³ãã³ããå®è¡ã§ããŠããŸãããšããããŸãã
|
A feasible way to gain passwords is to circumvent your search result pages.
|
å
¥åã®ãã§ãã¯ãæ ã£ãŠãããã¹ãŒããŒãŠãŒã¶ãããã¯ããŒã¿ããŒã¹äœææš©éã æã€ãŠãŒã¶ä»¥å€ã®ãŠãŒã¶ã§ããŒã¿ããŒã¹ã«æ¥ç¶ ããŠããªã ããã«ãæ»æè
ã¯ããŒã¿ããŒã¹ã«ã¹ãŒããŒãŠãŒã¶ãäœæããããšãåºæ¥ãŸãã
|
These filters can be set commonly in a preceding form to customize WHERE, ORDER BY, LIMIT and OFFSET clauses in SELECT statements.
|
äŸ 5-6 衚瀺ããããŒã¿ãåå²ã... ãããŠã¹ãŒããŒãŠãŒã¶ãäœæããŸãã (PostgreSQLãšMySQLã®äŸ)
|
Using encrypted password fields is strongly encouraged.
|
泚æ SQLããŒãµã«ã¯ãšãªã®æ®ãã®éšåãç¡èŠãããããã«éçºè
ã«ãã䜿ã ããææ³ãšããŠãSQLã®ã³ã¡ã³ã笊åã§ãã -- ãã ããŸãã
|
SQL UPDATEs are also subject to attacking your database.
|
äŸ 5-7 èšäº...ãããŠ(å
šãŠã®ããŒã¿ããŒã¹ãµãŒããŒã®)ããã€ãã®ãã¹ã¯ãŒã ã®ãªã¹ãã衚瀺ãã
|
But the attacker might fiddle with the SET clause.
|
SQL UPDATE ãããŒã¿ããŒã¹ãæ»æããããã«äœ¿çšãããŸãããããã®ã¯ ãšãªãåæšãŠããæ°ããã¯ãšãªãå
ã®ã¯ãšãªã«è¿œå ããããšã«ããæ»æ ãåããŸããããããæ»æè
㯠SET å¥ã䜿çšããå¯ èœæ§ããããŸãããã®å Žåãã¯ãšãªãæåãããããã«ããã€ãã®ã¹ã㌠ãæ
å ±ãä¿æããå¿
èŠããããŸããããã¯ããã©ãŒã ã®å€æ°åãç·åœã ãæ³ã«ãã調ã¹ãããšãã§ããŸãããã¹ã¯ãŒããŸãã¯ãŠãŒã¶åãä¿åã ããã£ãŒã«ãçšã®åœåèšæ³ã¯ããå€ãã¯ãããŸããã
|
This can be acquired by examing the form variable names, or just simply brute forcing.
|
äŸ 5-8 ãã¹ã¯ãŒãã®ãªã»ãããã... (å
šãŠã®ããŒã¿ããŒã¹ãµãŒããŒã§)ããå€ ãã®æš©éãåŸããŸã§
|
Example 5-8.
|
æãããäŸãšããŠãããã€ãã®ããŒã¿ããŒã¹ãã¹ãã®ãªãã¬ãŒãã£ã³ ã°ã·ã¹ãã ã¬ãã«ã®ã³ãã³ããã¢ã¯ã»ã¹å¯èœãšãªãæ¹æ³ã瀺ããŸãã
|
$query = "UPDATE usertable SET pwd='$pwd 'WHERE uid='$uid' ;";
|
äŸ 5-9ããŒã¿ããŒã¹ãã¹ãã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãæ»æãã (MSSQLãµãŒããŒ)
|
A frightening example how operating system level commands can be accessed on some database hosts.
|
泚æ äžèšã®ããã€ãã®äŸã¯ãããŒã¿ããŒã¹ãµãŒãã®çš®é¡ã«äŸåããŠããŸãã ããã¯ãä»ã®è£œåã«å¯ŸããŠåæ§ãªæ»æãã§ããªãããšãæå³ãããã®ã§ ã¯ãããŸããã䜿çšããŠããããŒã¿ããŒã¹ãä»ã®ææ®µã§æ»æå¯èœã§ãã å¯èœæ§ããããŸãã
|
You are right, but you never know when and how it can be taken out, and if it happens, your database may be exposed.
|
ãããã®æ»æã¯ãã»ãã¥ãªãã£ãèæ
®ããŠæžãããŠããªãã³ãŒããæ»æ ããæ¹æ³ã§ããç¹ã«ã¯ã©ã€ã¢ã³ãåŽããå
¥åãããããããçš®é¡ã®å
¥å ãæ±ºããŠä¿¡çšããªãã§äžãããããã¯ãselectããã¯ã¹ãhidden input ãã£ãŒã«ããCookieã®å Žåãåæ§ã§ããæåã®äŸã¯ããã®ãããªæ¬ ç¹ã® ãªãã¯ãšãªãç Žæ»
ãããããããããšã瀺ããã®ã§ãã
|
It may be also a security risk if it is a poorly designed one.
|
ããŒã¿ããŒã¹ã«ã¹ãŒããŒãŠãŒã¶ãŒãŸãã¯ããŒã¿ããŒã¹ã®ææè
ãšã㊠æ¥ç¶ããªãã§äžããã éåžžã«å¶éãããæš©éãæããã«ã¹ã¿ãã€ãº ããããŠãŒã¶ãåžžã«äœ¿çšããŠäžããã
|
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.
|
æå®ãããå
¥åãæåŸ
ããããŒã¿åã§ããããšã確èªããŠäžããã PHPã¯ãå€ãã®çš®é¡ã®å
¥åæ€èšŒçšé¢æ°ãæããŠããã 倿°é¢é£ã®é¢æ° ã æåå颿° ã«ããç°¡åãªé¢æ° (äŸ: ããããã is_numeric(), ctype_digit()) ãã Perläºæã®æ£èŠè¡šçŸ ã®ãµããŒã㟠ã§ãããŸãã
|
If the application waits for numerical input, consider to verify data with is_numeric(), or silently change its type using settype(), or use its numeric representation by sprintf().
|
ã¢ããªã±ãŒã·ã§ã³ããæ°å€å
¥åãæåŸ
ããŠããå ŽåãããŒã¿ã is_numeric() ã§æ€èšŒãããã settype() ã«ããæé»ã®å倿ãè¡ããã sprintf() ã«ããæ°å€è¡šçŸã䜿çšããããšãæ€èš ããŠã¿ãŠäžããã
|
A more secure way to compose a query for paging
|
äŸ 5-10ããŒãžã³ã°çšã®ã¯ãšãªãæ§ç¯ããããã®ããå®å
šãªæ¹æ³
|
Quote each non numeric user input which is passed to the database with addslashes() or addcslashes().
|
ããŒã¿ããŒã¹ã«æž¡ãæ°å€ä»¥å€ã®ãŠãŒã¶å
¥åã addslashes() ãŸã㯠addcslashes() ã§ã¯ãªãŒãããŠäžããã æåã®äŸ ãåç
§ ããŠäžãããåæã®äŸã瀺ãããã«ãã¯ãšãªã®éçãªéšåãã¯ãªãŒã ããã ãã§ã¯å
åã§ã¯ãªããç°¡åã«ã¯ã©ãã¯ãããŠããŸãå¯èœæ§ãã ããŸãã
|
Do not print out any database specific information, especially about the schema, by fair means or foul.
|
ããŒã¿ããŒã¹åºæã®æ
å ±ãç¹ã«ã¹ããŒãã«é¢ããæ
å ±ã¯åºåããŠã¯ã ããŸããã ãšã©ãŒåºå ãã ã³ ãšã©ãŒåŠçããã³ãã°é¢æ° ãåç
§äžããã
|
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.
|
ãŠãŒã¶ãããŒãã«ãŸãã¯ãã¥ãŒã«çŽæ¥ã¢ã¯ã»ã¹ã§ããªãããã«ã ããŒã¿ã¢ã¯ã»ã¹ãæœè±¡åããããšãç®çãšããŠã¹ãã¢ãããã·ãŒãžã£ åã³äºåã«å®çŸ©ããã«ãŒãœã«ã䜿çšããããšãã§ããŸããããã®ãœãªã¥ãŒ ã·ã§ã³ã«ã¯ãå¯äœçšããããŸãã
|
Obviously, the logging is unable to prevent any harmful attempt, but it can be helpful to trace back which application has been circumvented.
|
ãããã®ã±ãŒã¹ã«ãããŠãã¹ã¯ãªãããŸãã¯ãµããŒããããŠããå Žå㯠ããŒã¿ããŒã¹èªäœã§ã¯ãšãªã®ãã°ããšãããšãæçã§ãã æããã«ãã°ã¯ç Žå£çãªè¡çºã鲿¢ããããšã¯ã§ããŸããããæ»æãã ãã¢ããªã±ãŒã·ã§ã³ã远跡ããéã«ã¯æå¹ã§ãããã°èªäœã¯æçã§ã¯ã ããŸããããå«ãŸããŠããæ
å ±ã¯æçã§ããéåžžããã詳现ãªãã°ããš ãæ¹ãè¯ãã§ãããã
|
A standard attack tactic involves profiling a system by feeding it improper data, and checking for the kinds, and contexts, of the errors which are returned.
|
PHPã®ã»ãã¥ãªãã£ã«é¢ããŠã2çš®é¡ã®ãšã©ãŒåºåããããŸããäžã€ã¯ãã» ãã¥ãªãã£åäžã«åœ¹ç«ã€ãã®ã§ãããããäžã€ã¯ãã»ãã¥ãªãã£äžæå®³ãª ãã®ã§ãã
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.