Exploiting XSS to perform CSRF


The website in this lab contains a stored XSS vulnerability in the blog comments function.

Reproduction and proof of concept

  1. Log in using the credentials provided. On your user account page, notice the function for updating your email address.

  2. View the source for the page, and see the following information:

  • You need to issue a POST request to /my-account/change-email, with a parameter called email.

  • There is an anti-CSRF token in a hidden input called token.

This means your exploit will need to load the user account page, extract the CSRF token, and then use the token to change the victim’s email address.

  1. Enter the following payload in a blog comment:

    var req = new XMLHttpRequest();
    req.onload = handleResponse;
    function handleResponse() {
        var token = this.responseText.match(/name="csrf" value="(\w+)"/)[1];
        var changeReq = new XMLHttpRequest();
        changeReq.open('post', '/my-account/change-email', true);

This will make anyone who views the comment issue a POST request to change their email address to test@test.com.