Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Ethical hacking Tips (http://www.go4expert.com/articles/ethical-hacking-tutorials/)
-   -   Basics of XSS or Cross Site Scripting Explained (http://www.go4expert.com/articles/basics-xss-cross-site-scripting-t26878/)

lionaneesh 9Oct2011 08:23

Basics of XSS or Cross Site Scripting Explained
 
Cross Site Scripting also known as XSS is a popular type of Client Site Attack, It is a type of attack which occurs in Web-Applications and allows an attacker to inject desired client-side scripts into Web-Pages viewed by others.

Types of XSS



This attack is mainly of 2 types

Non-Persistent

This type of attack is carried out by injecting some client side code in a Vulnerable URL. Now further the Attacker can spread this URL and send it to his/her victims by means of some social engineering etc , on clicking these links the Victims Unknowingly executes the injected code , Which in turn can result in Cookie stealing , Privacy Disclosure etc.

Persistent

This type of Attack is more dangerous and it occurs when the data provided by the attacker is stored by the server, which is viewed as a normal page to the normal users.
Now Further the Attacker can simply inject some malicious Client Side Code which in turn can result in Defacement of the Website, Cookie Stealing, and Privacy Disclosure etc.

Demo



Now that we know something about what are these type of vulnerabilities and how they occur let’s actually take a look at how these vulnerabilities occur How to test it!
Xss.php
Code: php

<html>
<head>
    <title>Vulnerable to XSS</title>
</head>
</html>
<body>
<h1>Welcome to XSS Demo Page</h1>

<p>The Data Entered is As Follows :- </p>

<?php

/**
 * @author lionaneesh
 * @copyright 2011
 */

 

if(isset($_GET['data']))
{
    $data = $_GET['data'];
}
else
{
    $data = "No Data Entered !";
}

echo "<i>$data</i>";

?>

</body>


Now Just Go to :-

Site.com/path/xss.php?data=<script>alert(“XSS”);</script>

And See what happens!

Wow! An Alert box saying XSS will appear proving that your injected code actually executed! Now this is just an example of how these vulnerabilities can occur in web-applications and how you can test them!

How to Fix Them



If you’re one of the people whose site is vulnerable to this type of attack I recommend fixing it as soon as possible, For the scope of this tutorial I’ll be only covering on how these vulnerabilities can be fixed in PHP , If you are using some other language , I recommend you to check your Language Reference or Contact Me .

PHP Provides a function called htmlspecialchars() which converts the chars into their HTML entities. Now we’ll just use this in the above code and check what happens.
Xss.php (line number 33)
Code: php

echo htmlspecialchars("<i>$data</i>");

Now let’s once more Go to :-

Site.com/path/xss.php?data=<script>alert(“XSS”);</script>

And See what happens!

Voila! U can notice the change now!

That’s all for this tutorial stay tuned for more

lionaneesh 9Oct2011 09:22

Re: Basics of XSS or Cross Site Scripting Explained
 
Thanks for Accepting , I hope the viewers like it!

mitchumango 9Oct2011 19:38

Re: Basics of XSS or Cross Site Scripting Explained
 
This isn't working for me. I can set $data to a string by using "/xss.php?data=mitch", but I can't execute any scripts. Is it possible that htmlspecialchars() is automatically turned on?

lionaneesh 9Oct2011 20:12

Re: Basics of XSS or Cross Site Scripting Explained
 
Quote:

Originally Posted by mitchumango (Post 87813)
This isn't working for me. I can set $data to a string by using "/xss.php?data=mitch", but I can't execute any scripts. Is it possible that htmlspecialchars() is automatically turned on?

The XSS protections are implemented in some browsers , like Google Chrome etc!
Try it with Mozilla or Internet Explorer!

chandru4u 25Oct2011 13:14

Re: Basics of XSS or Cross Site Scripting Explained
 
Latest Version of All Browser have the XSS Protection bydefault is Enable .

Protection for ASP.NET

Microsoft Anti-XSS Library .

General Protection:

Input Validation .

Final Protection:

Implement WAF - Web Application Firewall

Thanks

Chandru

johnhawk 23Nov2011 15:57

Re:
 
Programming language very difficult but there are essay daily handle this work...!

phpcrazy 26Dec2011 15:28

Re: Basics of XSS or Cross Site Scripting Explained
 
nice to your post


All times are GMT +5.5. The time now is 23:10.