PHP Security-Safe Mode

Source: Internet
Author: User
Tags readfile



Safe Mode

The purpose of the PHP safe_mode option is to resolve some of the issues described in this chapter. However, it is architecturally incorrect to address such issues at the PHP level, as described in the PHP Manual (http://www.php.cn/).

When Safe mode is in effect, PHP checks the owner of the file that is being read (or manipulated) by the executing script to ensure that it is the same as the owner of the script. While this can really protect against many of the examples in this chapter, it does not affect programs written in other languages. For example, a CGI script written using bash:

#!/bin/bash   echo "Content-type:text/plain"  echo "  cat/home/victim/inc/db.inc


Does the Bash parser care about or even check the configuration string for the open security mode in the PHP configuration file? Of course not. Similarly, other languages supported by the server, such as Perl,python, do not care about this. All the examples in this chapter can be easily adapted to other programming languages.

Another typical problem is that Safe mode does not deny access to files that belong to the Web server. This is because a script can be used to build another script, and the new script belongs to the Web server, so it can access all the files that belong to the Web server:

<?php   $filename = ' file.php ';  $script = ' <?php   header (\ ' content-type:text/plain\ ');  ReadFile ($_get[\ ' file\ ');   ? > ';   File_put_contents ($filename, $script);   ? >


The script above establishes the following file:

<?php   Header (' Content-type:text/plain ');  ReadFile ($_get[' file ');   ? >


Since the file was created by a Web server, its owner is a Web server (Apache typically runs with nobody users):

$ ls file.php  -rw-r--r--  1 Nobody nobody 12:34file.php


Therefore, this script bypasses the security measures provided by many safe modes. Even if safe mode is turned on, attackers can display information such as session information that is stored in the/tmp directory because the files belong to the Web server (nobody).

PHP's security model does play a role, and can be thought of as a defense-in-depth mechanism. However, it provides only poor protection, and in this chapter there are no other security measures to replace it.

The above is the PHP security-Safe Mode content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.