• Technosailor.com
  • Desk of the Editor
  • Entrepreneurship
  • Web Marketing
  • Tech Policy
  • Contenido Español
Technosailor
  • Blog
  • Authors
  • Twitter Pitch Me!
  • Disclosures
  • Advertise on Technosailor.com
Feb
01
2005

Lessons in Web Security: PHP and register_globals

Posted by: Aaron Brazell
Woodlawn, MD, USA

After taking a gander at some of the threads at Sitepoint Forums, I decided to take a look at a topic that is as deep as it is wide. Over the next few days and weeks, we’ll look at some of the problems in the way of web security and what you can do to ensure your website does not get defaced, brought down or otherwise exploited. It will probably not be an exhaustive list but it should be enough. In some cases, I may be accused of being vague, so let me say for the record that that is my intention. I don’t intend to give away the house or industry secrets, but I do want to make the issue transparent enough that the dangers can be noted and understood.

So starting right off, let’s look at one of the weaknesses of a common scripting language, PHP. This exploit is actually old and has been closed by default in every PHP release for the past few years. This issue is a setting called register_globals.

Register_globals is a setting within the php.ini file that says, ‘okay, we have global variables that we want to make local variables’. What does this mean? Global variables are session and cookie variables as well as any data submitted via a form (POST) or by URL (GET).

When a URL is formed as such:

http://www.example.com/index.php?id=123&category=general

The GET global variables are id and category.

When an HTML form has fields with names such as username and password, the POST variables are username and password:

<form action="processform.php" method="post"> <input type="text" name="username" /> <input type="password" name="password" /> <input type="submit" name="submit" value="Submit"> </form>

In the old days, and still on some servers that have register_globals turned on, the ease of using PHP was partly due to the fact that using these global variables was as simple as calling them by name. If a programmer wanted to display the fields submitted by the URL in the first example, it was as simple as writing:

<?php echo $id; echo $categroty; ?>

This was easy but insecure. With register_globals enabled, PHP will trust any variable that it has been passed via a web form or a URL (or cookie if an attacker has local access to the machine the cookie is set on). By disabling register globals, it forces PHP to look at any information being passed to it and allows the developer to explicitly set data that is expected to be passed and ignore any information that is not intended.

For instance, take this example where an appropriate username/password combo is admin and mypass. The form is submitted to a script that is intended to authorize a user and grant them access, should the authentication be completed.

With Register Globals on:
<?php if($username == 'admin' && $password == 'mypass') { $authorized=1; } if($authorized == 1) { // Display content } ?>
This script essentially looks at the global variables submitted by the form and recognizes that the correct credentials are displayed, sets a variables ($authorized) equal to 1 and continues on. The next check determines if $authorized is equivalent to 1 and if so, authenticates.

Well, what if I am Joe Hacker, and I realize that this webserver has register_globals on (a simple test would determine this)? A variable created in a form with one name would be handled the same way as a variable in a URL with the same name. So If I browsed to http://www.example.com/processform.php?authorized=1, I can gain the same access.

But I never submitted a username and password, correct? This is correct, but the fact that I fail a username and password test doesn’t mean a thing, when the determining factor for whether to display protected content is based on whether a variable, $authorized, equals 1.

Solution: Chances are, if you are running a version of PHP within the past three years, register_globals has been turned off. If however, it is turned on or you are unsure about whther it is of, you can include the following bit at the top of your script:

ini_set("register_globals",0);

In addition, now global variables are referred to using their global array names. Variables passed in a URL are now referred to using $_GET['variable1'], $_GET['variable2'], etc. Variables submitted via forms, or the POST method, are ferred to using $_POST. $_COOKIE and $_SESSION touch on another area of security, but can also be referred to using their global variable array names.

So, next time, we’ll talk about PHP and the remote file execution capability.

  • Add to Mixx!
  • Stumble it!
About the Author: Aaron Brazell is the lead editor of Technosailor.com and a social media expert. His passion is to see companies and individuals use the internet and web technologies wisely and effectively to promote their brands and companies. He served as Director of Technology at b5media from 2005-2008 and is currently an independent consultant.
Tagged: php, Programming, register globals, securit at 2:39 pm -
Comments for this post are closed.
  • Subscribe:  This Thread
  • Go to:  My Comments ·  Community Page
  • Sort thread by:

    Viewing 3 Comments

    Thanks. Your comment is awaiting approval by a moderator.

    Do you already have an account? Log in and claim this comment.

      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block email
        • Block IP address
      Paige 3 years ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      Love the redesign!
      http://missdomestic.com /people/d6935aaa09724835a9090cfcfe90fd99/
      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block email
        • Block IP address
      Aaron 3 years ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      Thanks. :)
      http://www.technosailor.com /people/d409f7e3d0b43dd41dcfbd58aa255601/
      • ^
      • v
      • Permalink
      • Admin
        • Remove Post
        • Block email
        • Block IP address
      Vinnie Garcia 3 years ago 1 point

      Please login to rate.

      Do you already have an account? Log in and claim this comment.

      You can also set the register globals flag in Apache via .htaccess:

      php_flag register_globals off

      Though it's better to do this at the php.ini level and not in a PHP script or .htaccess. Sadly though, some hosts just won't turn RG off because some of their customers' systems rely on it.
      http://ibebloggin.com/ /people/fa1418ab598a80ad3882325e3fd9f808/
    Comments for this post are closed.

    close Joe Chill(joechill)
    konvict

    status via twitter

    Murdering the Wayne parents, creating Batman · 2 minutes ago

    recent comments (follow comments)

      View Profile »
      Powered by Disqus · Learn more
      blog comments powered by Disqus
      • Recent Posts

        • Fantasy Football for Charity
        • Findability is a Legitimate Concern for Bloggers
        • Search and Findability
        • Will I See you in Boston? Or in San Francisco? Or in Boulder? Or in Vegas?
        • The Psychology of Gap Marketing
      • Recent Comments

        Powered by Disqus
      • Tags

        Aaron Brazell Advertising Apple b5media Blogging book conferences Design entrepreneurship Facebook Finance and Funding Google guest_blogging holidays humor hurricanes_and_natural_disasters interesting job Links Marketing Music nfl Op-Ed Perfect Pitch personal politics pr Predictions productivity Programming Security Social Issues Social Media Social Networking social_issues Sports Tech Industry Technology Technosailor Travel twitter unix Venture Files WordPress you_can_blog

      • License Creative Commons Attribution-Noncommercial-Share Alike 3.0 | Copyright © 2004 - 2008 - Aaron Brazell | Lisa helped out | Privacy Policy

        Twitter Pitch!

        <p>Twitter pitching is a form of pitch that requires succint "what does this mean for me" kind of pitching. It is the ultimate efficiency of words. You have 140 characters or less to tell me why your pitch matters to me or my readers. Please include a means of contacting you. This is included in your 140 characters. If you send successive pitches, you will likely be ignored, unless it's obvious that the first pitch was a case of "accidental send", etc.</p> <p>This form of pitching does not mean I'm being a diva. It means that my time is valuable, and you want a piece of it. It's good practice for you, and delivers your pitch in a format I want. Win-win.</p>


        (X) Close

        Twitter Pitch Me!