HTTP attack and prevention of PHP security Configuration

Source: Internet
Author: User

1 What is security

Security is the protection of Web applications and Web pages from hackers. Some hackers are purely for fun to invade other people's computers, but more hackers are struggling to steal other people's computer files, and even the entire computer paralyzed to achieve his purpose. Phenomenon on the internet has a lot of software that can be used by hackers, these software is mostly free and easy to use, so the average person to attack your computer, is not a very difficult thing. The key is what kind of protection do you have on your computer? If you only install the virus-checking software or the firewall is safe, then the true meaning of your security can be said to be completely non-understanding.


2 Register Global

Starting with PHP4.2.0, the default value for PHP.ini's register_global option is preset to OFF. When Register_globals is set to ON, your program will be able to receive various environment variables from the server, including the variables submitted by the form, and because PHP does not have to initialize the value of the variable beforehand, resulting in a large security risk. For example, the request variable for an HTML form. Because PHP does not need to initialize the values of variables beforehand, it is easier to write unsafe code. It was a tough decision, but the PHP community decided to turn this option off by default. When opened, people do not know where the variable comes from when they use it, only to take it for granted. But Register_globals's shutdown has changed the way the code internal variables and the variables sent by the client are mixed together in a bad situation.


3 Safe Mode

Safe Mode (Safe_mode) is used by PHP to restrict access to documents, restrict access to environment variables, and control the execution of external programs.

Because the Web server is running as a single system user, the user account of the system must be able to read each user's document. This means that any code document executed on the site server can access the documentation for each consumer. The Safe mode of PHP sets some restrictive options on multi-user systems to ensure the safe operation of the program. Safe Mode only restricts PHP documentation, but cannot restrict the external applications that PHP executes. Therefore, place the executable application in a secure folder and do not allow external users to execute it. To start PHP safe mode, set the Safe_mode option (Directive) of the php.ini file to on:

Safe_mode = On


Case 1:

test.php content is as follows:

  
   

When the Register_globals=off in php.ini

Visit URL: http://localhost/test.php?authorized=1

The output is:

The variable is not assigned a value.


When the Register_globals=on in php.ini

Attack:

Variable is not initialized, you can assign a value to a variable by URL

The output result is

Assigning values to variables


Protection:

Variable initialization, which prevents an attack by assigning a value to a variable via a URL.

You need to change the code to:

    

Case 2:

For example: test.php content is as follows:

     

When you access http://localhost/test.php,

Output: Visitor not logged in


Attack:

Append to URL after? _session[username]=admin

namely: Http://localhost/test.php?_session[username]=admin

Output: Visitor: admin


Protection:

Session_Start () Opens the session, gets the value in the session, and prevents the session variable from being injected through the URL.

Change the code to


      

Case 3:

When allow_url_fopen = on in php.ini

The contents of the demo.php are as follows:

 The contents of 
test.php are:


 "!--? Phpecho" this is test.php. The file is called.   "; 

When accessing the URL:

http://localhost/demo.php

Output: The file was not called.


Attack:

Stitching behind links? path=test.php

That is: Access http://localhost/demo.php?path=test.php

Output Out: This is test.php. The file is called.


Protect:

To initialize the path variable.


Note:

You can call the Ini_get_all function to display the PHP setting values.

For example:

!--? php echo "
";        Print_r (Ini_get_all ());   echo "
";
The
Run Results section is as follows:



available through

!--? phpini_set ("Allow_ur   L_fopen ", 1);  
Modify configuration in PHP file
  • 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.