XSS Exploitation
Exe 1: DOM XSS in document.write sink using source location.search
- Enter a random alphanumeric string into the search box.
-
Right-click and inspect the element, and observe that your random string has been placed inside an
img srcattribute. -
Break out of the
imgattribute by searching for:"><svg onload=alert(1)>
Payload: "><svg onload=alert(1)>
-
Enter the following into the into the search box:
<img src=1 onerror=alert(1)> - Click "Search".
The value of the src attribute is invalid and throws an error. This triggers the onerror event handler, which then calls the alert()
function. As a result, the payload is executed whenever the user's
browser attempts to load the page containing your malicious post.
Vulnerable Code:
<script>
function doSearchQuery(query) {
document.getElementById('searchMessage').innerHTML = query;
}
var query = (new URLSearchParams(window.location.search)).get('search');
if (query) {
doSearchQuery(query);
}
</script>
- On the Submit feedback page, change the query parameter
returnPathto/followed by a random alphanumeric string. -
Right-click and inspect the element, and observe that your random string has been placed inside an a
hrefattribute. -
Change
returnPathto:javascript:alert(document.cookie)Hit enter and click "back".
- ❌ Hashchange does NOT require a page refresh.
✔️ It fires only when the hash changes, not when it’s initially loaded.
✔️ The lab exploit works by causing a hash change, not a reload.
Comments
Post a Comment