OWASP's testing for HTML injection page (link) shows a particular code that is supposed to be vulnerable to HTML injection.
<script src="../js/jquery-1.7.1.js"></script>
<script>
function setMessage(){
var t=location.hash.slice(1);
$("div[id="+t+"]").text("The DOM is now loaded and can be manipulated.");
}
$(document).ready(setMessage );
$(window).bind("hashchange",setMessage)
</script>
<body>
<script src="../js/embed.js"></script>
<span><a href="#message" > Show Here</a><div id="message">Showing Message1</div></span>
<span><a href="#message1" > Show Here</a><div id="message1">Showing Message2</div>
<span><a href="#message2" > Show Here</a><div id="message2">Showing Message3</div>
</body>
This code is one of the challenges on (domxss.com) and I am unsure of how this is vulnerable.
From what I understand, the URL's hash can be used as an input and any change in the URL will trigger the setMessage
function. This URL hash will be my payload. However, this payload is only being used as a selector in jQuery which is where I hit a wall.
I am relatively new to XSS so any payloads will be appreciated. An explanation is obviously welcome.
Also, any resources to better understand HTML injection attacks via jQuery will be useful.