Webmaster Forum


Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

   

Reply
 
LinkBack Thread Tools Display Modes
Old 01-28-2007, 12:26 PM   #1 (permalink)
Contributing Member
 
Join Date: 10-10-06
Location: Sweden
Posts: 177
iTrader: 0 / 0%
Latest Blog:
None

WatchOut is liked by many
register_globals security issue?

Hello everyone,

I just wanted to ask you all is register_globals a security issue?
Is it secure to have it enabled or is it unsecure?
WatchOut is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-28-2007, 04:14 PM   #2 (permalink)
Contributing Member
 
exam's Avatar
 
Join Date: 04-20-06
Posts: 310
iTrader: 0 / 0%
Latest Blog:
None

exam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web proexam is a highly respected web pro
Having it enabled is neither secure nor insecure. When register_globals is enabled, it simply makes it easier to write insecure code.

Consider a script like the following, it is a php page where the user passes his/her name in to the script via a $name variable and the script prints a welcome:

PHP Code:
<?php

// See if it's morning or afternoon
if (date('G') < 12) {
      
// Ok it's morning
      
$is_morning true;
}

// Print the welcome
if ($is_morning) {
      echo 
'<h2>Good morning '.$name.'</h2>';
} else {
      echo 
'<h2>Good afternoon/evening '.$name.'</h2>';
}
?>
The above code is vulnerable to attack when register_globals is on because the variable $is_morning is not initialized before use.

If you type in the URL 'script.php?name=Jackie' you will get Good morning Jackie or Good afternoon/evening Jackie depending on the time of day. With register_globals enabled, you can manipulate the script and make it print 'Good morning' even in the afternoon by typing in 'script.php?name=Jackie&is_morning=1'.

If register_globals is off, you have to access all variables that come in as parameters in the URL thru the $GLOBALS array or the $_GET (or $_POST etc) arrays: ie: $_GET['name'] instead of $name. Since the script uses the $is_morning variable, you can't manipulate the value of that variable via the URL when register_globals is enabled.

So, it's easier to write insecure code when register_globals is on.

To take advantage of these vulnerabilities, you have to either guess or know the variables being used in the script you want to hack, but with all the open source scripts out there, it's not that hard to know what variables they're using.

The above script can be perfectly safe even with register_globals on, if you initialize the value of $is_morning at the beginning of the script. Of course you'd need to validate the contents of the $name variable before using it as well, but that doesn't have anything to do with register_globals.
__________________
~exam~
exam is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-28-2007, 07:30 PM   #3 (permalink)
Inactive
 
Join Date: 01-23-07
Location: Netherworld, under Buenos Aires.
Posts: 169
iTrader: 0 / 0%
Hades is liked by somebodyHades is liked by somebodyHades is liked by somebodyHades is liked by somebody
Send a message via MSN to Hades Send a message via Yahoo to Hades
It could be insecure if you have some bad practices while you write the code.

IE, if you read and use a variable doing something like this:

PHP Code:
//register globals is ON
$sql "SELECT * FROM user WHERE ... AND password = $password"
using password as a global variable, someone could set it using GET method, and do some SQL injection to break your application.

Instead, you may want to do something like this:

PHP Code:
//register globals could be ON/OFF
$password mysql_escape_string($_POST['password']);

$sql "SELECT * FROM user WHERE ... AND password = '$password'" 
Regards.
Hades is offline  
Add Post to del.icio.us
Reply With Quote
Old 01-29-2007, 08:25 AM   #4 (permalink)
Contributing Member
 
Join Date: 10-10-06
Location: Sweden
Posts: 177
iTrader: 0 / 0%
Latest Blog:
None

WatchOut is liked by many
Thanks guys, I kinda knew it was safe if the script was working but people from some forums were claiming it was unsafe. Thanks for your feedback, helped me lots and will put a lot of minds at ease.
WatchOut is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Site-Sift listings Security Issue WhatiFind Web Directory Issues 0 05-09-2006 09:40 AM
Users Running phpBB *NEW SECURITY ISSUE FIX* Limit Coding Forum 6 01-02-2004 08:14 AM


Sponsor Links
Webmaster Forum Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 02:48 AM.
© Copyright 2008 V7 Inc