Register_Globals Override
October 29, 2010| Tweet |
- PHP.NET: Using Register_Globals
- PHP.NET: Description of register_globals directive.
- Brief overview of Web Application Security (PDF)
- Variable Listing Script with output of cleansing code to prevent register_globals related attacks.
Download Original
This script is best used as an include file before anything in your scripts. Failing to include this first will allow this script, which does NO FILTERING to override the variables you may have already sanitized. Meaning you're going to be dealing with XSS, XSRF, and SQL Injections. Bad news indeed.
<?PHP /*This function emulates the PHP.INI setting being set to ON, which should only be used on a server with register globals OFF, to assist in revising legacy scripts developed on servers designed for register_globals. The security vulnerabilites of having this feature on are well known, so use this function ONLY while updating these scripts, preferably on a development server. PHP's Handbook on Security with Register Globals http://php.net/manual/en/security.globals.php Use the output of this script at the beginning of your programs to negate register_globals holes, however it will not pull in the vars. http://www.robert-lerner.com/phpvarlist.php License: Copyright ©2010 Robert Lerner, All Rights Reserved http://www.robert-lerner.com Feel free to incorporate this script into any script, personal, free, open-source, or commercial. Please leave this license statement intact.*/ }
So wait, you're writing code to open holes?
I sure am. I know, sounds insane, but unless you read those links above, you won't understand why this would be useful. Some of you who really read them may have noticed that PHP.NET provides it's own version of this function. So why use mine?
Inside of PHP.INI, the file that "configures" PHP, a directive exists titled
variables_order. This variable controls the order that the variables are registered, for example, GPCES would import all of the variables in these arrays: $_GET, $_POST, $_COOKIE, $_ENV and $_SERVER, and in that order. So if you used the following code:
<form action='page.php?id=5' method='post'>
<input type='text' name='id' value='4' />
</form>
The PHP file, if register_globals is on or this script is used, would cause
$id to equal 4. The order the arrays are imported causes $_POST variables of the same name to overwrite $_GET variables, unless of course, inside your script, you include the code:
<?PHP
$id = $_GET['id'];
?>
This would re-read the $_GET array and override the register_globals / this script's output.
PHP.NET's example doesn't respect this variable order, nor does it count for differing lengths. For example, PHP 5.3.3's PHP.INI file has four array order element listed, older ones may have more, and custom ones may have less. This works with all of them.
Happy Fixing! No comments yet! Be the first!

Facebook
LinkedIn