Php global variable vulnerability analysis-php Tutorial

Source: Internet
Author: User
Php global variable vulnerability analysis

  1. If (isset ($ _ REQUEST ['globals']) OR isset ($ _ FILES ['globals']) {
  2. Exit ('request tainting attempted .');
  3. }

Register_globals is a control option in php. it can be set to off or on. The default value is off. it determines whether to register EGPCS (Environment, GET, POST, Cookie, Server) variables as global variables. If register_globals is enabled, the data submitted by the client contains the GLOBALS variable name, which overwrites the $ GLOBALS variable on the server. Therefore, this code determines that if the submitted data contains the GLOBALS variable name, the program will be terminated.

The security problem caused by this becomes an "automatic global variable vulnerability" in PHP. Please disable the register_globals option. Use $ _ GET, $ _ POST, $ _ COOKIE instead of $ _ REQUEST.

Discuz! The forum bypasses global variables to defend against vulnerabilities

In php5.3.x php. ini, the default request_order value is GP, causing Discuz! In 6.x/7.x, global variable protection can be bypassed.

In include/global. func. php:

  1. Function daddslashes ($ string, $ force = 0 ){
  2. ! Defined ('Magic _ QUOTES_GPC ') & define ('Magic _ QUOTES_GPC', get_magic_quotes_gpc ());
  3. If (! MAGIC_QUOTES_GPC | $ force ){
  4. If (is_array ($ string )){
  5. Foreach ($ string as $ key => $ val ){
  6. $ String [$ key] = daddslashes ($ val, $ force );
  7. }
  8. } Else {
  9. $ String = addslashes ($ string );
  10. }
  11. }
  12. Return $ string;
  13. }

Include/common. inc. php:

  1. Foreach (array ('_ cookies',' _ post', '_ get') as $ _ request ){
  2. Foreach ($ _ request as $ _ key => $ _ value ){
  3. $ _ Key {0 }! = '_' & $ _ Key = daddslashes ($ _ value );
  4. }
  5. }

When register_globals = on, you can bypass the above code by submitting the GLOBALS variable.

Discuz! Provides the following defense methods:

  1. If (isset ($ _ REQUEST ['globals']) OR isset ($ _ FILES ['globals']) {
  2. Exit ('request tainting attempted .');
  3. }

$ _ REQUEST: the value of the Super global variable is determined by php. the effect of request_order in ini. in the latest php5.3, the default value of request_order is GP, that is, $ _ REQUEST contains only $ _ GET and $ _ POST, but not $ _ COOKIE by default. Use cookies to submit GLOBALS variables.

Temporary solution: change php. ini settings in php 5.3.x and set request_order to GPC.

We will introduce the global variable vulnerability and temporary solutions in php. I hope this will be helpful to you.

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.