Join us at IRC!
The important thing is not to stop questioning. - Albert Einstein
Thursday, May 17, 2012
Navigation
Members Online
Total Online: 33
Web Spiders: 18
Guests Online: 30
Members Online: 3

Registered Members: 70042
Newest Member: sirrom
Latest Articles

Cookie Poisoning



FLV Blaster - Download Music and Videos Faster

website security A basic introduction to cookie poisoning



One of the major mistakes which web masters make is considering that all data they set stay the same. These things are usually harmless to them such as cookies and hidden form details.

To start with I am going to show how the web master sets his data for his vulnerable CMS.

He begins with a form :-

[username] Username
[********] Password
[Button] Submit button

Once the form is submitted, the backend PHP which recieves the $_POST is as follows.

<?php

if ((isset($_POST['user'])) && (isset($_POST['pass']))) {
$user = $_POST['user'];
$pass = $_POST['pass'];

<Database connection>
// mysql_real_escape_string stops SQL Injection
$query = mysql_query("SELECT * FROM `usertbl` WHERE 'user' = '".mysql_real_escape_string($user)."' AND

'pass' = '".mysql_real_escape_string($pass)."'");

$num_rows = mysql_num_rows($query);

if (isset($num_rows)) {
if ($num_rows >= 1) {
echo "Username accepted";
setcookie("UID", ($user . ":" . $pass), time()+7200);
}
echo "Username Incorrect";
}
echo "MySQL Error";
}

}
echo "<FORM Details>";

}

?>

Right, so now we have checked the database for for a the username and password and set the cookie.
Presuming our attacker's username and password are correct then the cookie will be something of the folowing

UID = "tom:password123".

Later on our attack visits a protected page and his cookie is checked with this code.

<?php
if (isset($_COOKIE['UID'])) {
$cookies = $_COOKIE['UID'];
$cookies = explode(":", $cookie);

<Database connection>
// $cookies[0] is the first part of $cookie ie User
$query = mysql_query("SELECT * FROM `usertbl` WHERE 'user' = '".($cookies[0])."' AND

'pass' = '".($cookies[1])."'");

// Notice here the webmaster forgot to prevent SQL Injection

$num_rows = mysql_num_rows($query);

if (isset($num_rows)) {
if ($num_rows >= 1) {
viewPage;
}
}
}
?>

Now, if the cookie stays the same the SQL query is safe. However, if you change the cookie you can use it as simply as a basic SQL injection.

Right, now we have see how basic cookie poisoning works with SQL Injection. This can also be utilised in all other major web vulnerabilities.

Comments

tolchocker on August 02 2006 - 14:17:01
what? no chocolate chips?:wow:
The_Cell on August 02 2006 - 17:53:35
Nice article. This proves yet again how important it is to consider all data not filtered as tainted.
minermonk on August 02 2006 - 22:01:23
bacause of this i learn something, therefore it forfils its pupose :D good article mozzer
mozzer on August 03 2006 - 07:58:01
Cheers, every webmaster should take something from this
chislam on August 03 2006 - 18:57:00
Yes, good article, you always gotta be sure you are filtering every possible string.
el3v3nty on August 04 2006 - 06:09:26
Man this is good stuff. ;) for some reason i wasnt even thinkin about it like that :whoa: I know that is a security vulnerability i wouldve let slide by :@ but now.. now i feel like i can do so much more :evil: oh yeaah thas right good stuff man, real good stuff
ranma on September 22 2006 - 01:59:52
That is sweet! I wonder how many sites have that vulnerability?:D
thk-h3x on June 08 2007 - 15:55:31
Too many.:ninja:
a240 on March 09 2008 - 23:29:53
Good article, you should make more.
sam207 on September 23 2008 - 08:16:06
It's so sweet nice & well written.. Thanks mozzer.
styloverte116 on February 17 2009 - 22:36:23
ok so.... im doin basic challenge 20, and i cant quite figure this out. after looking at this article (well written btw) i thought i knew how to do it. but whatever i tried, i couldnt figure anything out. can i pm someone?
styloverte116 on February 17 2009 - 22:43:34
ok so.... im doin basic challenge 20, and i cant quite figure this out. after looking at this article (well written btw) i thought i knew how to do it. but whatever i tried, i couldnt figure anything out. can i pm someone?
stealth- on December 04 2009 - 02:09:36
Amazing article for basic 20, well written and doesn't give too much away. We need more articles like this!
Shazrah on April 06 2010 - 14:31:45
awsome article, really explains things without making it like hello skiddie take this and paste there. :love::love: very well written ty
Post Comment

Sorry.

You must have completed the challenge Basic 1 and have 100 points or more, to be able to post.
Ratings
Rating is available to members only.

Please login or register to vote.

Awesome! 53% [10 Votes]
Very Good 42% [8 Votes]
Good 0% [No Votes]
Average 5% [1 Vote]
Poor 0% [No Votes]
Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 

 

Links
By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2008- 2009. Since 3rd December 2004.