A bit analysis of PHP global variable Vulnerability

Source: Internet
Author: User
    1. if (Isset ($_request[' GLOBALS ')) OR isset ($_files[' GLOBALS '])) {
    2. Exit (' Request tainting attempted. ');
    3. }
Copy Code

Register_globals is a control option in PHP that can be set to off or on, default to OFF, to decide whether to register the egpcs (environment,get,post,cookie,server) variable as a global variable. If Register_globals is turned on, the client-submitted data contains the Globals variable name, overwriting the $globals variable on the server. So this code, is to judge, if the submitted data has globals variable name, it terminates the program.

The resulting security issue becomes an "automatic global variable Vulnerability" in PHP, so make sure to turn off the register_globals option. and use $_get, $_post, $_cookie rather than $_request.

discuz! Forum Bypass global Variable Defense vulnerability

Because the default value of Request_order is GP in the settings of php5.3.x version php.ini, it causes discuz! Global variable defenses can be bypassed in 6.x/7.x.

In the 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. }
Copy Code

In include/common.inc.php:

    1. foreach (Array (' _cookie ', ' _post ', ' _get ') as $_request) {
    2. foreach ($$_request as $_key = $_value) {
    3. $_key{0}! = ' _ ' && $$_key = daddslashes ($_value);
    4. }
    5. }
Copy Code

The above code can be bypassed at Register_globals=on by committing the globals variable.

The precautionary approach provided in discuz!:

    1. if (Isset ($_request[' GLOBALS ')) OR isset ($_files[' GLOBALS '])) {
    2. Exit (' Request tainting attempted. ');
    3. }
Copy Code

The value of the $_request Super global variable is affected by the Request_order in PHP.ini, in the latest php5.3, the Request_order default is GP, which is the default configuration $_request contains only $_get and $_post and not $_ Cookies. Use cookies to submit globals variables.

Workaround: Change the php.ini settings in PHP 5.3.x and set the Request_order to GPC.

About the global variables in PHP vulnerability and temporary solution, this is introduced, I hope to help 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.