Saturday, October 07, 2006

Variable Poisoning



Yesterday when I was writing my code, i thought what would happen if I don't initialise my variables before their use.
To find suitable answer i searched the forum,articles then finally PHP manual and found out that it may seriously open my code to attacker and create some serious problems.

By leaving variables undefined before using them, you open yourself up to a security attack called "Variable Poisoning".


note:Excerpts from Php Manual
http://in.php.net/manual/en/security.registerglobals.php



Perhaps the most controversial change in PHP is when the default value for the PHP directive register_globals went from ON to OFF in PHP 4.2.0. Reliance on this directive was quite common and many people didn't even know it existed and assumed it's just how PHP works. This page will explain how one can write insecure code with this directive but keep in mind that the directive itself isn't insecure but rather it's the misuse of it.

When on, register_globals will inject your scripts with all sorts of variables, like request variables from HTML forms. This coupled with the fact that PHP doesn't require variable initialization means writing insecure code is that much easier. It was a difficult decision, but the PHP community decided to disable this directive by default. When on, people use variables yet really don't know for sure where they come from and can only assume. Internal variables that are defined in the script itself get mixed up with request data sent by users and disabling register_globals changes this. Let's demonstrate with an example misuse of register_globals:

Example 29-1. Example misuse with register_globals = on

phpcode
// define $authorized = true only if user is authenticated
if (authenticated_user()) { $authorized = true; }
// Because we didn't first initialize $authorized as false, this might be
// defined through register_globals, like from GET auth.php?authorized=1
// So, anyone can be seen as authenticated!
if ($authorized) { include "/highly/sensitive/data.php"; } ?>



When register_globals = on, our logic above may be compromised. When off, $authorized can't be set via request so it'll be fine, although it really is generally a good programming practice to initialize variables first. For example, in our example above we might have first done $authorized = false. Doing this first means our above code would work with register_globals on or off as users by default would be unauthorized.

Another example is that of sessions. When register_globals = on, we could also use $username in our example below but again you must realize that $username could also come from other means, such as GET (through the URL).

Example 29-2. Example use of sessions with register_globals on or off


phpcode // We wouldn't know where $username came from but do know $_SESSION is
// for session data
if (isset($_SESSION['username'])) {
echo "Hello {$_SESSION['username']}";

} else {

echo "Hello Guest
";
echo "Would you like to login?";

}



It's even possible to take preventative measures to warn when forging is being attempted. If you know ahead of time exactly where a variable should be coming from, you can check to see if the submitted data is coming from an inappropriate kind of submission. While it doesn't guarantee that data has not been forged, it does require an attacker to guess the right kind of forging. If you don't care where the request data comes from, you can use $_REQUEST as it contains a mix of GET, POST and COOKIE data. See also the manual section on using variables from outside of PHP.

Example 29-3. Detecting simple variable poisoning

phpcode
if (isset($_COOKIE['MAGIC_COOKIE'])) {
// MAGIC_COOKIE comes from a cookie.
// Be sure to validate the cookie data!

}
elseif (isset($_GET['MAGIC_COOKIE']) isset($_POST['MAGIC_COOKIE']))
{ mail("admin@example.com", "Possible breakin attempt", $_SERVER['REMOTE_ADDR']);
echo "Security violation, admin has been alerted.";
exit;
} else {

// MAGIC_COOKIE isn't set through this REQUEST

}


Of course, simply turning off register_globals does not mean your code is secure. For every piece of data that is submitted, it should also be checked in other ways. Always validate your user data and initialize your variables! To check for uninitialized variables you may turn up error_reporting() to show E_NOTICE level errors.

Top Ten Entrepreneurial Traits



1. Independence

You can’t be an entrepreneur if you are constantly depending on someone else. You have to be willing to stand on your own two feet. In handwriting, independence shows in two ways.

Where the capital I, when used as the Personal Pronoun, is either just a straight stick, or a straight stick with a horizontal bar top and bottom.
Independence thinking or independence of ideas, going your own way regardless, shows in very short stems on the lower case “t” or “d”.


2. Intuition

If the entrepreneur expects facts in front of her before making every decision, she will be left behind. Intuition, that gut feeling that you just “know” is right, is essential. Intuition shows in breaks between letters in script. If it’s all printing, this is not intuition.



3. Imagination

Creativity is too complicated a trait to give as part of this list, but imagination is one component of it. Imagination, especially when it comes as the ability to think outside the box (often imagination + independent thinking) is shown in large upper loops on b,h,k,l and lower loops on j,g,y.



4. Initiative

Always a positive trait, the ability to recognize opportunity and move towards grasping it, initiative is shown in the strong rightward swing of the end stroke of a lower case “t” substituting for the t-bar. It also shows in a strong forward swing of the “hump” part of the lower case “k” or “h”.


5. Ability To Be Objective + Ability To Be Responsive

Both of these are needed by the entrepreneur. The ability to be objective and not be consumed by emotional reaction is shown in an upright slant. The ability to be responsive is shown in a forward right slant. How can anyone have both? Well, yes that’s the tricky part, but a slight right slant shows the best of both worlds – the ability to be empathetic and respond to people, plus the ability to keep calm and make rational decisions.



6. Lack Of Caution

Caution, as shown in handwriting, is an inhibitor. Too much caution can be crippling. The slant as mentioned in #5 will prevent foolhardy impulsiveness. So a lack of the caution trait would be good for the entrepreneur. It shows in a long, flat stroke at the baseline before lifting the pen from the page at the end of a word/ letter formation.



7. Honesty and Integrity

This is an absolute necessity for anyone and especially someone who’s reputation translates into business or no business. Honesty is shown in circle letters (a, o, the circle part of g and d) with no loops or hooks. Just clean, clear circles.


8. Clear Thinking

A clear head, the ability to see right though all the “garbage” and get to the important point, that is clear thinking. It is shown in a lack of lead in strokes in letters. This is when putting the pen to paper the writer starts with the actual letter formation itself, not with a curvy, or straight, lead-in stroke.


9. Persistent

It has been said that 80% of businesses that fail do so because the entrepreneur gave up too soon. There are several traits which show someone who will keep on going. Persistence is just one. It shows in a counter clockwise knot which can appear anywhere, but frequently can be seen as a connected t-bar, in the formation of the bar in a capital H or A, in a lower case f and sometimes by itself in place of the word “and”.



10. Self- Motivated

And lastly self- motivation. No-one is going to push the entrepreneur to get his work done. No one is going to complain if he skips some things he doesn’t like to do. But his business will suffer. He needs to be motivated to succeed. This ability to get himself going is shown in a strong, heavy t-bar – heavier than the rest of the writing.

These are just some of the entrepreneurial traits, but some of the most important. With full time jobs becoming a thing of the past, more and more people are becoming entrepreneurs whether out of desire or necessity. It requires a whole different set of skills, and a different outlook than being an employee. By knowing where you are strong and where you are lacking, you are empowered to seek help in the areas you need it before it “comes back to bite you”. If you’re starting on your entrepreneurial journey, I wish you well